Question: Implement A Method That Returns The Value Of The Function Xn RECURSIVELY, Where X Is The Base And N Is The Exponent. The Way That
Implement a method that returns the value of the function xnRECURSIVELY, where x is the base and n is the exponent.
The way that we will compute this value is by using the concept of fast exponentiation, given by this definition:
Non-recursive implementations will not receive credit
You CANNOT use the pow(double a, double b) method from the Math class. Implementations that use this method will not receive credit
public class Q5 { /** * Returns the value of the function x^n RECURSIVELY using fast exponentiation, * where x is the base and n is the exponent. * * Non-recursive implementations will not receive credit * WARNING: You CANNOT use the pow(double a, double b) method from the Math class. * @param x - base * @param n - exponent * @return value of x^n */ public static double pow(double x, int n) { /*ADD YOUR CODE HERE*/ return 0.0; //Dummy Return }
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
