Question: Need help with question b) ! In a Fibonacci sequence, each number is the sum of the two preceding ones, starting from 0 and 1.

Need help with question b) !

Need help with question b) ! In a Fibonacci sequence, each number

In a Fibonacci sequence, each number is the sum of the two preceding ones, starting from 0 and 1. The beginning of the sequence is: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ... Write a C++ program, no need to be object-oriented, to find the nth number in a Fibonacci sequence using two different approaches. Each approach is implemented by a function that takes n as its only parameter. One function solves the problem only recursively. The other function solves the problem recursively but with the support of dynamic programming. For the dynamic programming implementation, you are allowed to define the needed array as a global variable. You are not allowed to use any loop in your functions. The only loop you will need in your program is the one in the main() function, right before calling the dynamic version function. You need this loop to initialize all elements in the array to an invalid Fibonacci number (e.g., -1) to keep track of the array elements that do not have a Fibonacci number calculated yet. Test your code with n values 5, 10, 20, 30, 40 Submit your test program and in your report answer the following questions: a) Comment on the running time of each function. b) For each function, find the big O asymptotic notation of its running time growth rate

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!