Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Step: 3

blur-text-image

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

Transactions On Large Scale Data And Knowledge Centered Systems Vi Special Issue On Database And Expert Systems Applications Lncs 7600

Authors: Abdelkader Hameurlain ,Josef Kung ,Roland Wagner ,Stephen W. Liddle ,Klaus-Dieter Schewe ,Xiaofang Zhou

2012th Edition

3642341780, 978-3642341786

More Books

Students also viewed these Databases questions

Question

6. Explain the strengths of a dialectical approach.

Answered: 1 week ago