please show work and explain. Consider the following code: rand() returns a rand
ID: 3737330 • Letter: P
Question
please show work and explain.
Consider the following code:
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
Explanation / Answer
Solution:
1: A
2: K
3: A
6: D
7: D
9: A
11: D
12: A
13: A
Line 7: D
Line 9: D
Avg Line 9: B
Line 13: G
Line 12: D
Avg Line 12: D
Lines 11-13: G
Avg Lines 11-13: E
Avg Lines 12-14: B
I hope this helps if you find any problem. Please comment below. Don't forget to give a thumbs up if you liked it. :)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.