SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Walter Savitch ,kenrick Mock
Chapter:
Recursion
Exercise:
Programming Projects
Question:7 | ISBN:9780132846813 | Edition: 5

Question

(You need to have first completed Programming Project 13.6 to work on this project.) When computing a Fibonacci number using the most straightforward recursive function definition, the recursive solution recomputes each Fibonacci number too many times. To compute Fi+2 = Fi + Fi+1, it computes all the numbers computed in Fi a second time in computing Fi+1 . You can avoid this by saving the numbers in an array while computing Fi. Write another version of your recursive Fibonacci function based on this idea. In the recursive solution for calculating the N th Fibonacci number, declare an array of size N. Array entry with index i stores the ith ( ) Fibonacci number as it is computed the first time. Then use the array to avoid the second (redundant) recalculation of the Fibonacci numbers. Time this solution as you did in Programming Project 13.6 , and compare it to your results for the iterative solution.


TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Sorry the answer is not available at the moment…

If you are able to find the answer, please make sure to post it here. So that your Juniors have smile on their lips and feel happy.

Spread the 'tradition of sharing'.