subject

Compare Fibonacci (recursion vs. bottom up)

In this project 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[i] = F[i-1] + F[i-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

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 07:00
For all machines-not just hammers- the user applies force force to the machine to the machine over a certain distance. a. input b. output c. duo d. none of the above
Answers: 1
question
Computers and Technology, 22.06.2019 10:30
How can a user open a blank presentation? 1.on the file menu, click new, and then click recent templates 2.on the file menu, click new, and then click blank presentation 3. on the view menu, click templates, and then click recent templates 4. on the view menu, click samples, and then click blank presentation
Answers: 1
question
Computers and Technology, 23.06.2019 12:00
3. when you right-click a linked spreadsheet object, what commands do you choose to activate the excel features? a. linked worksheet object > edit b. edit data > edit data c. linked spreadsheet > edit d. object > edit data
Answers: 2
question
Computers and Technology, 24.06.2019 01:10
Create a program that will take in a single x and y coordinate as the origin. after the input is provided, the output should be all of the coordinates (all 26 coordinates read from the “coordinates.json” file), in order of closest-to-farthest from the origin.
Answers: 1
You know the right answer?
Compare Fibonacci (recursion vs. bottom up)

In this project we will compare the computa...
Questions
Questions on the website: 13722363