Menu

(Solved) : 4 Algorithm Analysis Correctness 35 Pts Consider Following Algorithm 1 Complex N 2 J 1 3 0 Q44080927 . . .

4 Algorithm analysis and correctness (35 pts) Consider the following algorithm: 1: COMPLEX(n) 2: j = 1 3: a= 0 4 while in a=

4 Algorithm analysis and correctness (35 pts) Consider the following algorithm: 1: COMPLEX(n) 2: j = 1 3: a= 0 4 while in a= a + j=2.j 7: return a (a) (10 pts) Determine the precise number of iterations that the while loop executes. Prove your answer using induction. Hint: Observe how the value of changes in each iteration. (b) (5 pts) Using your answer in part (a), determine the asymptotic running time of the COMPLEX(n) algorithm (use notation). (c) (10 pts) Determine the value that COMPLEX(n) returns (as a function of n) and prove your answer using loop invariants, as presented in Chapter 2 of CLRS. Hint: Use the answer from part (a) and observe how it affects the value of a in each iteration. (d) (10 pts) Prove your answer in part (c) using induction. Observe the similarity between loop invariants and induction. Show transcribed image text 4 Algorithm analysis and correctness (35 pts) Consider the following algorithm: 1: COMPLEX(n) 2: j = 1 3: a= 0 4 while in a= a + j=2.j 7: return a (a) (10 pts) Determine the precise number of iterations that the while loop executes. Prove your answer using induction. Hint: Observe how the value of changes in each iteration. (b) (5 pts) Using your answer in part (a), determine the asymptotic running time of the COMPLEX(n) algorithm (use notation). (c) (10 pts) Determine the value that COMPLEX(n) returns (as a function of n) and prove your answer using loop invariants, as presented in Chapter 2 of CLRS. Hint: Use the answer from part (a) and observe how it affects the value of a in each iteration. (d) (10 pts) Prove your answer in part (c) using induction. Observe the similarity between loop invariants and induction.

Expert Answer


Answer to 4 Algorithm analysis and correctness (35 pts) Consider the following algorithm: 1: COMPLEX(n) 2: j = 1 3: a= 0 4 while i…

OR