Introduction
The Tower of Hanoi is one of the most famous problems in computer science, invented by French mathematician Édouard Lucas in 1883.
The puzzle demonstrates the power of recursion: solving a problem by breaking it into smaller instances of the same problem.
Legend: According to myth, monks in a temple are moving 64 golden disks between three diamond pegs. When they finish, the world will end. At one move per second, this would take about 585 billion years!
Why it matters:
- Foundation for understanding recursive algorithms
- Appears in technical interviews
- Models real-world problems (backup strategies, memory management)
The Key Insight
To move disks from A to C, you cannot move the largest disk until all other disks are out of the way.
The insight: To move disks from source to destination:
- First, move the top disks somewhere else (to the auxiliary peg)