Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Analysis of recursive algorithm. Consider the pseudocode of the following three algorithms for computing 2n, where n is a non-negative integer. Alg1 (n) if (n

Analysis of recursive algorithm. Consider the pseudocode of the following three algorithms for computing 2n, where n is a non-negative integer.

Alg1 (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 nd out the outputs of the three algorithms, respectively.

b. (4 points) Prove the correctness of Alg1 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

Visualizing Health And Healthcare Data Creating Clear And Compelling Visualizations To See How Youre Doing

Authors: Katherine Rowell ,Lindsay Betzendahl ,Cambria Brown

1st Edition

1119680883, 978-1119680888

More Books

Students also viewed these Databases questions

Question

recognise typical interviewer errors and explain how to avoid them

Answered: 1 week ago

Question

identify and evaluate a range of recruitment and selection methods

Answered: 1 week ago

Question

understand the role of competencies and a competency framework

Answered: 1 week ago