Question: JAVA PROGRAMMING QUESTION: Write a main method that calculates the 20th through 40th Fibonacci numbers using both the iterative and recursive methods, and time how

JAVA PROGRAMMING QUESTION:

Write a main method that calculates the 20th through 40th Fibonacci numbers using both the iterative and recursive methods, and time how long it takes each method to execute (rounded to the nearest millisecond). Your program should output the results in a table. For example:JAVA PROGRAMMING QUESTION: Write a main method that calculates the 20th through

n n Iterative Recursive ========= ========= 20 21 22 1 23 1 24 3 25 5 8 26 27 @ 13 28 21 29 36 30 58 93 31 32 149 243 33 34 394 637 35 36 37 1027 1668 2699 38 39 4351 7016 40 This table shows that it takes less than a half a millisecond (which is rounded to 0 ms) to calculate each of the Fibonacci numbers when using iteration, but it takes up to 7 seconds to calculate the same values when using recursion! When you run your program on your own computer, you should not expect to get exactly the same results. My computer and your computer probably have different hardware, and the exact execution times will vary. You can read about a simple way to measure execution time here c

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!