Implement a naive recursive (top-down) algorithm to compute the Fibonacci numbers.
Implement an improved recursive (top-down) algorithm to compute the Fibonacci numbers.
Implement an improved iterative (bottom-up) algorithm to compute the Fibonacci numbers.
Measure and compare the performance of the three algorithms.
Fibonacci numbers are the basis of the simple example used for this programming assignment. Fibonacci numbers Fi are defined as follows: Fo=0, F=1, Fn= Fn-1 + Fn-2 for any number n ≥ 2.
I) Algorithm I: Implement this naive recursive (top-down) algorithm to compute the Fibonacci numbers:
Fibonacci(n)
if (n == 0)
return 0;
if (n == 1)
return 1;
return (Fibonacci(n-1) + Fibonacci(n-2));
2) Algorithm 2: The above algorithm is inefficient because it calls the function Fibonacci multiple times to recompute the ith Fibonacci number many times. For example, trace the execution of Fibonacci(6) and compute the number of times you call Fibonacci(2). Report this number in your final written report (worth 10 points).
In order to improve the efficiency of the recursive algorithm, an idea would be to store the value Fibonacci(i) in some table Fib(i) whenever we compute it the first time. For the consecutive times when Fibonacci(i) is needed, bring it out of Table Fib. This method is called memoization: it is a trade-off space versus time. Improve the above algorithm by using memoization (hint: Use and initialize the table Fib(i) with -1 (−1 is not a Fibonacci number). Whenever you need Fibonacci(i), check if Fib(i) != -1 ....). Provide the pseudocode of your solution (in the report) and implement it in your preferred language.
3) Algorithm 3: Implement an iterative (bottom-up) version. This means that you must implement an iterative loop from F0, F1, F2, F3, ..., until you reach Fn. Provide the pseudocode of your solution (in the report) and implement it in your preferred language.
Data collection and analysis:
For each algorithm A (1) naive recursive (top-down), (2) recursive with memoization, and (3) iterative (bottom-up), collect the execution times t(A) to compute the Fibonacci number for i = 0 to i = 55 using Algorithm A.
Compare, discuss, and analyze the results of the three algorithms.