Question: Consider the following code: 01: void folderol (int n) 02: { 03: set t; 05: 06: while (t.size() < n) 07: t.insert (rand() % (n*n));

Consider the following code:

01: void folderol (int n) 02: { 03: set t; 05: 06: while (t.size() < n) 07: t.insert (rand() % (n*n)); 08: 09: list L (t.begin(), t.end()); 10: 11: for (int i = 0; i < n; i++) 12: if (t.count(i) > 0) 13: cout << std::count(L.begin(), L.end(), i) << endl; 14: }

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:

Line 9: Avg Line 9: Line 13: Line 12: Avg Line 12: Lines 11-13: Avg Lines 11-13: Avg Lines 12-14

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!