Computers and Technology

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

answer
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 22:00, mrnotsosmart744
Discuss the ways in which electronic information associated with payments is addressed in terms of security. include encryption, secure sockets layers, and secure electronic transactions in your discussion. are there any other ways that consumers and businesses can keep their payment information secure in an electronic commerce environment? do you feel that your information is safe when conducting electronic business? why or why not?
Answers: 1
image
Computers and Technology, 23.06.2019 12:40, Emilyvite6251
According to the video what are some tasks petroleum engineers perform check all that apply
Answers: 2
image
Computers and Technology, 23.06.2019 15:00, puppylove899
Barbara is interested in pursuing a career in the science and math pathway. which qualifications will her reach that goal? a. an advanced knowledge of physics and math b. an advanced knowledge of engineering and math c. an advanced knowledge of physics and robotics an d. advanced knowledge of machinery and math
Answers: 1
image
Computers and Technology, 24.06.2019 10:20, silviamgarcia
Write a program that keeps asking the user for new values to be added to a list until the user enters 'exit' ('exit' should not be added to the list). these values entered by the user are added to a list we call 'initial_list'. then write a function that takes this initial_list as input and returns another list with 3 copies of every value in the initial_list. finally, inside print out all of the values in the new list. for example: input: enter value to be added to list: a enter value to be added to list: b enter value to be added to list: c enter value to be added to list: exit output: a b c a b c a b c note how 'exit' is not added to the list. also, your program needs to be able to handle any variation of 'exit' such as 'exit', 'exit' etc. and treat them all as 'exit'.
Answers: 2
Do you know the correct answer?
Compare Fibonacci (recursion vs. bottom up)

In this project we will compare the computa...

Questions in other subjects:

Konu
Mathematics, 15.06.2021 17:40
Konu
Biology, 15.06.2021 17:40
Konu
Mathematics, 15.06.2021 17:40
Konu
English, 15.06.2021 17:40