No moves yet
To move n disks from source to destination:
function hanoi(n, from, to, aux) {
if (n == 1) move(from, to);
else {
hanoi(n-1, from, aux, to);
move(from, to);
hanoi(n-1, aux, to, from);
}
}
Recurrence Relation:
T(n) = 2T(n-1) + 1, T(1) = 1
Solution:
T(n) = 2ⁿ - 1
Examples:
• Move all disks from Tower 1 to Tower 3
• Only one disk can be moved at a time
• A larger disk cannot be placed on a smaller disk
• Click and drag disks or use manual controls
• Mouse: Click and drag disks
• Keyboard: 1,2,3 to select/move towers
• Space: Toggle disk selection
• R: Reset game
• Step through the recursive algorithm
• Watch how subproblems are solved
• Visualize recursion in action