Answered step by step
Verified Expert Solution
Question
1 Approved Answer
For each subprogram below, derive (in detail as shown in pages 10, inserted page with cost/times-table, and 11) the worst case running time first, provide
For each subprogram below, derive (in detail as shown in pages 10, inserted page with cost/times-table, and 11) the worst case running time first, provide its asymptotic tight bound (big-Theta estimate), and answer specific questions.
I am so lost and do not know what he means by this so please try to your best of your ability and will give THUMBS UP !!!
(a) What does the code fragment compute? procedure P.1 (integer n; array A[1..n] of integer); S:= A[1]; for i:= 2 to n step 2 loop Increments of 2 S:=S+ A[i]; end loop; return S; end P 1; (b) What does the code fragment compute? Give a computationally equivalent algorithm P-2' with a linear worst-case running time. procedure P-2 (integer n; array A[0..n 1] of integer); S:= 0; for i:= 0 to n - 1 loop S:= S + A[O]; for j :=1 to i loop S:= S + A[i]; end loop; end loop; return S; end P.1; (c) procedure P-3 (integer n); for i:=1 to n loop x := na: while x > 0 loop 2:=x-2.1; end loop; end loop; end P_3; (a) What does the code fragment compute? procedure P.1 (integer n; array A[1..n] of integer); S:= A[1]; for i:= 2 to n step 2 loop Increments of 2 S:=S+ A[i]; end loop; return S; end P 1; (b) What does the code fragment compute? Give a computationally equivalent algorithm P-2' with a linear worst-case running time. procedure P-2 (integer n; array A[0..n 1] of integer); S:= 0; for i:= 0 to n - 1 loop S:= S + A[O]; for j :=1 to i loop S:= S + A[i]; end loop; end loop; return S; end P.1; (c) procedure P-3 (integer n); for i:=1 to n loop x := na: while x > 0 loop 2:=x-2.1; end loop; end loop; end P_3Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started