Question & Answer: Consider the following algorithm: Algorithm Calc(a, n): Input: two integers, a and n Output: ? k leftarrow 0 b leftar…..

5. Consider the following algorithm: Algorithm Calc(a, n): Input: two integers, a and n Output: while k<n do return b a. What does the algorithm calculate? b. Analyze its worst-case running time and express using Big-0h notation 6. Let f(N) and g(N) be asymptotically positive functions. Disprove each of the following statements using a counterexample: f (N) = 0(g(N)) implies g(N) = 0(f(N)) a,

Consider the following algorithm: Algorithm Calc(a, n): Input: two integers, a and n Output: ? k leftarrow 0 b leftarrow 1 while k

Expert Answer

 

5 a) Its computing a^n. Basically in each iteration of while loop b is multiplied by a and its done n times so result is a^n

b) Time complexity of above algorithm considering constant time in doing multiplication is O(n) as while loop runs n time doing constant work.

Still stressed from student homework?
Get quality assistance from academic writers!