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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!