Question: 5. For each subprogram below, derive (in detail as shown in lect21_01_20-1.pdf: pages 10, inserted page with cost/times-table, and 11) the worst case running time

5. For each subprogram below, derive (in detail as shown in lect21_01_20-1.pdf: pages 10, inserted page with cost/times-table, and 11) the worst case running time first, provide its asymptotic tight bound (big-Theta es- timate), and answer specific questions. 1 (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[O..n - 1] of integer); S:=0; for i:= 0 to n - 1 loop S:=S+ A[0]; for j :=1 to i loop SEES+ A[]; end loop; end loop; return S; end P.1
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
