Question: 1. (40 points) Analysis of recursive algorithm. Consider the pseudocode of the following three algorithms for computing 2, where n is a non-negative integer. Algi

1. (40 points) Analysis of recursive algorithm. Consider the pseudocode of the following three algorithms for computing 2", where n is a non-negative integer. Algi (n) if (n == 0) return 1; return 2 * Alg1(n - 1); end Alg2 (n) if (n == 0) return 1; return Alg2(n - 1) + Alg2 (n - 1); end Alg3 (n) if (n 0) return 1; m = floor (n / 2); P = Alg3(m); P = p *p; if (n % 2 == 1) // n is an odd number return 2 * p; else // n is an even number; return p; end end a. 6 points) Trace the three algorithms using two small examples (n = 2 and n = 3) to find out the outputs of the three algorithms, respectively. b. (4 points) Prove the correctness of Algl using induction. c. (12 points) Let A(n), B(n), and C(n) be the running time of the three algorithms, respectively, as a function of n. Write down the recurrences for A(n), B(n), and C(n). d. (18 points) Analyze and compare the running time of the three algorithms above. You can use either recursion tree or master method to solve the recurrences
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
