0% found this document useful (0 votes)
62 views1 page

DSA Assignment: Tower of Hanoi Explained

This document explains the Tower of Hanoi puzzle. It describes how to move disks of increasing numbers (1, 2, 3 disks) from the starting tower L to the ending tower N using the middle tower M according to the rules: only one disk can be moved at a time and no larger disk can be placed on top of a smaller disk. It notes that recursion can help solve the puzzle for any number N of disks more efficiently than manually. Pseudocode is provided for a recursive Move function to solve the puzzle.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
62 views1 page

DSA Assignment: Tower of Hanoi Explained

This document explains the Tower of Hanoi puzzle. It describes how to move disks of increasing numbers (1, 2, 3 disks) from the starting tower L to the ending tower N using the middle tower M according to the rules: only one disk can be moved at a time and no larger disk can be placed on top of a smaller disk. It notes that recursion can help solve the puzzle for any number N of disks more efficiently than manually. Pseudocode is provided for a recursive Move function to solve the puzzle.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

DSA ASSIGNMENT

TOWER OF HANOI
EXPLANATION
This tower is an interesting game . In it we have three tower L ,M and N. And size of towers increases
while coming from top to bottom. we have to move all the disks from tower L to tower N using tower M
as middle such that at no point of time a larger disk comes on top of the smaller one and one more rule
is that we can only move one disk at a time so lets see an example.

EXAMPALE
1 DISK
imagine we have just one disk . this Is simple we can just move one disk from tower L to tower N directly
. we have named the tower and numbered the disks so we can track the movement .

2 DISKS
IF there are two disks we can move upper disk from tower L to tower M and then 2nd disk from tower L
to tower N and finally previous disk from tower M to tower N.

3 DISKS
If there are three disks we will move 1 disk from tower L to N and disk 2 from tower L to M . move disk 1
from N to M and move disk 3 from L to N . now we would move both of disk 1 and 2 to tower N .

As we can only move one disk at a time so we first need to move disk 1 from tower M to tower L and
then move disk 2 from tower M to N and then finally move disk 1 from L to N .

This was little more complicated then 2 disks .so when disks are greater in size .. this is where recursion
comes and it becomes quite easy with recursion.

N DISKS
For n number of disks we will repeat the same process of recursion.
manually it would take a lot of time but by recursion the following algorathim can help.

PSEUDOCODE
Move (N,’L’,’M’,’N’)

MOVE (N-1,’L’,’M’,’N’)

Print “moving disk n from L to N”

Move (N-1,’M’,’N’,’L’)

You might also like