Calls in fib(5)
Warm-up · Trace the algorithm · about 4 min
Naive fib(5) calls itself again and again. Before the tree grows, predict how many calls it makes in total, the first call included.
Example 1
Input:
{"n":5}
Output:
5
fib(5) returns 5; the question is how many calls it takes.
Constraints
- The trace uses n = 5.
Learn the idea first: Recursion trees: Fibonacci and repeated work, a visual lesson.
More Recursion trees: Fibonacci and repeated work problems
- Fibonacci, the naive way Warm-up
- Order of calls Standard
- Repeated subproblems Standard
- Count the calls of fib Standard
- Climbing stairs Standard
- Count leaves of the call tree Challenge