Similar questions 1 more →
Asymptotic Analysis & Recurrences


Answer & solution
Answer: 41 (no official key was published)
Step through it (23 steps)
Let C(n) count function invocations. Each base case requires one call, so C(0)=C(1)=1. A nonbase invocation counts itself plus both recursive subtrees: C(n)=1+C(n−1)+C(n−2). Successive values for n=2, …, 7 are 3, 5, 9, 15, 25, 41. This count includes repeated evaluation of identical arguments, as the supplied recursion does not memoize them. It is different from the numeric return value fib(7)=21; counting only leaves or only additions would also answer a different question.