Skip to content

Why it matters

Memoization turns exponential-time recursive algorithms into linear-time ones, without changing the algorithm itself.

Consider a naïve Fibonacci implementation: fib(n) = fib(n-1) + fib(n-2). Without memoization, fib(40) makes ~300 million calls. With memoization, it makes 40. The algorithm is the same; the cache collapses the redundant subtrees.