🌳 Recursion & Memoization Explorer

The same Fibonacci function, two ways: naive recursion recomputes the same subproblems a staggering number of times, while memoization remembers each answer once. Watch the call tree fill with duplicates, and see the gap explode on the chart.

What you're seeing

Left: the call tree for fib(tree-n). Every box is one function call — the same colour means the same subproblem, so identical-coloured boxes are wasted duplicate work. Right: a log-scale bar chart of total function calls: naive (red) grows like 2ⁿ, memoized (green) grows linearly. Memoization turns an exponential explosion into a straight line — the same trick behind dynamic programming.