How to use the Tower of Hanoi Visualizer
- 1. Set it upChoose 1 to 8 disks.
- 2. RunPress Solve to generate the minimum moves.
- 3. ReplayPlay or step through; the disk that just moved is highlighted.
Worked example: 4 disks
With 4 disks the solution takes 15 moves, which is 2⁴ − 1. It starts disk 1 A→B, disk 2 A→C, disk 1 B→C, disk 3 A→B, and so on. The smallest disk moves on every other move, 8 times in all. With 8 disks the count is 255, and every extra disk doubles it and adds one.
The recursive idea
To move n disks from A to C, first move the top n − 1 disks out of the way to B, then move the largest disk to C, then move the n − 1 disks from B onto it. Each of those smaller moves uses the same rule. That gives the recurrence T(n) = 2T(n − 1) + 1, which works out to 2ⁿ − 1, and no shorter solution exists because the largest disk can only move once the n − 1 disks above it are out of the way.
Using it to understand recursion
Students often find recursion hard because they try to follow every call. Hanoi shows why you don't have to: trust that the smaller call works, and only think about the current step. Compare with the recursion tree visualizer, which draws the calls for Hanoi as a tree with 2ⁿ − 1 non-empty calls.
Frequently asked questions
Can I play it myself?
This tool shows the optimal solution. Try predicting each move before pressing Next.
Why is 8 the maximum?
With 8 disks there are already 255 moves; more would be too long to replay.
What's the iterative solution?
Move the smallest disk one way in a cycle every other move, and make the only other legal move in between.
Is the Tower of Hanoi visualizer free?
Yes. You can use the Tower of Hanoi visualizer without signing up. The first time you run it, we ask once for your name and WhatsApp number; after that the Tower of Hanoi visualizer and every other Uncodemy tool open straight away.