fib(5) = 5 — three approaches
🚫 Naive RecursionO(2ⁿ)
no cache — recomputes everything
15 calls💾 Memoization (top-down)O(n)
cache computed values
9 calls✅ Bottom-up DPO(n)*
*O(1) space keeping last 2
~6 itersNaive fib(5): 15 function calls, exponential redundancy.
fib(5) calls fib(4) AND fib(3) — the call tree doubles every level = O(2^n).
15 calls
1 / 10
SPD0.5×
click to pause · hover for controls · fullscreen for more
Fibonacci
Why naive recursion is O(2ⁿ) — and how memoisation fixes it
Visual by thisgirltech
BeginnerConcept