The Tower of Hanoi
The Tower of Hanoi
The Tower of Hanoi problem is a classic puzzle that involves moving a stack of disks from
one peg to another, with the constraint that smaller disks must always be on top of larger
ones. The problem is typically formulated with three pegs and a set of disks of different sizes.
Here's how you can represent the Tower of Hanoi problem:
Initial State:
Three pegs: A, B, and C.
A stack of n disks on peg A, with the largest disk at the bottom and the smallest disk at the
top.
Goal State:
Move all the disks from peg A to peg C, preserving the order of larger disks on the bottom
and smaller disks on top.
Set of Rules:
Only one disk can be moved at a time.
A disk can only be placed on top of a larger disk or an empty peg.
Only the top disk on a peg can be moved.
Solution Search Tree:
To solve the Tower of Hanoi problem, you can use a recursive algorithm. Each node in the
search tree represents a state of the problem, where the state includes the configuration of the
disks on each peg. The edges represent valid moves between states, following the rules
mentioned earlier. Here's a simplified example of the solution search tree for a Tower of
Hanoi problem with 3 disks (n=3):
Initial State: Goal State:
A -> [3, 2, 1] C -> [3, 2, 1]
B -> [] B -> []
C -> [] A -> []
Move B to A:
A -> [3, 1]
B -> [2]
C -> [1]
Move C to B:
A -> [3]
B -> [2, 1]
C -> []
Move A to B:
A -> []
B -> [3, 2, 1]
C -> []