The legend of the Tower of Hanoi puts 64 discs at 2⁶⁴−1 moves, over eighteen quintillion lifts, and yet the entire solution fits in one sentence that calls itself: move n−1 discs to the spare peg, shift the bottom disc, repeat. Every call occupies a frame on the stack and the stack is finite, so a missing base case overflows it. Naive Fibonacci branches in two at every level, so the same fib(k) is recomputed exponentially often; once results are memoized the duplicate branches are lopped off and the call tree collapses to something close to linear.
The legend of the Tower of Hanoi puts 64 discs at 2⁶⁴−1 moves, over eighteen quintillion lifts, and yet the entire solution fits in one sentence that calls itself: move n−1 discs to the spare peg, shift the bottom disc, repeat. Every call occupies a frame on the stack and the stack is finite, so a missing base case overflows it. Naive Fibonacci branches in two at every level, so the same fib(k) is recomputed exponentially often; once results are memoized the duplicate branches are lopped off and the call tree collapses to something close to linear.
Related topics in Mind & Machine