- What procedure suggests:
If n=1 move the disk from source to
destination.
Otherwise
(i) Move n-1 disks
from source to temp. peg by using destination
peg as auxiliary.
(ii)Move nth disk from temp. to destination then move n-1
disks using source peg as c auxiliary.
- An alternative for easy manual tracing.
(I) If n!=1then lftchild ={n-1,S,D,T} and
rtchild={n-1,T,S,D}
Do this
till n=1;
For n=3 you will get tree as shown in
fig. to get moves go for inorder traversal of tree,
( Move nth disk from source to
destination.{n, s, t, d} )
Inorder Traversal
1. Traverse the left sub tree in inorder.
2. Visit the root.
3. Traverse the right sub tree in inorder.
Do the Inorder traversal for the above problem
1. Traverse the left sub tree in inorder.
2. Visit the root.
3. Traverse the right sub tree in inorder.
Move disk 1 from A to C.
Move disk 2 from A to B.
Move disk 1 from C to B.
Move disk 3 from A to C.
Move disk 1 from B to A.
Move disk 2 from B to C.
Move disk 1 from A to C.
No comments:
Post a Comment