Dynamic Programming21 sections · 916 units
Open in Course

Visualization - Fibonacci Tree

Explosion of calls

Before you look at this tree, make a prediction: how many times do you think fib(2)fib(2) gets calculated when computing fib(5)fib(5)? Once? Twice? More? Hold that guess.

Here's the call tree for fib(5)fib(5): Notice fib(3)fib(3) computed twice, fib(2)fib(2) three times, fib(1)fib(1) five times! You're doing the same work over and over. This is the main problem you need to fix. Tracing through examples helps build intuition for how it works.