Question: This problem is for Python language. Thank you. 3. Checkpoint 3: As we saw in Lab 01, the Fibonacci sequence is calculated recursively by summing

 This problem is for Python language. Thank you. 3. Checkpoint 3:

This problem is for Python language. Thank you.

3. Checkpoint 3: As we saw in Lab 01, the Fibonacci sequence is calculated recursively by summing the previous two values of the sequence, i.e., fib (n)=fib (n-1)+fib(n-2). As with Lab 01, assume that this sequence starts with 0 and 1 as its first two elements For this checkpoint, write code to calculate the nth Fibonacci number for up to 10 inputs given by the user on the command-line (hint: use argc to determine the number of inputs and atoi) to convert each input into an integer). Use a naive approach in which you simply calculate each Fibonacci number in turn using either a recursive or iterative approach. An example of program execution is as follows: bash$./a.out 4 11 8 fib 4) is 3 fib (11) is 89 fib (8) is 21 Repeatedly calculating the nth Fibonacci number with varying values of n requires a lot of repetitive computation. A better approach is to store results of previous computations for future use. This technique is called memoization. Next, write an optimized version that stores previously computed Fibonacci numbers in a global array of values that you dynamically allocate at program startup. Pre-fill this array with sentinel values of zero, which will let you check whether the requested value has already been computed or not. As an example, if fib(n) is non-zero, then you know that that value has already been computed and you can return that as the solution. Otherwise, you must compute fib(n), though you can possibly utilize some pre-computed values. Once you've tested your solutions, prepend the time command to your normal command line for both your naive and optimized versions, as in: bash$ time./a.out 4 11 8 13 9 5 Was there a noticeable difference? What was the tradeoff here? And is there a further optimized version you could write

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!