Consider the following alternative to this chapter's powerOf2 algorithm:
public static long otherPowerOf2(int n) {
if (n > 0) {
long lowerPower = otherPowerOf2(n - 1);
return lowerPower + lowerPower;
}
else {
return 1 ;
Estimate the execution time of this algorithm.
Redo the analysis of powerOf 2's execution time, counting
1. The n > 0 comparisons as well as the additions
2. The n > 0 comparisons and the subtractions as well the additions
Do these more complete analyses still suggest execution times more or less proportional to 2n, or do the times become even worse?
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here