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 +...


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?



Jan 02, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here