Question: This lab is about timing different algorithms for calculating the nth fibonacci number. I have given you code to show you how to time algorithms,
This lab is about timing different algorithms for calculating the nth fibonacci number.
I have given you code to show you how to time algorithms, as well as the first algorithm.
The algorithm I have given you is a recursive method for calculating fibonacci numbers.
For this lab you must write another method for calculating fibonacci numbers that is NOT recursive.
Then time both of these methods with a small, medium, and large number.
Write comments in your code with the resulting times and values.
Explain the trend in the times that you observed.
This is the code already provided:
public class Timer
public static void mainString args
long startTime System.currentTimeMillis;
Code you want to time goes in between the System.currentTimeMillis calls.
Feel free to duplicate this block to time more methods.
long endTime System.currentTimeMillis;
System.out.printlnendTime startTime;
public static int fibRecint num
if num
return ;
return fibRecnum fibRecnum ;
public static int fibIterint num
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
