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

Binary trees
Binary treesBinary trees
Binary trees
Amit Vats
 
Algorithm analysis
Algorithm analysisAlgorithm analysis
Algorithm analysis
sumitbardhan
 

What's hot (20)

DFS and BFS
DFS and BFSDFS and BFS
DFS and BFS
 
8 queen problem
8 queen problem8 queen problem
8 queen problem
 
Towers Hanoi Algorithm
Towers Hanoi AlgorithmTowers Hanoi Algorithm
Towers Hanoi Algorithm
 
Binary trees
Binary treesBinary trees
Binary trees
 
Heap sort
Heap sort Heap sort
Heap sort
 
Lecture 16 memory bounded search
Lecture 16 memory bounded searchLecture 16 memory bounded search
Lecture 16 memory bounded search
 
Binary search tree(bst)
Binary search tree(bst)Binary search tree(bst)
Binary search tree(bst)
 
Breadth First Search & Depth First Search
Breadth First Search & Depth First SearchBreadth First Search & Depth First Search
Breadth First Search & Depth First Search
 
Hash table in data structure and algorithm
Hash table in data structure and algorithmHash table in data structure and algorithm
Hash table in data structure and algorithm
 
Graph traversal-BFS & DFS
Graph traversal-BFS & DFSGraph traversal-BFS & DFS
Graph traversal-BFS & DFS
 
Graph in data structure
Graph in data structureGraph in data structure
Graph in data structure
 
Bfs and Dfs
Bfs and DfsBfs and Dfs
Bfs and Dfs
 
Tower of hanoi
Tower of hanoiTower of hanoi
Tower of hanoi
 
Merge Sort
Merge SortMerge Sort
Merge Sort
 
A Star Search
A Star SearchA Star Search
A Star Search
 
Algorithm analysis
Algorithm analysisAlgorithm analysis
Algorithm analysis
 
Queue - Data Structure - Notes
Queue - Data Structure - NotesQueue - Data Structure - Notes
Queue - Data Structure - Notes
 
Quick sort
Quick sortQuick sort
Quick sort
 
Expression trees
Expression treesExpression trees
Expression trees
 
Depth-First Search
Depth-First SearchDepth-First Search
Depth-First Search
 

Viewers also liked

towers of hanoi
towers of hanoitowers of hanoi
towers of hanoi
student
 
Tower of Hanoi using AI technique - means ends analysis
Tower of Hanoi using AI technique - means ends analysisTower of Hanoi using AI technique - means ends analysis
Tower of Hanoi using AI technique - means ends analysis
Shubham Nimiwal
 
N301 Von Neumann Architecture
N301 Von Neumann ArchitectureN301 Von Neumann Architecture
N301 Von Neumann Architecture
guest3b9707
 
Computer Generation Presentation
Computer Generation PresentationComputer Generation Presentation
Computer Generation Presentation
Jayesh Modi
 
History Of Computer
History Of ComputerHistory Of Computer
History Of Computer
guest420b9d
 
The five generations of computers presentation
The five generations of computers presentationThe five generations of computers presentation
The five generations of computers presentation
Swarnima 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 using AI technique - means ends analysis
Tower of Hanoi using AI technique - means ends analysisTower of Hanoi using AI technique - means ends analysis
Tower of Hanoi using AI technique - means ends analysis
 
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

Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 

Recently uploaded (20)

ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 

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.