Question: Give an algorithm that takes as input a positive integer n and a number x, and computes x^2 (i.e., x raised to the power n)
Give an algorithm that takes as input a positive integer n and a number x, and computes x^2 (i.e., x raised to the power n) by performing O(lg n) multiplications. Your algorithm CANNOT use the exponentiation operation, and may use only the basic arithmetic operations (addition, subtraction, multiplication, division, modulo). Moreover, the total number of basic arithmetic operations use should be O(lg n). (Hint, Use divide and conquer).
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
