Question: Overview Web Page Template ssignment, we will implement two well-known recursive algorithms: Fibonacci and the Towers of Hanoi. For Fibonacci, we will compare an iterative


Overview Web Page Template ssignment, we will implement two well-known recursive algorithms: Fibonacci and the Towers of Hanoi. For Fibonacci, we will compare an iterative and a recursive approach. Part 1 In the first part of this lab assignment, you will write two versions of Fibonacci and will compare thenm 1. The recursive version o This version has been presented during the lectures o Base case: o Recursive: Fibonacci(n-1) + Fibonacci (n-2) 2. The iterative version The iterative version of the algorithm will calculate the nth Fibonacci number by calculating the 0th-nth Fibonacci numbers, in a linear way. This is similar to the linear recursion version presented in the lectures, but you will use a loop instead of recursion in your solution To compare the two algorithms, write code similar to the previous lab to count the number of recursive calls in the recursive version, and count the number of iterations in the loop of the iterative version. Below, you will find some test code: public static void main(String[] args) System.out.println("Fibonacci:") int n = 15; resetCallcount(); int recursiveResult fibonacc1Rec (n); int recursiveCalls getCallCount(); System . out .printf( "Recursive result: %d (%d recursive calls) ", recursiveResult, recursiveCalls); resetCallCount( ); int iterativeResult = fibonacci!ter ( n); int iterations = getCal!Count(); system . out .print f ("Iterative result : %d (2d iterations) ", iterativeResult, iterations)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
