0% found this document useful (0 votes)
14 views2 pages

The Tower of Hanoi

Uploaded by

Thomas Anto
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views2 pages

The Tower of Hanoi

Uploaded by

Thomas Anto
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

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 -> []

Solution Search Tree:


Initial State
/ | \
/ | \
Move A to B Move A to C Move B to C:
A -> [3, 2] A -> [3] C -> [3]
B -> [1] C -> [2] B -> [2, 1]
C -> [] B -> [] A -> [1]

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 -> []

Goal State Reached!


The solution is a sequence of moves that transforms the initial state into the goal state while
adhering to the Tower of Hanoi rules. In this example, we've shown a solution search tree for
a Tower of Hanoi problem with 3 disks, but the same principles apply for larger numbers of
disks.

You might also like