Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this assignment we will compare the computational time taken by a recursive algorithm to determine the Fibonacci number of an integer n and the

In this assignment we will compare the computational time taken by a recursive algorithm to determine the Fibonacci number of an integer n and the time taken by a bottom-up approach (using a loop) to calculate the Fibonacci number of the same integer n.

A Fibonacci number F(n) is determined by the following recurrence function:

F(0) =0; F(1)=1;

F(n)= F(n-1) + F(n-2), for n 2

Thus the recursive algorithm can be written in C++ as

int FiboR ( int n) // array of size n

{ if (n==0 || n==1)

return (n);

else return (FiboR (n-1) + FiboR(n-2));

}

And the non-recursive algorithm can be written in C++ as

int FiboNR ( int n) // array of size n

{ int F[max];

F[0]=0; F[1]=1;

for (int i =2; i <=n; i++)

{ F[n] = F[n-1] + F[n-2];

}

return (F[n]);

}

While FiboR takes exponential time FiboNR takes n steps

Write an algorithm that computes the time (in seconds using ctime.h header library file that takes to determine Fibonacci (n) using FiboR and the time taken by FiboNR on the same input n.

Try to run both routines using different values of n (n={1,5,10,15,20,25,30,35,40,45,50,55,60)

You final output should look like:

Fibonacci time analysis (recursive vs. non-recursive)

Integer FiboR (seconds) FiboNR(seconds) Fibo-value

1 XX.XX XX.XX 1

5 XX.XX XX.XX 5

.. .. ..

60 XX.XX XX.XX XXXXXXXXXX

PLEASE HELP, I NEED SAME OUTPUT, MUST FOLLOW DIRECTIONS, AND PLEASE DONT COPY FROM OTHER WEBSITES. MUST BE ORIGINAL WORK.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Analysis Using SQL And Excel

Authors: Gordon S Linoff

2nd Edition

111902143X, 9781119021438

More Books

Students also viewed these Databases questions

Question

Compare the current team to the ideal team.

Answered: 1 week ago

Question

Are the rules readily available?

Answered: 1 week ago

Question

Have ground rules been established for the team?

Answered: 1 week ago