Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Consider the following code: 01: list folderol (int n) 02: { 03: set t, u; 05: 06: while (t.size() < n) 07: t.insert (rand()

C++

Consider the following code:

01: list folderol (int n)

02: {

03: set t, u;

05:

06: while (t.size() < n)

07: t.insert (rand() % (2*n));

08: while (u.size() < n)

09: u.insert (rand() % (2*n));

10:

11: list L;

11: for (int i: t)

12: if (u.count(i) > 0)

13: L.push_back(i);

14: return L;

15: }

rand() returns a random non-negative integer and runs in `O(1)` time. Assume that each possible unsigned int value is equally likely to be returned on any given call to rand().

Match the line numbers below to the closest correct complexity expression, giving the single-letter identifier for your chosen complexity.

A: O(1)

B: O(log n)

C: O(sqrt(n))

D: O(n)

E: O(n log n)

F: O(n sqrt(n))

G: O(n2)

H: O(n2 log(n))

I: O(n2 sqrt(n))

J: O(n3)

K: none of these

If the line numbers are preceded by "Avg", give the average case complexity. Otherwise, give the worst case complexity. Line 7:

Avg Line 7:

Lines 6-7:

Line 13:

Line 12:

Avg Line 12:

Lines 11-13:

Avg Lines 11-13:

Line 14:

Avg Line 14:

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2016 Riva Del Garda Italy September 19 23 2016 Proceedings Part 3 Lnai 9853

Authors: Bettina Berendt ,Bjorn Bringmann ,Elisa Fromont ,Gemma Garriga ,Pauli Miettinen ,Nikolaj Tatti ,Volker Tresp

1st Edition

3319461303, 978-3319461304

More Books

Students also viewed these Databases questions

Question

Solve 2 x 2 -5x = 1/64.

Answered: 1 week ago

Question

Respond to personality differences among people.

Answered: 1 week ago

Question

Find y'. y= |x + X (x) (x) X 1 02x+ 2x 1 O 2x + 1/3 Ex 2x +

Answered: 1 week ago