This problem is a case study in using recursive thinking to improve the efficiency of an iterative algorithm.

computer science

Description

Computing Powers 

This problem is a case study in using recursive thinking to improve the efficiency of an iterative algorithm. You will write a sequence of methods for the exponentiation of floating point numbers. Parts I and II involve writing rather simple-minded iterative and recursive methods for the task. In Parts III and IV you use more sophisticated recurrence relations in order to write more efficient recursive methods. In Part V you convert your method from Part IV into an iterative method that is far more efficient than the Part I iterative method.


You may put all of your code for this project into a single class file – PowersUsername.java. All of your methods should be static.


Part I: 

Write an iterative method called power1 to compute bn , where b is of type double and n is an integer ≥ 0. Use a simple for-loop that repeatedly (n times) multiplies an accumulator variable by b.


Part II: 

Write a recursive method power2 that accomplishes the same task as power1, but is based on the following recurrence relation:


Related Questions in computer science category