Question: count algorithm time Algorithm Analysis Analyze the pseudocode below and give the asymptotic worst-case running time of each function in terms of the input value
Algorithm Analysis Analyze the pseudocode below and give the asymptotic worst-case running time of each function in terms of the input value n as a Big-Theta expression. (a) 1: procedure KSUM1 (n) 2: S leftarrow 0 3: k leftarrow n 4: while k greaterthanorequalto 1 do 5: for i = 1, 2, ..., k do (b) 1: procedure KSuM^2 (n) 2: 5 leftarrow 0 3: k leftarrow n 4: while k greaterthanorequalto 1 do 5: for i = 1, 2, .., n do 6: S leftarrow S + n 7: end for k leftarrow k/2 end while return S end procedure
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
