0% found this document useful (0 votes)
23 views8 pages

Unit III - Tower of Hanoi

Uploaded by

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

Unit III - Tower of Hanoi

Uploaded by

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

Tower of Hanoi

Tower of Hanoi
• Tower of Hanoi, is a mathematical puzzle which consists of three
towers (pegs) and more than one rings is as depicted −

• These rings are of different sizes and stacked upon in an


ascending order, i.e. the smaller one sits over the larger one.
There are other variations of the puzzle where the number of
disks increase, but the tower count remains the same.
Concept
• There are three pegs say A, B and C.
• The different diameters of n discs are placed one above the other.
• Peg A is Source peg, Peg B is intermediate or temporary peg and peg
C is destination peg.
• The problem is to shift all discs from Peg A to Peg C by making
temporary Peg
• The rules to be followed while transferring the disc are:
• Only one disk can be moved among the towers at any given time.
• Only the "top" disk can be removed.
• No large disk can sit over a small disk.
The initial setup is

• After transferring all the disc to peg C from peg A,


Algorithm for Tower of Hanoi can be driven as follows −
START
Procedure Hanoi(disk, source, dest, temp)

IF disk == 1, THEN
move disk from source to dest
ELSE
Hanoi(disk - 1, source, temp, dest) // Step 1
move disk from source to dest // Step 2
Hanoi(disk - 1, temp, dest, source) // Step 3
END IF

END Procedure
STOP

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy