Question: 8. In class we discussed a recursive algorithm, Pow2(n), to compute 2 for nonnegative integer n. The algorithm runs in O(n) time. By using the

 8. In class we discussed a recursive algorithm, Pow2(n), to compute

8. In class we discussed a recursive algorithm, Pow2(n), to compute 2" for nonnegative integer n. The algorithm runs in O(n) time. By using the following recurrence relation, it is possible to develop an algorithm with better running time. 2 = 1. 2n = (21/2)*(21/2), when n > 0 and is even 2n = (2n/2)*(21/2)*2, when n > 0 and is odd (The divisions above are integer divisions). Write an algorithm in pseudo code to compute 2" for nonnegative integer n. The algorithm should have time complexity Odlog n). (12 points)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!