Question: (2) (10 pts) Consider the problem of computing xn, given positive integers x and n. We can easily do this in O(n) time with a

 (2) (10 pts) Consider the problem of computing xn, given positive

(2) (10 pts) Consider the problem of computing xn, given positive integers x and n. We can easily do this in O(n) time with a simple loop. Suppose n is a power of 2 . Then, we can find xn in O(logn) time as follows: first recursively compute y=x2n (using the same algorithm), and then return yy. Convince yourself first that this will yield an O(logn) time algorithm. For example, when n=16, first recursively compute y=x8, and then return yy (when does recursion stop?). But, this can also be done in general, even when n is not a power of 2 . Observe, for example, that x10=x5x5, and x13=x6x6x. (a) Present an O(logn) time algorithm that, given positive integers x and n, computes and returns xn. (b) Let T(n) be the complexity of your algorithm when invoked with x and n. Model T(n) as a recurrence and provide a bound for it

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!