Question: Java program cannot use Math.pow() or other functions! a. Write an iterative method power1 to compute x^n for n>= 0. b. Write a recursive method
Java program cannot use Math.pow() or other functions!
a. Write an iterative method power1 to compute x^n for n>= 0.
b. Write a recursive method power2 to compute x^n by using the following recursive formulation:
x^0 = 1
x^n = x * x^n -1 if n>0
c.Write a recursive method power3 to compute x^n by using the following recursive formulation:
x^0 = 1
x^n = (x^n/2)^2 if n>0 and n is even
x^n = x * (x^n/2)^2 if n>0 and n is odd
d. How many multiplication will each of the method power1, power2 and power3 perform when computing 3^32? 3^19?
e. How many recursive calls will power2 and power3 make when computing 3^32? 3^19?
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
