Question
Case 3: Fibonacci sequence For each case, we want to plot input (n x-axis) verses execution time (t y-axis). Each of the above cases has
Case 3: Fibonacci sequence
For each case, we want to plot input (n x-axis) verses execution time (t y-axis). Each of the above cases has two programs to solve the corresponding problem. We want to compare the behavior of both programs (i.e. practical comparison) by prepare a figure using Excel. Each figure should have two lines, one for the first program and the other for the second program. In addition to the figures, provide the collected data in separated tables.
Case 3: Fibonacci numbers is famous formula in mathematics that generates a sequence of numbers in which the next number is computed based on the previous two numbers (1, 1, 2, 3, 5, 8, 13, 21, 34,).
Program 1 (recursive method) | Program 2 (Dynamic Programming method) |
#include using namespace std;
int fib(int n) { if (n<=1) return n; else { return fib(n-1)+fib(n-2); } } main() { int n; cout<<"input n: "; cin>>n; for (int i=0;i cout< } | #include using namespace std; void fib(double A[], int n) { A[0]=0;A[1]=1; for (int i=2;i A[i]=A[i-1]+A[i-2]; } main() { int n; cout<<"input n: "; cin>>n; double A[n]; fib(A,n); for (int i=0;i cout< } |
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