SlideShare a Scribd company logo
1 of 11
Tower Of Hanoi
-A Mathematical Puzzle
RMD SINHGAD COLLEGE OF COMPUTER
STUDIES,WARJE ,PUNE-58
Guide:
Balachandra Doddi
Submitted By:
Purva Nahar(2176)
Submitted To:
Department Of Computer Studies ,
RMD Sinhgad College of Computer
Studies
Historical Note
• The Tower of Hanoi was invented by the French mathematician Edouard Lucas and
sold as a toy in 1883. It originally bore the name of ”Prof.Claus” of the college of “Li-
Sou-Stain”, but these were soon discovered to be anagrams for “Prof.Lucas” of the
college of “Saint Loius”, the university where he worked in Paris.
• There is a history about an Indian temple in Kashi Vishwanath which contains a large
room with three time-worn posts in it surrounded by 64 golden disks. Brahmin priests,
acting out the command of an ancient prophecy, have been moving these disks, in
accordance with the immutable rules of the Brahma, since that time. According to
the legend, when the last move of the puzzle will be completed, the world will end.
Objective
• The aim of the tower of Hanoi problem is to move the initial n different sized
disks from Tower A to Tower C using a temporary Tower B. The rule is that no
larger disk is to be placed above the smaller disk in any of the needle while
moving or at any time, and only the top of the disk is to be moved at a time
from any Tower to any Tower.
Rules of Puzzle
• The Tower of Hanoi is a mathematical game or puzzle. It consists of three rods, and
a number of disks of different sizes which can slide onto any rod. The puzzle starts
with the disks in a neat stack in ascending order of size on one rod, the smallest at
the top, thus making a conical shape. The objective of the puzzle is to move the
entire stack to another rod, obeying the following rules:
• 1) Only one disk must be moved at a time.
• 2) Each move consists of taking the upper disk from one of the rods and sliding it
onto another rod, on top of the other disks that may already be present on that rod.
• 3) No disk may be placed on top of a smaller disk.
Algorithm
Recursive Solution for the Tower of Hanoi with algorithm
Let’s call the three peg Src(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. So once you master
solving Tower of Hanoi with three disks, you can solve it with
any number of disks with the above algorithm.
Time Complexity of Algorithm
• Let the time required for n disks is T(n) .
• There are 2 recursive call for n-1 disks and one constant time operation to move a disk
from ‘from’ peg to ‘to’ peg . Let it be k1.
• Therefore,
• T(n) = 2 T(n-1) + k1
• T(0) = k2 , a constant.
• T(1) = 2 k2 + k1
• T(2) = 4 k2 + 2k1 + k1
• T(2) = 8 k2 + 4k1 + 2k1 + k1
• Coefficient of k1 =2n
• Coefficient of k2 =2n-1
• Time complexity is O(2n) or O(an) where a is a constant greater than 1.
• So it has exponential time complexity. For single increase in problem size the time
required is double the previous one. This is computationally very expensive. Most of the
recursive programs takes exponential time that is why it is very hard to write them
iteratively .
Space Complexity of Algorithm
• Space for parameter for each call is independent of n i.e., constant. Let it be k .
• When we do the 2nd recursive call 1st recursive call is over . So, we can reuse the
space of 1st call for 2nd call . Hence ,
• T(n) = T(n-1) + k
• T(0) = k
• T(1) = 2k
• T(2) = 3k
• T(3) = 4k
• So the space complexity is O(n).
• Here time complexity is exponential but space complexity is linear . Often there is a
trade off between time and space complexity .
Table:
Showing Number of Disk
and Disk Moves.
Number of Disks Number of Moves
0 INVALID
1 INVALID
2 3
3 7
4 15
5 31
6 63
7 127
8 255
9 511
Applications
• The Tower of Hanoi is frequently used in psychological research
on problem solving. There also exists a variant of this task called Tower of
London for neuropsychological diagnosis and treatment of executive
functions.
• The Tower of Hanoi is also used as a Backup rotation scheme when
performing computer data Backups where multiple tapes/media are
involved.
• As mentioned above, the Tower of Hanoi is popular for teaching recursive
algorithms to beginning programming students. A pictorial version of this
puzzle is programmed into the emacs editor, accessed by typing M-x hanoi.
There is also a sample algorithm written in Prolog.
• The Tower of Hanoi is also used as a test by neuropsychologists trying to
evaluate frontal lobe deficits.

More Related Content

What's hot

Data Structures - Lecture 9 [Stack & Queue using Linked List]
 Data Structures - Lecture 9 [Stack & Queue using Linked List] Data Structures - Lecture 9 [Stack & Queue using Linked List]
Data Structures - Lecture 9 [Stack & Queue using Linked List]Muhammad Hammad Waseem
 
Array operations
Array operationsArray operations
Array operationsZAFAR444
 
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 analysisShubham Nimiwal
 
heap Sort Algorithm
heap  Sort Algorithmheap  Sort Algorithm
heap Sort AlgorithmLemia Algmri
 
Stacks in DATA STRUCTURE
Stacks in DATA STRUCTUREStacks in DATA STRUCTURE
Stacks in DATA STRUCTUREMandeep Singh
 
Applications of stack
Applications of stackApplications of stack
Applications of stackeShikshak
 
BINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.pptBINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.pptSeethaDinesh
 
3.9 external sorting
3.9 external sorting3.9 external sorting
3.9 external sortingKrish_ver2
 
daa-unit-3-greedy method
daa-unit-3-greedy methoddaa-unit-3-greedy method
daa-unit-3-greedy methodhodcsencet
 
Informed and Uninformed search Strategies
Informed and Uninformed search StrategiesInformed and Uninformed search Strategies
Informed and Uninformed search StrategiesAmey Kerkar
 
Heap Sort in Design and Analysis of algorithms
Heap Sort in Design and Analysis of algorithmsHeap Sort in Design and Analysis of algorithms
Heap Sort in Design and Analysis of algorithmssamairaakram
 

What's hot (20)

Data Structures - Lecture 9 [Stack & Queue using Linked List]
 Data Structures - Lecture 9 [Stack & Queue using Linked List] Data Structures - Lecture 9 [Stack & Queue using Linked List]
Data Structures - Lecture 9 [Stack & Queue using Linked List]
 
Array operations
Array operationsArray operations
Array operations
 
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
 
Heaps
HeapsHeaps
Heaps
 
Heaps
HeapsHeaps
Heaps
 
heap Sort Algorithm
heap  Sort Algorithmheap  Sort Algorithm
heap Sort Algorithm
 
Heap
HeapHeap
Heap
 
Tower of hanoi
Tower of hanoiTower of hanoi
Tower of hanoi
 
Stacks in DATA STRUCTURE
Stacks in DATA STRUCTUREStacks in DATA STRUCTURE
Stacks in DATA STRUCTURE
 
Heap and heapsort
Heap and heapsortHeap and heapsort
Heap and heapsort
 
Applications of stack
Applications of stackApplications of stack
Applications of stack
 
BINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.pptBINARY TREE REPRESENTATION.ppt
BINARY TREE REPRESENTATION.ppt
 
3.9 external sorting
3.9 external sorting3.9 external sorting
3.9 external sorting
 
Binary search tree(bst)
Binary search tree(bst)Binary search tree(bst)
Binary search tree(bst)
 
daa-unit-3-greedy method
daa-unit-3-greedy methoddaa-unit-3-greedy method
daa-unit-3-greedy method
 
Stack
StackStack
Stack
 
Informed and Uninformed search Strategies
Informed and Uninformed search StrategiesInformed and Uninformed search Strategies
Informed and Uninformed search Strategies
 
Stacks
StacksStacks
Stacks
 
Heap Sort in Design and Analysis of algorithms
Heap Sort in Design and Analysis of algorithmsHeap Sort in Design and Analysis of algorithms
Heap Sort in Design and Analysis of algorithms
 
Data Structure (Queue)
Data Structure (Queue)Data Structure (Queue)
Data Structure (Queue)
 

Similar to Tower Of Hanoi -A MatheMatical PuZzle

Tower of Hanoi presentation
Tower of Hanoi presentationTower of Hanoi presentation
Tower of Hanoi presentationFahadQaiser1
 
Tower of hanoi algorithm
Tower of hanoi algorithmTower of hanoi algorithm
Tower of hanoi algorithmWeaamRaed
 
Zvi random-walks-slideshare
Zvi random-walks-slideshareZvi random-walks-slideshare
Zvi random-walks-slideshareZvi Lotker
 
ICPC 2015, Tsukuba : Unofficial Commentary
ICPC 2015, Tsukuba: Unofficial CommentaryICPC 2015, Tsukuba: Unofficial Commentary
ICPC 2015, Tsukuba : Unofficial Commentaryirrrrr
 
Collection of mathematics university of correction
Collection of mathematics university of correctionCollection of mathematics university of correction
Collection of mathematics university of correctionUD. Berkah Jaya Komputer
 
Recurrent Problem in Discrete Mathmatics.pptx
Recurrent Problem in Discrete Mathmatics.pptxRecurrent Problem in Discrete Mathmatics.pptx
Recurrent Problem in Discrete Mathmatics.pptxgbikorno
 
module5_backtrackingnbranchnbound_2022.pdf
module5_backtrackingnbranchnbound_2022.pdfmodule5_backtrackingnbranchnbound_2022.pdf
module5_backtrackingnbranchnbound_2022.pdfShiwani Gupta
 
Tower of Hanoi Investigation
Tower of Hanoi InvestigationTower of Hanoi Investigation
Tower of Hanoi InvestigationWriters Per Hour
 
Dc8c4f010f40.hanoi.towers
Dc8c4f010f40.hanoi.towersDc8c4f010f40.hanoi.towers
Dc8c4f010f40.hanoi.towersSumedha
 
ProblemspowerWrite a public static function named power.docx
ProblemspowerWrite a public static function named power.docxProblemspowerWrite a public static function named power.docx
ProblemspowerWrite a public static function named power.docxleahlegrand
 
On the Convex Layers of a Planer Dynamic Set of Points
On the Convex Layers of a Planer Dynamic Set of PointsOn the Convex Layers of a Planer Dynamic Set of Points
On the Convex Layers of a Planer Dynamic Set of PointsKasun Ranga Wijeweera
 
The n Queen Problem
The n Queen ProblemThe n Queen Problem
The n Queen ProblemSukrit Gupta
 
Analysis and Enhancement of Algorithms in Computational Geometry
Analysis and Enhancement of Algorithms in Computational GeometryAnalysis and Enhancement of Algorithms in Computational Geometry
Analysis and Enhancement of Algorithms in Computational GeometryKasun Ranga Wijeweera
 
Sorting Algorithm
Sorting AlgorithmSorting Algorithm
Sorting AlgorithmAl Amin
 
Searching Informed Search.pdf
Searching Informed Search.pdfSearching Informed Search.pdf
Searching Informed Search.pdfDrBashirMSaad
 
Accurate, Simple and Efficient Triangulation of a Polygon by Ear Removal with...
Accurate, Simple and Efficient Triangulation of a Polygon by Ear Removal with...Accurate, Simple and Efficient Triangulation of a Polygon by Ear Removal with...
Accurate, Simple and Efficient Triangulation of a Polygon by Ear Removal with...Kasun Ranga Wijeweera
 

Similar to Tower Of Hanoi -A MatheMatical PuZzle (20)

Tower of Hanoi presentation
Tower of Hanoi presentationTower of Hanoi presentation
Tower of Hanoi presentation
 
Tower of hanoi
Tower of hanoiTower of hanoi
Tower of hanoi
 
Rand final
Rand finalRand final
Rand final
 
Tower of hanoi algorithm
Tower of hanoi algorithmTower of hanoi algorithm
Tower of hanoi algorithm
 
Zvi random-walks-slideshare
Zvi random-walks-slideshareZvi random-walks-slideshare
Zvi random-walks-slideshare
 
Tower of Hanoi
Tower of HanoiTower of Hanoi
Tower of Hanoi
 
ICPC 2015, Tsukuba : Unofficial Commentary
ICPC 2015, Tsukuba: Unofficial CommentaryICPC 2015, Tsukuba: Unofficial Commentary
ICPC 2015, Tsukuba : Unofficial Commentary
 
Collection of mathematics university of correction
Collection of mathematics university of correctionCollection of mathematics university of correction
Collection of mathematics university of correction
 
Data structure lab
Data structure labData structure lab
Data structure lab
 
Recurrent Problem in Discrete Mathmatics.pptx
Recurrent Problem in Discrete Mathmatics.pptxRecurrent Problem in Discrete Mathmatics.pptx
Recurrent Problem in Discrete Mathmatics.pptx
 
module5_backtrackingnbranchnbound_2022.pdf
module5_backtrackingnbranchnbound_2022.pdfmodule5_backtrackingnbranchnbound_2022.pdf
module5_backtrackingnbranchnbound_2022.pdf
 
Tower of Hanoi Investigation
Tower of Hanoi InvestigationTower of Hanoi Investigation
Tower of Hanoi Investigation
 
Dc8c4f010f40.hanoi.towers
Dc8c4f010f40.hanoi.towersDc8c4f010f40.hanoi.towers
Dc8c4f010f40.hanoi.towers
 
ProblemspowerWrite a public static function named power.docx
ProblemspowerWrite a public static function named power.docxProblemspowerWrite a public static function named power.docx
ProblemspowerWrite a public static function named power.docx
 
On the Convex Layers of a Planer Dynamic Set of Points
On the Convex Layers of a Planer Dynamic Set of PointsOn the Convex Layers of a Planer Dynamic Set of Points
On the Convex Layers of a Planer Dynamic Set of Points
 
The n Queen Problem
The n Queen ProblemThe n Queen Problem
The n Queen Problem
 
Analysis and Enhancement of Algorithms in Computational Geometry
Analysis and Enhancement of Algorithms in Computational GeometryAnalysis and Enhancement of Algorithms in Computational Geometry
Analysis and Enhancement of Algorithms in Computational Geometry
 
Sorting Algorithm
Sorting AlgorithmSorting Algorithm
Sorting Algorithm
 
Searching Informed Search.pdf
Searching Informed Search.pdfSearching Informed Search.pdf
Searching Informed Search.pdf
 
Accurate, Simple and Efficient Triangulation of a Polygon by Ear Removal with...
Accurate, Simple and Efficient Triangulation of a Polygon by Ear Removal with...Accurate, Simple and Efficient Triangulation of a Polygon by Ear Removal with...
Accurate, Simple and Efficient Triangulation of a Polygon by Ear Removal with...
 

Recently uploaded

Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
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
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
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
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...anjaliyadav012327
 
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
 
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
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 

Recently uploaded (20)

Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
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
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
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
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
 
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...
 
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
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 

Tower Of Hanoi -A MatheMatical PuZzle

  • 1. Tower Of Hanoi -A Mathematical Puzzle
  • 2. RMD SINHGAD COLLEGE OF COMPUTER STUDIES,WARJE ,PUNE-58 Guide: Balachandra Doddi Submitted By: Purva Nahar(2176) Submitted To: Department Of Computer Studies , RMD Sinhgad College of Computer Studies
  • 3. Historical Note • The Tower of Hanoi was invented by the French mathematician Edouard Lucas and sold as a toy in 1883. It originally bore the name of ”Prof.Claus” of the college of “Li- Sou-Stain”, but these were soon discovered to be anagrams for “Prof.Lucas” of the college of “Saint Loius”, the university where he worked in Paris. • There is a history about an Indian temple in Kashi Vishwanath which contains a large room with three time-worn posts in it surrounded by 64 golden disks. Brahmin priests, acting out the command of an ancient prophecy, have been moving these disks, in accordance with the immutable rules of the Brahma, since that time. According to the legend, when the last move of the puzzle will be completed, the world will end.
  • 4. Objective • The aim of the tower of Hanoi problem is to move the initial n different sized disks from Tower A to Tower C using a temporary Tower B. The rule is that no larger disk is to be placed above the smaller disk in any of the needle while moving or at any time, and only the top of the disk is to be moved at a time from any Tower to any Tower.
  • 5. Rules of Puzzle • The Tower of Hanoi is a mathematical game or puzzle. It consists of three rods, and a number of disks of different sizes which can slide onto any rod. The puzzle starts with the disks in a neat stack in ascending order of size on one rod, the smallest at the top, thus making a conical shape. The objective of the puzzle is to move the entire stack to another rod, obeying the following rules: • 1) Only one disk must be moved at a time. • 2) Each move consists of taking the upper disk from one of the rods and sliding it onto another rod, on top of the other disks that may already be present on that rod. • 3) No disk may be placed on top of a smaller disk.
  • 6. Algorithm Recursive Solution for the Tower of Hanoi with algorithm Let’s call the three peg Src(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. So once you master solving Tower of Hanoi with three disks, you can solve it with any number of disks with the above algorithm.
  • 7. Time Complexity of Algorithm • Let the time required for n disks is T(n) . • There are 2 recursive call for n-1 disks and one constant time operation to move a disk from ‘from’ peg to ‘to’ peg . Let it be k1. • Therefore, • T(n) = 2 T(n-1) + k1 • T(0) = k2 , a constant. • T(1) = 2 k2 + k1 • T(2) = 4 k2 + 2k1 + k1 • T(2) = 8 k2 + 4k1 + 2k1 + k1 • Coefficient of k1 =2n • Coefficient of k2 =2n-1 • Time complexity is O(2n) or O(an) where a is a constant greater than 1. • So it has exponential time complexity. For single increase in problem size the time required is double the previous one. This is computationally very expensive. Most of the recursive programs takes exponential time that is why it is very hard to write them iteratively .
  • 8. Space Complexity of Algorithm • Space for parameter for each call is independent of n i.e., constant. Let it be k . • When we do the 2nd recursive call 1st recursive call is over . So, we can reuse the space of 1st call for 2nd call . Hence , • T(n) = T(n-1) + k • T(0) = k • T(1) = 2k • T(2) = 3k • T(3) = 4k • So the space complexity is O(n). • Here time complexity is exponential but space complexity is linear . Often there is a trade off between time and space complexity .
  • 9.
  • 10. Table: Showing Number of Disk and Disk Moves. Number of Disks Number of Moves 0 INVALID 1 INVALID 2 3 3 7 4 15 5 31 6 63 7 127 8 255 9 511
  • 11. Applications • The Tower of Hanoi is frequently used in psychological research on problem solving. There also exists a variant of this task called Tower of London for neuropsychological diagnosis and treatment of executive functions. • The Tower of Hanoi is also used as a Backup rotation scheme when performing computer data Backups where multiple tapes/media are involved. • As mentioned above, the Tower of Hanoi is popular for teaching recursive algorithms to beginning programming students. A pictorial version of this puzzle is programmed into the emacs editor, accessed by typing M-x hanoi. There is also a sample algorithm written in Prolog. • The Tower of Hanoi is also used as a test by neuropsychologists trying to evaluate frontal lobe deficits.