subject
Mathematics, 12.03.2020 05:42 austinhamy1

The fundamental source of the inefficiency is not the fact that recursive calls are being made, but that values are being recomputed. One way around this is to compute the values from the beginning of the sequence instead of from the end, saving them in an array as you go. Although this could be done recursively, it is more natural to do it iteratively. Proceed as follows: a. Add a method fib2 to your Fib class. Like fib1, fib2 should be static and should take an integer and return an integer. b. Inside fib2, create an array of integers the size of the value passed in. c. Initialize the first two elements of the array to 0 and 1, corresponding to the first two elements of the Fibonacci sequence. Then loop through the integers up to the value passed in, computing each element of the array as the sum of the two previous elements. When the array is full, its last element is the element requested. Return this value. d. Modify your TestFib class so that it calls fib2 (first) and prints the result, then calls fib1 and prints that result. You should get the same answers, but very different computation times.

ansver
Answers: 1

Another question on Mathematics

question
Mathematics, 21.06.2019 16:00
Which ahows the graph of the solution set of 6x+4y< 12
Answers: 3
question
Mathematics, 21.06.2019 21:00
If there are 3.281 feet in 1 meter, how many inches are in one centimeter
Answers: 1
question
Mathematics, 22.06.2019 00:00
What are the interpretations of the line 3x - 15y = 60? x-intercept y-interception a: x 20 - y -4 b: x 5 - y 20 c: x -3 - y 15 d: x -4 - y 20
Answers: 1
question
Mathematics, 22.06.2019 02:20
What are the solutions of the equation x4 – 5x2 – 14 = 0? use factoring to solve. someone !
Answers: 2
You know the right answer?
The fundamental source of the inefficiency is not the fact that recursive calls are being made, but...
Questions
question
Mathematics, 29.01.2020 10:48
question
English, 29.01.2020 10:48
question
History, 29.01.2020 10:48