Course Solutions Uncategorized (Solved) : Analysis Recursive Algorithm Consider Pseudocode Following Three Algorithms Computing 2n N Q26402250 . . . .

(Solved) : Analysis Recursive Algorithm Consider Pseudocode Following Three Algorithms Computing 2n N Q26402250 . . . .

 

Analysis of recursive algorithm. Consider the pseudocode of thefollowing three algorithms for computing 2n, where n is anon-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 smallexamples (n = 2 and n = 3) to find out

OR

PayPal Gateway not configured

OR

PayPal Gateway not configured

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post