Analyzing the exact complexity of recursive functions can be difficult to do. Finding the Big O of them can be somewhat eyeballed by drawing out charts of how many calls are made for a recursive function to solve a problem. Take the Fibonacci sequence, which has much less repeated work when calculated with iteration but is very elegant to write with recursion (without tail call optimization). (a) Using the description of Fibonacci below to draw out a recursive Fibonacci call for fibonacci(5), the 5th Fibonacci number. The actual calculated values are not as important as the number passed into each Fibonacci call. Just write out the call tree until the termination of the tree down at each F(1) and F(0) leaf. (b) There are many repeated calls going down the recursion tree, especially when calculating the low Fibonacci numbers. If we used record keeping to remember what we calculated previously (of- ten called dynamic programming) then these repeated calculations all the way down the tree would not happen. Keep track of what Fibonacci numbers you’ve calculated and returned back up the tree previously (the tree is evaluated left to right). Cross out the calls that would be eliminated if you used this record keeping approach. (c) Based on the number of function calls, what would you call the complexity of the original recursive Fibonacci? How does the overall complexity of the Fibonacci change if you cut out these repeated calls with the record keeping? Would it make more sense to use iterative Fibonacci or the record keeping recursive Fibonacci? i n t  f i b o n a c c i ( i n t n ) { i f ( n < 2 ) r e t u r n n ; r e t u r n. f i b o n a c c i ( n−1) + f i b o n a c c i ( n−2); }

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Analyzing the exact complexity of recursive functions can be difficult to
do. Finding the Big O of them can be somewhat eyeballed by drawing
out charts of how many calls are made for a recursive function to solve
a problem. Take the Fibonacci sequence, which has much less repeated
work when calculated with iteration but is very elegant to write with
recursion (without tail call optimization).

(a) Using the description of Fibonacci below to draw out a
recursive Fibonacci call for fibonacci(5), the 5th Fibonacci number.
The actual calculated values are not as important as the number
passed into each Fibonacci call. Just write out the call tree until the
termination of the tree down at each F(1) and F(0) leaf.

(b) There are many repeated calls going down the recursion
tree, especially when calculating the low Fibonacci numbers. If we
used record keeping to remember what we calculated previously (of-
ten called dynamic programming) then these repeated calculations
all the way down the tree would not happen. Keep track of what
Fibonacci numbers you’ve calculated and returned back up the tree
previously (the tree is evaluated left to right). Cross out the calls
that would be eliminated if you used this record keeping approach.

(c) Based on the number of function calls, what would you
call the complexity of the original recursive Fibonacci? How does
the overall complexity of the Fibonacci change if you cut out these
repeated calls with the record keeping? Would it make more sense
to use iterative Fibonacci or the record keeping recursive Fibonacci?

i n t  f i b o n a c c i ( i n t n )
{
i f ( n < 2 ) r e t u r n n ;
r e t u r n. f i b o n a c c i ( n−1) + f i b o n a c c i ( n−2);
}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY