func2(n) 1 s ← 0; 2 for i ← 2n to 4n3 do 3 j ← ⌊\sqrt(i)⌋; 4 while (j >= 16) do 5 s ← s + i - j; 6 j ← j - 5 ; ()/()* Note: Subtraction( *)/() 7 end 8 end 9 return (s); (a) Give an equation representing the running time of Function func2. (b) Give the asymptotic running time of Function func2 in \theta notation based on your equation in part a
Added by David W.
Step 1
We count running time as a function T(n). The code: s ← 0; for i ← 2n to 4n^3 do j ← floor(sqrt(i)); while (j >= 16) do s ← s + i - j; j ← j - 5; end end return(s). We will count operations per iteration of the loops; constant-time overheads will be absorbed into Show more…
Show all steps
Your feedback will help us improve your experience
Neel Patel and 72 other AP CS educators are ready to help you.
Ask a new question
Labs
Want to see this concept in action?
Explore this concept interactively to see how it behaves as you change inputs.
Key Concepts
Recommended Videos
Give the asymptotic running time of each the following functions in Θ notation. Justify your answer. (Show your work.) 5. Func5(n) 1 s ← 0; 2 i ← n; 3 while (i < n² log₃(n)) do 4 j ← n²; 5 while (j > n) do 6 s ← s + i - j; 7 j ← ⌊ j / 7 ⌋; 8 end 9 i ← i + ⌊ √ n ⌋; 10 end 11 return (s); 6. Func6(n) 1 s ← 0; 2 for i ← 6 to n² do 3 j ← 3; 4 while (j < 2i²) do 5 s ← s + i - j; 6 j ← (1.5) * j; 7 end 8 end 9 return (s);
Supreeta N.
Give the big-O estimate for the number of operations where an operation is an addition or a multiplication, used in this segment of an algorithm (ignoring comparison used to test the condition in the while loop). i:=1 t:=0 while i < n t:= t+2i i:= i+1
Nick J.
Breanna O.
Recommended Textbooks
Computer Science and Information Technology
Introduction to Programming Using Python
Computer Science - An Overview
Watch the video solution with this free unlock.
EMAIL
PASSWORD