Question

Given two integers x and n, describe and prove an algorithm that computes xn. Is there...

Given two integers x and n, describe and prove an algorithm that computes xn.

Is there any way to go faster than O(n)?

0 0
Add a comment Improve this question Transcribed image text
Answer #1
function power(x, n)
    if n is 0
        return 1
    else if n is odd
        temp = power(n / 2)
        return x * temp * temp
    else
        temp = power(n / 2)
        return temp * temp
    end if
end

time complexity of this algorithm is O(log(n))
Add a comment
Know the answer?
Add Answer to:
Given two integers x and n, describe and prove an algorithm that computes xn. Is there...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT