subject

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 powerl to compute b, where b is of type double and n is an integer20 Use a simple for-loop that repeatedly (n times) multiplies an accumulator variable byb Part II Write a recursive method power2 that accomplishes the same task as powerl, but is based on the following recurrence relation Part III Write a recursive method power3 that is identical to power2 except that it is based on this recurrence relation b0- 1 bn (bn/2)2 bn-b (bn/2)2 ifn> 0 and n is odd (Note: This equation is not true in math. Why is it true in Java?) if n>0 and n is even Note: If n is a large exponent, then power3 should perform far fewer multiplications than power2. In particular, when computing something like (b2, there is no need to compute b2 twice. Rather, compute it once, store it in a variable, and then compute the result of multiplying the variable by itself. Part IV Write a tail recursive helper method called multPow, that computes the value of a b. Base your implementation on the following recurrence relation: a*bn-a*(b2)n/2 if n>0 and n is even if n>0 and n is odd Then write a method called power4 that computes b simply by making the call multPow(, b, n). Note that in this approach, the extra parameter a used by the helper method is serving as an accumulator for the result.

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 21.06.2019 21:00
In this lab, you add a loop and the statements that make up the loop body to a c++ program that is provided. when completed, the program should calculate two totals: the number of left-handed people and the number of right-handed people in your class. your loop should execute until the user enters the character x instead of l for left-handed or r for right-handed. the inputs for this program are as follows: r, r, r, l, l, l, r, l, r, r, l, x variables have been declared for you, and the input and output statements have been written.
Answers: 3
question
Computers and Technology, 22.06.2019 21:30
Im doing this last minute and literally none of my neighbors or people that my dad works with use excel so if anyone could me make up an example
Answers: 1
question
Computers and Technology, 23.06.2019 06:00
How can a user delete a drawing object
Answers: 1
question
Computers and Technology, 23.06.2019 13:00
Donnie does not have powerpoint. which method would be best for elana to save and share her presentation as is? a pdf a doc an rtf a ppt
Answers: 3
You know the right answer?
Computing Powers This problem is a case study in using recursive thinking to improve the efficiency...
Questions
question
History, 10.11.2020 05:20
question
Mathematics, 10.11.2020 05:20
question
History, 10.11.2020 05:20
question
Mathematics, 10.11.2020 05:20
question
Mathematics, 10.11.2020 05:20
question
Mathematics, 10.11.2020 05:20
Questions on the website: 13722360