Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started