Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing

Authors: David Kroenke

11th Edition

0132302675, 9780132302678

More Books

Students also viewed these Databases questions

Question

Provide examples of Dimensional Tables.

Answered: 1 week ago