SlideShare a Scribd company logo
1 of 20
Tower of Hanoi
What????
• Three pegs, one with n disks of decreasing diameter; two other pegs
are empty
Objective
The Objective is to transfer the entire tower to one of the other pegs.
Rules
• Only one disk may be moved at a time. Specifically, only the top disk
on any disk on any peg may be moved to any other peg.
• At no time can a larger disk be placed on a smaller disk.
Tower of Hanoi
Tower of Hanoi
Tower of Hanoi
Tower of Hanoi
Tower of Hanoi
Tower of Hanoi
Tower of Hanoi
Tower of Hanoi
Tower of Hanoi
Algorithm
Let’s call the three peg BEG(Source), AUX(AUXiliary) and
st(Destination).
1) Move the top N – 1 disks from the Source to AUXiliary tower
2) Move the Nth disk from Source to Destination tower
3) Move the N – 1 disks from AUXiliary tower to Destination tower.
Transferring the top N – 1 disks from Source to AUXiliary tower can
again be thought of as a fresh problem and can be solved in the
same manner.
Algorithm
TOWER(N,BEG,AUX,END)
If N=1 then BEG  END RETURN
CALL(N-1,BEG,END,AUX)
BEG  END
CALL(N-1,AUX,BEG,END)
BEG  END
RETURN
*Read Notes of this page
Tower of Hanoi( N= 3)
1. Move from BEG to END
2. Move from BEG to AUX
3. Move from END to AUX
4. Move from BEG to END
5. Move from AUX to BEG
6. Move from AUX to END
7. Move from BEG to END
Tower of Hanoi( N= 4)
1. Move from BEG to AUX
2. Move from BEG to END
3. Move from AUX to END
4. Move from BEG to AUX
5. Move from END to BEG
6. Move from END to AUX
7. Move from BEG to AUX
Tower of Hanoi( N= 4)
8. Move from BEG to END
9. Move from AUX to END
10. Move from AUX to BEG
11. Move from END to BEG
12. Move from AUX to END
13. Move from BEG to AUX
14. Move from BEG to END
15. Move from AUX to END
Presented by
Akshat Saxena
Year – 2nd
Branch = CSE
College – UIT RGPV
Thank You

More Related Content

What's hot

Towers Hanoi Algorithm
Towers Hanoi AlgorithmTowers Hanoi Algorithm
Towers Hanoi AlgorithmJorge Jasso
 
Infix to Postfix Conversion Using Stack
Infix to Postfix Conversion Using StackInfix to Postfix Conversion Using Stack
Infix to Postfix Conversion Using StackSoumen Santra
 
My lectures circular queue
My lectures circular queueMy lectures circular queue
My lectures circular queueSenthil Kumar
 
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority QueueWhat is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority QueueBalwant Gorad
 
linked list in data structure
linked list in data structure linked list in data structure
linked list in data structure shameen khan
 
Graph in data structure
Graph in data structureGraph in data structure
Graph in data structureAbrish06
 
Lecture: Regular Expressions and Regular Languages
Lecture: Regular Expressions and Regular LanguagesLecture: Regular Expressions and Regular Languages
Lecture: Regular Expressions and Regular LanguagesMarina Santini
 
Syntax directed translation
Syntax directed translationSyntax directed translation
Syntax directed translationAkshaya Arunan
 
Multithreading
MultithreadingMultithreading
MultithreadingA B Shinde
 
Priority Queue in Data Structure
Priority Queue in Data StructurePriority Queue in Data Structure
Priority Queue in Data StructureMeghaj Mallick
 
Hashing in datastructure
Hashing in datastructureHashing in datastructure
Hashing in datastructurerajshreemuthiah
 
Dfs presentation
Dfs presentationDfs presentation
Dfs presentationAlizay Khan
 

What's hot (20)

Towers Hanoi Algorithm
Towers Hanoi AlgorithmTowers Hanoi Algorithm
Towers Hanoi Algorithm
 
Chapter 12 ds
Chapter 12 dsChapter 12 ds
Chapter 12 ds
 
Infix to Postfix Conversion Using Stack
Infix to Postfix Conversion Using StackInfix to Postfix Conversion Using Stack
Infix to Postfix Conversion Using Stack
 
My lectures circular queue
My lectures circular queueMy lectures circular queue
My lectures circular queue
 
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority QueueWhat is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
 
linked list in data structure
linked list in data structure linked list in data structure
linked list in data structure
 
Red Black Tree Insertion & Deletion
Red Black Tree Insertion & DeletionRed Black Tree Insertion & Deletion
Red Black Tree Insertion & Deletion
 
Graph in data structure
Graph in data structureGraph in data structure
Graph in data structure
 
Collision in Hashing.pptx
Collision in Hashing.pptxCollision in Hashing.pptx
Collision in Hashing.pptx
 
Complexity of Algorithm
Complexity of AlgorithmComplexity of Algorithm
Complexity of Algorithm
 
Lecture: Regular Expressions and Regular Languages
Lecture: Regular Expressions and Regular LanguagesLecture: Regular Expressions and Regular Languages
Lecture: Regular Expressions and Regular Languages
 
Syntax directed translation
Syntax directed translationSyntax directed translation
Syntax directed translation
 
linked list
linked list linked list
linked list
 
Multithreading
MultithreadingMultithreading
Multithreading
 
Priority Queue in Data Structure
Priority Queue in Data StructurePriority Queue in Data Structure
Priority Queue in Data Structure
 
Linklist
LinklistLinklist
Linklist
 
Linked list
Linked listLinked list
Linked list
 
Hashing in datastructure
Hashing in datastructureHashing in datastructure
Hashing in datastructure
 
Dfs presentation
Dfs presentationDfs presentation
Dfs presentation
 
Graph traversals in Data Structures
Graph traversals in Data StructuresGraph traversals in Data Structures
Graph traversals in Data Structures
 

Viewers also liked

towers of hanoi
towers of hanoitowers of hanoi
towers of hanoistudent
 
Tower of hanoi problem
Tower of hanoi problemTower of hanoi problem
Tower of hanoi problemTyler Murphy
 
Recursion(Advanced data structure)
Recursion(Advanced data structure)Recursion(Advanced data structure)
Recursion(Advanced data structure)kurubameena1
 
Algorithmic puzzles - #83 restricted tower of hanoi
Algorithmic puzzles - #83  restricted tower of hanoiAlgorithmic puzzles - #83  restricted tower of hanoi
Algorithmic puzzles - #83 restricted tower of hanoiNicholas Chen
 
N301 Von Neumann Architecture
N301 Von Neumann ArchitectureN301 Von Neumann Architecture
N301 Von Neumann Architectureguest3b9707
 
Data Structures- Part5 recursion
Data Structures- Part5 recursionData Structures- Part5 recursion
Data Structures- Part5 recursionAbdullah Al-hazmy
 
Von Neumann Architecture
Von Neumann ArchitectureVon Neumann Architecture
Von Neumann ArchitectureJawad Farooqi
 
Computer Generation Presentation
Computer Generation PresentationComputer Generation Presentation
Computer Generation PresentationJayesh Modi
 
Araling Panlipunan Grade 8 - First Quarter Module
Araling Panlipunan Grade 8 - First Quarter ModuleAraling Panlipunan Grade 8 - First Quarter Module
Araling Panlipunan Grade 8 - First Quarter ModuleJhing Pantaleon
 
History Of Computer
History Of ComputerHistory Of Computer
History Of Computerguest420b9d
 
Generations of computer
Generations of computerGenerations of computer
Generations of computerJatin Jindal
 
The five generations of computers presentation
The five generations of computers presentationThe five generations of computers presentation
The five generations of computers presentationSwarnima Tiwari
 

Viewers also liked (17)

towers of hanoi
towers of hanoitowers of hanoi
towers of hanoi
 
Tower of Hanoi
Tower of HanoiTower of Hanoi
Tower of Hanoi
 
Tower of hanoi problem
Tower of hanoi problemTower of hanoi problem
Tower of hanoi problem
 
Tower of hanoi
Tower of hanoiTower of hanoi
Tower of hanoi
 
Recursion(Advanced data structure)
Recursion(Advanced data structure)Recursion(Advanced data structure)
Recursion(Advanced data structure)
 
Algorithmic puzzles - #83 restricted tower of hanoi
Algorithmic puzzles - #83  restricted tower of hanoiAlgorithmic puzzles - #83  restricted tower of hanoi
Algorithmic puzzles - #83 restricted tower of hanoi
 
N301 Von Neumann Architecture
N301 Von Neumann ArchitectureN301 Von Neumann Architecture
N301 Von Neumann Architecture
 
Data Structures- Part5 recursion
Data Structures- Part5 recursionData Structures- Part5 recursion
Data Structures- Part5 recursion
 
Von Neumann Architecture
Von Neumann ArchitectureVon Neumann Architecture
Von Neumann Architecture
 
Recursion
RecursionRecursion
Recursion
 
AP G8/G9 lm q1
AP G8/G9 lm q1AP G8/G9 lm q1
AP G8/G9 lm q1
 
Computer Generation Presentation
Computer Generation PresentationComputer Generation Presentation
Computer Generation Presentation
 
Araling Panlipunan Grade 8 - First Quarter Module
Araling Panlipunan Grade 8 - First Quarter ModuleAraling Panlipunan Grade 8 - First Quarter Module
Araling Panlipunan Grade 8 - First Quarter Module
 
History Of Computer
History Of ComputerHistory Of Computer
History Of Computer
 
Generations of computer
Generations of computerGenerations of computer
Generations of computer
 
The five generations of computers presentation
The five generations of computers presentationThe five generations of computers presentation
The five generations of computers presentation
 
GENERATION OF COMPUTERS.
GENERATION OF COMPUTERS.GENERATION OF COMPUTERS.
GENERATION OF COMPUTERS.
 

Recently uploaded

Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptxPoojaSen20
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 

Recently uploaded (20)

Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
PSYCHIATRIC History collection FORMAT.pptx
PSYCHIATRIC   History collection FORMAT.pptxPSYCHIATRIC   History collection FORMAT.pptx
PSYCHIATRIC History collection FORMAT.pptx
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 

Tower of hanoi

Editor's Notes

  1. In recursive form of algorithm, consider n disks are grouped in two groups. One is single and other is a group of remaining n-1 disks. Now instead of n disks it becomes a problem of 2 disks. The 2 two disks can be transferred in two steps. Taking 1st disk from Beg to End. And 2nd disk in two steps. From Beg to Auxiliary and then auxiliary to End. This method continues till value of n decreases to 2, which is simple base case.