Answered step by step
Verified Expert Solution
Question
1 Approved Answer
* * * * * * * * * * * * * * * * * * * * * * * * *
public class Fibonacci
public static long calculateFibonacciNumberint n
To Do
public static void mainString args
int n Integer.parseIntargs;
System.out.printlncalculatesFibonacciNumbern;
Use the Java code template above to implement the linear time Fibonacci algorithm shown below. Name the Java file LinearFibonacci.java.
function fibn
if n: return
create an array fn
f f
for i n:
fi fi fi
return fn
Test your Java Fibonacci program with n You may have to come with large integer numbers to see the effect on the algorithm runtime.
Use the R code below to measure and visualize the runtime.
k
ns :k
runtime vectorlength k
for i in :k
n nsi
# Measure execution time of Java program
command pastejava Fibonacci", n
# Measure execution time and convert to microseconds
runtimei system.timesystemcommand intern TRUEuserself"e
# Plotting the results
plotns runtime, type b xlab n ylab "runtime microsecond
gridcol "blue"
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