Answered step by step
Verified Expert Solution
Question
1 Approved Answer
(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 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started