Rewrite the recursive pow method from Figure 8.11 so that the time to compute pow(x, n) is

Question:

Rewrite the recursive pow method from Figure 8.11 so that the time to compute pow(x, n) is log(n). 

FIGURE 8.11 Altemative Implementation of a Method to Compute Powers Implementation public static double pow(double x, int n) if (x == 0 && n  0) return x * pow(x, n-1); else // x is nonzero, and n is negative. return 1/pow (x, -n); 0) == }

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Related Book For  book-img-for-question
Question Posted: