Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a java program and Implement a method called iterativeFibonacci that takes an integer, n, as a parameter and returns the nth Fibonacci value. e.g.:

Write a java program and Implement a method called "iterativeFibonacci" that takes an integer, n, as a parameter and returns the nth Fibonacci value. e.g.:
fibonacci(1) will return 1 (the 1st Fibonacci number),
fibonacci(6) will return 8 (the 6th Fibonacci number),
fibonacci(10) will return 55 (the 10th Fibonacci number),
and so on.. The return type of the method is double. This method must use iteration in its implementation.
Implement a method called "recursiveFibonacci" that does exactly what the "iterativeFibonacci" method does, except it will use recursion. It will take an integer, n, as a parameter and return the nth Fibonacci value. The return type will be double. It must use recursion.
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).
n Iterative Recursive
== ========= =========
20 0 0
21 0 0
22 0 1
23 0 1
24 0 3
25 0 5
26 0 8
27 0 13
28 0 21
29 0 36
30 0 58
31 0 93
32 0 149
33 0 243
34 0 394
35 0 637
36 0 1027
37 0 1668
38 0 2699
39 0 4351
40 0 7016

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Databases And Information Systems Uropean Conference Adbis 2020 Lyon France August 25 27 2020 Proceedings Lncs 12245

Authors: Jerome Darmont ,Boris Novikov ,Robert Wrembel

1st Edition

3030548317, 978-3030548315

Students also viewed these Databases questions

Question

What is the address size of IPv 6

Answered: 1 week ago

Question

Is there a digital divide? If so, why does it matter?

Answered: 1 week ago