SlideShare a Scribd company logo
1 of 11
Topic
TOWER OF HANOI
Presentation of
Discrete Maths
SUBMITTED BY
FAHAD QAISER
Submitted to
SIR. RAZA UL HAQ
Introduction
 The tower of Hanoi (also called the tower of Brahma
or the Lucas tower) is a mathematical game or a
puzzle.
 invented by the French mathematician Edouard
Lucas and sold as a toy in 1883.
 It consists of three rods and a numbers of disks of
different sizes which can slide onto any rod.
History
 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.
 The number of moves required to correctly move a tower
of 64 disks is 264 _1=18,446,744,073,709,551,615.
 At rate of one move per second, that is 584,942,417,335
years.
Objective and Procedure
 The objective of this game is to move the disks one
by one from first peg(rod) to last peg(rod).
 The number of disks can vary, but there are only three
rods.
 The game starts by having few disks stacked in increasing
order of size.
 Start the game with your two smallest disks. Stack them
on the rod B and C, with the smaller disk on top of the
larger disk.
Rules
1. Only one disk can be move at a time.
2. Each move consists of taking the upper disk
from one of the stacks and placing it on top
of another stack i.e a disk can only be moved
if it is the uppermost disk on a stack.
3. No disk may be placed on top of a smaller
disk.
Example
Algorithm
 Algorithm Recursive Solution for the Tower of Hanoi with algorithm.
1. Let’s call the three peg Src(Source), Aux(Auxiliary) and
st(Destination).
2. Move the top N – 1 disks from the Source to Auxiliary tower.
3. Move the Nth disk from Source to Destination tower.
4. 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.
solution
 Tower(N, Beg, AUX, END)
1. If N=1 then BEGEnd.
2. [Move N-1 disks from rod BEG to rod AUX]
3. Call Tower(N-1, BEG, END, AUX)
4. Write BEGEND
5. [Move N-1 disks from rod AUX to rod END]
6. Call Tower(N-1, AUX, BEG, END)
7. Return
Time Complexity
 T(n)=2T(n-1)+c
 T(0)=0
 T(n)=2{2T(n-2)+c}+c T(n-1)=2T(n-2)+c
 T(n)= 4T(n-2)+2c+c
 T(n)= 4{2T(n-3)+c}+2c+c T(n-2)=2T(n-3)+c
 T(n)= 8T(n-3)+4c+2c+c
 T(n)= 8{2T(n-4)+c}+4c+2c+c T(n-3)=2T(n-4)+c
 T(n)= 16T(n-4)+8c+4c+2c+c
 T(n)=2k T(n-k)+2k -1 if n-k=0, k=n
 T(n)=2N T(0)+2N -1
 T(n)=2N = 1
Recursive Equation :

More Related Content

Similar to Tower of Hanoi presentation

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
 
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
 
Tower of Hanoi Investigation
Tower of Hanoi InvestigationTower of Hanoi Investigation
Tower of Hanoi InvestigationWriters Per Hour
 
The Towers of Hanoi puzzle has three posts and some number n of disk.pdf
The Towers of Hanoi puzzle has three posts and some number n of disk.pdfThe Towers of Hanoi puzzle has three posts and some number n of disk.pdf
The Towers of Hanoi puzzle has three posts and some number n of disk.pdffcsondhiindia
 
Tower of hanoi
Tower of hanoiTower of hanoi
Tower of hanoiUsr11011
 
Dc8c4f010f40.hanoi.towers
Dc8c4f010f40.hanoi.towersDc8c4f010f40.hanoi.towers
Dc8c4f010f40.hanoi.towersSumedha
 
Stack - Data structures - Dr. Shaukat Wasi
Stack - Data structures - Dr. Shaukat WasiStack - Data structures - Dr. Shaukat Wasi
Stack - Data structures - Dr. Shaukat WasiDr. Shaukat Wasi
 
May 7, 2015
May 7, 2015May 7, 2015
May 7, 2015khyps13
 

Similar to Tower of Hanoi presentation (15)

Tower Of Hanoi
Tower Of HanoiTower Of Hanoi
Tower Of Hanoi
 
Collection of mathematics university of correction
Collection of mathematics university of correctionCollection of mathematics university of correction
Collection of mathematics university of correction
 
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
 
Tower of Hanoi Investigation
Tower of Hanoi InvestigationTower of Hanoi Investigation
Tower of Hanoi Investigation
 
Tower of hanoi
Tower of hanoiTower of hanoi
Tower of hanoi
 
The Towers of Hanoi puzzle has three posts and some number n of disk.pdf
The Towers of Hanoi puzzle has three posts and some number n of disk.pdfThe Towers of Hanoi puzzle has three posts and some number n of disk.pdf
The Towers of Hanoi puzzle has three posts and some number n of disk.pdf
 
Rand final
Rand finalRand final
Rand final
 
Tower of Hanoi
Tower of HanoiTower of Hanoi
Tower of Hanoi
 
Tower of hanoi
Tower of hanoiTower of hanoi
Tower of hanoi
 
Dc8c4f010f40.hanoi.towers
Dc8c4f010f40.hanoi.towersDc8c4f010f40.hanoi.towers
Dc8c4f010f40.hanoi.towers
 
N queen problem
N queen problemN queen problem
N queen problem
 
Data structure
Data structureData structure
Data structure
 
Stack - Data structures - Dr. Shaukat Wasi
Stack - Data structures - Dr. Shaukat WasiStack - Data structures - Dr. Shaukat Wasi
Stack - Data structures - Dr. Shaukat Wasi
 
May 7, 2015
May 7, 2015May 7, 2015
May 7, 2015
 
Tower of hanoi
Tower of hanoiTower of hanoi
Tower of hanoi
 

Recently uploaded

Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...amitlee9823
 
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...amitlee9823
 
BPAC WITH UFSBI GENERAL PRESENTATION 18_05_2017-1.pptx
BPAC WITH UFSBI GENERAL PRESENTATION 18_05_2017-1.pptxBPAC WITH UFSBI GENERAL PRESENTATION 18_05_2017-1.pptx
BPAC WITH UFSBI GENERAL PRESENTATION 18_05_2017-1.pptxMohammedJunaid861692
 
Generative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and MilvusGenerative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and MilvusTimothy Spann
 
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...amitlee9823
 
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...amitlee9823
 
Schema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdfSchema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdfLars Albertsson
 
Carero dropshipping via API with DroFx.pptx
Carero dropshipping via API with DroFx.pptxCarero dropshipping via API with DroFx.pptx
Carero dropshipping via API with DroFx.pptxolyaivanovalion
 
Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% SecureCall me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% SecurePooja Nehwal
 
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...SUHANI PANDEY
 
Edukaciniai dropshipping via API with DroFx
Edukaciniai dropshipping via API with DroFxEdukaciniai dropshipping via API with DroFx
Edukaciniai dropshipping via API with DroFxolyaivanovalion
 
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 nightCheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 nightDelhi Call girls
 
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Callshivangimorya083
 
100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptxAnupama Kate
 
Vip Model Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...
Vip Model  Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...Vip Model  Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...
Vip Model Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...shivangimorya083
 
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Callshivangimorya083
 
Zuja dropshipping via API with DroFx.pptx
Zuja dropshipping via API with DroFx.pptxZuja dropshipping via API with DroFx.pptx
Zuja dropshipping via API with DroFx.pptxolyaivanovalion
 

Recently uploaded (20)

Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
 
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
 
BPAC WITH UFSBI GENERAL PRESENTATION 18_05_2017-1.pptx
BPAC WITH UFSBI GENERAL PRESENTATION 18_05_2017-1.pptxBPAC WITH UFSBI GENERAL PRESENTATION 18_05_2017-1.pptx
BPAC WITH UFSBI GENERAL PRESENTATION 18_05_2017-1.pptx
 
Generative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and MilvusGenerative AI on Enterprise Cloud with NiFi and Milvus
Generative AI on Enterprise Cloud with NiFi and Milvus
 
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
 
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
 
Schema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdfSchema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdf
 
Carero dropshipping via API with DroFx.pptx
Carero dropshipping via API with DroFx.pptxCarero dropshipping via API with DroFx.pptx
Carero dropshipping via API with DroFx.pptx
 
Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% SecureCall me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
 
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
 
Edukaciniai dropshipping via API with DroFx
Edukaciniai dropshipping via API with DroFxEdukaciniai dropshipping via API with DroFx
Edukaciniai dropshipping via API with DroFx
 
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 nightCheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
 
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts ServiceCall Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
Call Girls In Shalimar Bagh ( Delhi) 9953330565 Escorts Service
 
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
 
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get CytotecAbortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
 
Sampling (random) method and Non random.ppt
Sampling (random) method and Non random.pptSampling (random) method and Non random.ppt
Sampling (random) method and Non random.ppt
 
100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx
 
Vip Model Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...
Vip Model  Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...Vip Model  Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...
Vip Model Call Girls (Delhi) Karol Bagh 9711199171✔️Body to body massage wit...
 
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
 
Zuja dropshipping via API with DroFx.pptx
Zuja dropshipping via API with DroFx.pptxZuja dropshipping via API with DroFx.pptx
Zuja dropshipping via API with DroFx.pptx
 

Tower of Hanoi presentation

  • 4. Introduction  The tower of Hanoi (also called the tower of Brahma or the Lucas tower) is a mathematical game or a puzzle.  invented by the French mathematician Edouard Lucas and sold as a toy in 1883.  It consists of three rods and a numbers of disks of different sizes which can slide onto any rod.
  • 5. History  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.  The number of moves required to correctly move a tower of 64 disks is 264 _1=18,446,744,073,709,551,615.  At rate of one move per second, that is 584,942,417,335 years.
  • 6. Objective and Procedure  The objective of this game is to move the disks one by one from first peg(rod) to last peg(rod).  The number of disks can vary, but there are only three rods.  The game starts by having few disks stacked in increasing order of size.  Start the game with your two smallest disks. Stack them on the rod B and C, with the smaller disk on top of the larger disk.
  • 7. Rules 1. Only one disk can be move at a time. 2. Each move consists of taking the upper disk from one of the stacks and placing it on top of another stack i.e a disk can only be moved if it is the uppermost disk on a stack. 3. No disk may be placed on top of a smaller disk.
  • 9. Algorithm  Algorithm Recursive Solution for the Tower of Hanoi with algorithm. 1. Let’s call the three peg Src(Source), Aux(Auxiliary) and st(Destination). 2. Move the top N – 1 disks from the Source to Auxiliary tower. 3. Move the Nth disk from Source to Destination tower. 4. 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.
  • 10. solution  Tower(N, Beg, AUX, END) 1. If N=1 then BEGEnd. 2. [Move N-1 disks from rod BEG to rod AUX] 3. Call Tower(N-1, BEG, END, AUX) 4. Write BEGEND 5. [Move N-1 disks from rod AUX to rod END] 6. Call Tower(N-1, AUX, BEG, END) 7. Return
  • 11. Time Complexity  T(n)=2T(n-1)+c  T(0)=0  T(n)=2{2T(n-2)+c}+c T(n-1)=2T(n-2)+c  T(n)= 4T(n-2)+2c+c  T(n)= 4{2T(n-3)+c}+2c+c T(n-2)=2T(n-3)+c  T(n)= 8T(n-3)+4c+2c+c  T(n)= 8{2T(n-4)+c}+4c+2c+c T(n-3)=2T(n-4)+c  T(n)= 16T(n-4)+8c+4c+2c+c  T(n)=2k T(n-k)+2k -1 if n-k=0, k=n  T(n)=2N T(0)+2N -1  T(n)=2N = 1 Recursive Equation :