SlideShare a Scribd company logo
1 of 6
Download to read offline
Generating the Closed Formula for the Tower of Hanoi 
Problem Using Matrix Algebra 
Tyler Murphy 
September 30, 2014 
1 Background 
The Tower of Hanoi (also called the Tower of Brahma or Lucas' Tower, and sometimes 
pluralized) is a mathematical game or puzzle. It consists of three rods, and a number of 
disks of dierent 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. 
Figure 1: Tower of Hanoi Game 
The objective of the puzzle is to move the entire stack to another rod, obeying the 
following simple rules: 
 Only one disk can be moved at a time. 
 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. 
 No disk may be placed on top of a smaller disk. 
We are interested in
nding the smallest number of moves it takes to move a tower 
with n discs to another location. First, we generate a table of experimentation values 
1
Number of Discs (n) Minimum Number of Moves (Mn) 
1 1 
2 3 
3 7 
4 15 
5 31 
6 63 
We see that after this point, experimentation begins to take a long time, so we stop 
here and try to devise a pattern. 
2 Recurrence Form 
We notice that each value for Mn is twice the value of Mn1 plus 1. So we need to know 
the value for Mn1, which we can see would be dicult to generate for any large n. So 
calculating the value for Mn becomes no small task when we use the recurrence formula to
nd it. We need a simpler way. 
It turns out that if can design a matrix that models this recurrence relation, we will be 
able to use this matrix to generate a closed formula to
nd Mn without having to know 
Mn1. 
3 Designing the Matrix 
Recall that a matrix is simply another way to write a system of equations. 
For example, the equations 
2x + 3y = 4 (1) 
and 
x + y = 1: (2) 
These can be written in matrix multiplication form as: 
 
2 3 
1 1 
  
x 
y 
 
= 
 
4 
1 
 
So we can write our recursive formula in this manner. 
We will eventually end up with something of the form 
Anb = c 
Where A is our matrix, b is our initial value vector and c is our solution vector. 
2
Because of the constant term in the recursion relation and because Mn+1 only depends 
on Mn but not Mn1 (like the Fibonnaci sequence), we will use vectors of the form 
 
Mn 
1 
 
We also know our matrix will be a 2x2 matrix because we only have two terms in our 
recurrence formula. So: 
A = 
 
a11 a12 
a21 a22 
 
We want a matrix A such that 
 
Mn+1 
1 
 
= A 
 
Mn 
1 
 
The equations represented by this are: 
Mn+1 = a11Mn + a12 
and 
1 = a21Mn + a22: 
To make the

More Related Content

What's hot

3.1 solving systems graphically
3.1 solving systems graphically3.1 solving systems graphically
3.1 solving systems graphicallyfthrower
 
Systems Non Linear Equations
Systems Non Linear EquationsSystems Non Linear Equations
Systems Non Linear EquationsBitsy Griffin
 
Gaussian elimination method & homogeneous linear equation
Gaussian elimination method & homogeneous linear equationGaussian elimination method & homogeneous linear equation
Gaussian elimination method & homogeneous linear equationStudent
 
Math lecture 7 (Arithmetic Sequence)
Math lecture 7 (Arithmetic Sequence)Math lecture 7 (Arithmetic Sequence)
Math lecture 7 (Arithmetic Sequence)Osama Zahid
 
Gaussian Elimination
Gaussian EliminationGaussian Elimination
Gaussian EliminationZunAib Ali
 
April 16, 2014
April 16, 2014April 16, 2014
April 16, 2014khyps13
 
System of linear equations
System of linear equationsSystem of linear equations
System of linear equationsDiler4
 
System of linear equations and their solution
System of linear equations and their solutionSystem of linear equations and their solution
System of linear equations and their solutionJoseph Nilo
 
Solving systems of Linear Equations
Solving systems of Linear EquationsSolving systems of Linear Equations
Solving systems of Linear Equationsswartzje
 

What's hot (19)

3.1 solving systems graphically
3.1 solving systems graphically3.1 solving systems graphically
3.1 solving systems graphically
 
Systems Non Linear Equations
Systems Non Linear EquationsSystems Non Linear Equations
Systems Non Linear Equations
 
Gaussian elimination method & homogeneous linear equation
Gaussian elimination method & homogeneous linear equationGaussian elimination method & homogeneous linear equation
Gaussian elimination method & homogeneous linear equation
 
Lsd ee n
Lsd ee nLsd ee n
Lsd ee n
 
Math lecture 7 (Arithmetic Sequence)
Math lecture 7 (Arithmetic Sequence)Math lecture 7 (Arithmetic Sequence)
Math lecture 7 (Arithmetic Sequence)
 
Coueete project
Coueete projectCoueete project
Coueete project
 
Gaussian Elimination
Gaussian EliminationGaussian Elimination
Gaussian Elimination
 
Systems of equations
Systems of equationsSystems of equations
Systems of equations
 
Bounded var
Bounded varBounded var
Bounded var
 
April 16, 2014
April 16, 2014April 16, 2014
April 16, 2014
 
Ch03 5
Ch03 5Ch03 5
Ch03 5
 
7.1
7.17.1
7.1
 
Ma3bfet par 10.6 5 aug 2014
Ma3bfet par 10.6 5 aug 2014Ma3bfet par 10.6 5 aug 2014
Ma3bfet par 10.6 5 aug 2014
 
System of linear equations
System of linear equationsSystem of linear equations
System of linear equations
 
Linear equations
Linear equationsLinear equations
Linear equations
 
Systems of equations and matricies
Systems of equations and matriciesSystems of equations and matricies
Systems of equations and matricies
 
System of linear equations and their solution
System of linear equations and their solutionSystem of linear equations and their solution
System of linear equations and their solution
 
Solving systems of Linear Equations
Solving systems of Linear EquationsSolving systems of Linear Equations
Solving systems of Linear Equations
 
Maths project
Maths projectMaths project
Maths project
 

Viewers also liked

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
 
Towers Hanoi Algorithm
Towers Hanoi AlgorithmTowers Hanoi Algorithm
Towers Hanoi AlgorithmJorge Jasso
 
Monkey & banana problem in AI
Monkey & banana problem in AIMonkey & banana problem in AI
Monkey & banana problem in AIManjeet Kamboj
 
K to 12 - Grade 8 Araling Panlipunan Learners Module Quarter 2
K to 12 - Grade 8 Araling Panlipunan Learners Module Quarter 2K to 12 - Grade 8 Araling Panlipunan Learners Module Quarter 2
K to 12 - Grade 8 Araling Panlipunan Learners Module Quarter 2Nico Granada
 

Viewers also liked (8)

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
 
Tower of hanoi
Tower of hanoiTower of hanoi
Tower of hanoi
 
Tower of hanoi
Tower of hanoiTower of hanoi
Tower of hanoi
 
Tower of hanoi
Tower of hanoiTower of hanoi
Tower of hanoi
 
Towers Hanoi Algorithm
Towers Hanoi AlgorithmTowers Hanoi Algorithm
Towers Hanoi Algorithm
 
Tower of Hanoi
Tower of HanoiTower of Hanoi
Tower of Hanoi
 
Monkey & banana problem in AI
Monkey & banana problem in AIMonkey & banana problem in AI
Monkey & banana problem in AI
 
K to 12 - Grade 8 Araling Panlipunan Learners Module Quarter 2
K to 12 - Grade 8 Araling Panlipunan Learners Module Quarter 2K to 12 - Grade 8 Araling Panlipunan Learners Module Quarter 2
K to 12 - Grade 8 Araling Panlipunan Learners Module Quarter 2
 

Similar to Tower of hanoi problem

Binomial Theorem, Recursion ,Tower of Honai, relations
Binomial Theorem, Recursion ,Tower of Honai, relationsBinomial Theorem, Recursion ,Tower of Honai, relations
Binomial Theorem, Recursion ,Tower of Honai, relationsAqeel Rafique
 
Solution 1
Solution 1Solution 1
Solution 1aldrins
 
Solution 1
Solution 1Solution 1
Solution 1aldrins
 
Solutions Manual for An Introduction To Abstract Algebra With Notes To The Fu...
Solutions Manual for An Introduction To Abstract Algebra With Notes To The Fu...Solutions Manual for An Introduction To Abstract Algebra With Notes To The Fu...
Solutions Manual for An Introduction To Abstract Algebra With Notes To The Fu...Aladdinew
 
Conjugate Gradient Methods
Conjugate Gradient MethodsConjugate Gradient Methods
Conjugate Gradient MethodsMTiti1
 
modul pembelajaran 4
modul pembelajaran 4modul pembelajaran 4
modul pembelajaran 4Ajrina Pia
 
C2 st lecture 2 handout
C2 st lecture 2 handoutC2 st lecture 2 handout
C2 st lecture 2 handoutfatima d
 
Weatherwax cormen solutions
Weatherwax cormen solutionsWeatherwax cormen solutions
Weatherwax cormen solutionskirankoushik
 
3 d scaling and translation in homogeneous coordinates
3 d scaling and translation in homogeneous coordinates3 d scaling and translation in homogeneous coordinates
3 d scaling and translation in homogeneous coordinatesKRIPA SHNAKAR TIWARI
 

Similar to Tower of hanoi problem (20)

Binomial
BinomialBinomial
Binomial
 
Binomial Theorem, Recursion ,Tower of Honai, relations
Binomial Theorem, Recursion ,Tower of Honai, relationsBinomial Theorem, Recursion ,Tower of Honai, relations
Binomial Theorem, Recursion ,Tower of Honai, relations
 
Solution 1
Solution 1Solution 1
Solution 1
 
Solution 1
Solution 1Solution 1
Solution 1
 
Solutions Manual for An Introduction To Abstract Algebra With Notes To The Fu...
Solutions Manual for An Introduction To Abstract Algebra With Notes To The Fu...Solutions Manual for An Introduction To Abstract Algebra With Notes To The Fu...
Solutions Manual for An Introduction To Abstract Algebra With Notes To The Fu...
 
Conjugate Gradient Methods
Conjugate Gradient MethodsConjugate Gradient Methods
Conjugate Gradient Methods
 
Vivek
VivekVivek
Vivek
 
Statistical Method In Economics
Statistical Method In EconomicsStatistical Method In Economics
Statistical Method In Economics
 
Number theory
Number theoryNumber theory
Number theory
 
modul pembelajaran 4
modul pembelajaran 4modul pembelajaran 4
modul pembelajaran 4
 
Exponential function
Exponential functionExponential function
Exponential function
 
C2 st lecture 2 handout
C2 st lecture 2 handoutC2 st lecture 2 handout
C2 st lecture 2 handout
 
Weatherwax cormen solutions
Weatherwax cormen solutionsWeatherwax cormen solutions
Weatherwax cormen solutions
 
Advance algebra
Advance algebraAdvance algebra
Advance algebra
 
3 d scaling and translation in homogeneous coordinates
3 d scaling and translation in homogeneous coordinates3 d scaling and translation in homogeneous coordinates
3 d scaling and translation in homogeneous coordinates
 
Daa chapter 2
Daa chapter 2Daa chapter 2
Daa chapter 2
 
Ca 1.6
Ca 1.6Ca 1.6
Ca 1.6
 
104newton solution
104newton solution104newton solution
104newton solution
 
Quadratic equations
Quadratic equationsQuadratic equations
Quadratic equations
 
Binomial theorem
Binomial theoremBinomial theorem
Binomial theorem
 

More from Tyler Murphy

Job application 2020
Job application 2020Job application 2020
Job application 2020Tyler Murphy
 
The Table Method for Derivatives
The Table Method for DerivativesThe Table Method for Derivatives
The Table Method for DerivativesTyler Murphy
 
intro to Implicit differentiation
intro to Implicit differentiationintro to Implicit differentiation
intro to Implicit differentiationTyler Murphy
 
Intro to derivatives
Intro to derivativesIntro to derivatives
Intro to derivativesTyler Murphy
 
Limits as x approaches infinity
Limits as x approaches infinityLimits as x approaches infinity
Limits as x approaches infinityTyler Murphy
 
Introduction to limits
Introduction to limitsIntroduction to limits
Introduction to limitsTyler Murphy
 
Solving a trig equation
Solving a trig equationSolving a trig equation
Solving a trig equationTyler Murphy
 
solving a trig problem and sketching a graph example problems
solving a trig problem and sketching a graph example problemssolving a trig problem and sketching a graph example problems
solving a trig problem and sketching a graph example problemsTyler Murphy
 
Finding a polyomial from data
Finding a polyomial from dataFinding a polyomial from data
Finding a polyomial from dataTyler Murphy
 
Jason format preferences m170
Jason format preferences m170Jason format preferences m170
Jason format preferences m170Tyler Murphy
 
Final exam review
Final exam review Final exam review
Final exam review Tyler Murphy
 
Inclusion exclusion principle
Inclusion exclusion principleInclusion exclusion principle
Inclusion exclusion principleTyler Murphy
 
Oral exam structure M189
Oral exam structure M189Oral exam structure M189
Oral exam structure M189Tyler Murphy
 
Drop trow game rules
Drop trow game rules Drop trow game rules
Drop trow game rules Tyler Murphy
 

More from Tyler Murphy (20)

Job application 2020
Job application 2020Job application 2020
Job application 2020
 
The Table Method for Derivatives
The Table Method for DerivativesThe Table Method for Derivatives
The Table Method for Derivatives
 
Math 170 notation
Math 170 notationMath 170 notation
Math 170 notation
 
intro to Implicit differentiation
intro to Implicit differentiationintro to Implicit differentiation
intro to Implicit differentiation
 
Intro to derivatives
Intro to derivativesIntro to derivatives
Intro to derivatives
 
One sided limits
One sided limitsOne sided limits
One sided limits
 
Limits as x approaches infinity
Limits as x approaches infinityLimits as x approaches infinity
Limits as x approaches infinity
 
Computing limits
Computing limitsComputing limits
Computing limits
 
Introduction to limits
Introduction to limitsIntroduction to limits
Introduction to limits
 
Solving a trig equation
Solving a trig equationSolving a trig equation
Solving a trig equation
 
solving a trig problem and sketching a graph example problems
solving a trig problem and sketching a graph example problemssolving a trig problem and sketching a graph example problems
solving a trig problem and sketching a graph example problems
 
Finding a polyomial from data
Finding a polyomial from dataFinding a polyomial from data
Finding a polyomial from data
 
functions review
functions reviewfunctions review
functions review
 
Jason format preferences m170
Jason format preferences m170Jason format preferences m170
Jason format preferences m170
 
Final exam review
Final exam review Final exam review
Final exam review
 
Inclusion exclusion principle
Inclusion exclusion principleInclusion exclusion principle
Inclusion exclusion principle
 
Oral exam structure M189
Oral exam structure M189Oral exam structure M189
Oral exam structure M189
 
Class mods
Class mods Class mods
Class mods
 
Drop trow game rules
Drop trow game rules Drop trow game rules
Drop trow game rules
 
Exam 3 Math 189
Exam 3 Math 189Exam 3 Math 189
Exam 3 Math 189
 

Recently uploaded

How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
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.MaryamAhmad92
 
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
 
Magic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxMagic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxdhanalakshmis0310
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxAmita Gupta
 
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 FellowsMebane Rash
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docxPoojaSen20
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
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.pptxheathfieldcps1
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseAnaAcapella
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 

Recently uploaded (20)

How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
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.
 
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
 
Magic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxMagic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptx
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptx
 
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
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
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...
 
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
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 

Tower of hanoi problem

  • 1. Generating the Closed Formula for the Tower of Hanoi Problem Using Matrix Algebra Tyler Murphy September 30, 2014 1 Background The Tower of Hanoi (also called the Tower of Brahma or Lucas' Tower, and sometimes pluralized) is a mathematical game or puzzle. It consists of three rods, and a number of disks of dierent 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. Figure 1: Tower of Hanoi Game The objective of the puzzle is to move the entire stack to another rod, obeying the following simple rules: Only one disk can be moved at a time. 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. No disk may be placed on top of a smaller disk. We are interested in
  • 2. nding the smallest number of moves it takes to move a tower with n discs to another location. First, we generate a table of experimentation values 1
  • 3. Number of Discs (n) Minimum Number of Moves (Mn) 1 1 2 3 3 7 4 15 5 31 6 63 We see that after this point, experimentation begins to take a long time, so we stop here and try to devise a pattern. 2 Recurrence Form We notice that each value for Mn is twice the value of Mn1 plus 1. So we need to know the value for Mn1, which we can see would be dicult to generate for any large n. So calculating the value for Mn becomes no small task when we use the recurrence formula to
  • 4. nd it. We need a simpler way. It turns out that if can design a matrix that models this recurrence relation, we will be able to use this matrix to generate a closed formula to
  • 5. nd Mn without having to know Mn1. 3 Designing the Matrix Recall that a matrix is simply another way to write a system of equations. For example, the equations 2x + 3y = 4 (1) and x + y = 1: (2) These can be written in matrix multiplication form as: 2 3 1 1 x y = 4 1 So we can write our recursive formula in this manner. We will eventually end up with something of the form Anb = c Where A is our matrix, b is our initial value vector and c is our solution vector. 2
  • 6. Because of the constant term in the recursion relation and because Mn+1 only depends on Mn but not Mn1 (like the Fibonnaci sequence), we will use vectors of the form Mn 1 We also know our matrix will be a 2x2 matrix because we only have two terms in our recurrence formula. So: A = a11 a12 a21 a22 We want a matrix A such that Mn+1 1 = A Mn 1 The equations represented by this are: Mn+1 = a11Mn + a12 and 1 = a21Mn + a22: To make the
  • 7. rst equation true, we use the recursion relation and choose a11 = 2; a12 = 1. The second equation becomes true if we choose a21 = 0 and a22 = 1. Thus our matrix is A = 2 1 0 1 So, using this matrix, we can
  • 8. nd that Mn+1 1 = 2 1 0 1 Mn 1 This makes sense when we put it back into equation form and obtain: Mn+1 = 2Mn+1 and 1 = 0Mn+1. The problem now is that we still need an input vector that requires Mn in order to give us Mn+1. But consider that Mn+1 1 = A Mn 1 So for n = 1, M2 1 = A M1 1 3
  • 9. M3 1 = A A M1 1 = A2 M1 1 M4 1 = A A2 M1 1 = A3 M1 1 So we see the pattern that: Mn+1 1 = An M1 1 4 Quickly Computing An Since computing An for any large n would be extremely cumberson and dicult, we must
  • 10. nd a better way to computer these large powers of A. Linear Algebra teaches us that if a matrix can be diagonalized, then this process of computing powers becomes very simple. When a matrix is diagonalized, it becomes of the form A = SDS1 where S is the matrix composed of the eigenvectors of the matrix, and D is the diagonal matrix composed of the eigenvalues () of A. That is, D = I, where I is the Identity Matrix. 4.1 Finding the Eigenvalues of A So
  • 12. nd the eigenvalues associated with A. This is done by
  • 13. nding the values for that satisfy the equation: det(A I) = 0 First, we
  • 14. nd (A I) = 2 1 0 1 Recall that the determinant of a 2x2 matrix A = a b c d is ad bc So , Det(A = I) = (2 )(1 ) (0)(1). Setting this equal to zero and solving we
  • 15. nd = 1; 2. So we can plug these values into I to
  • 16. nd D = 1 0 0 2 4.2 Finding the Eigenvectors of A Now we need to
  • 17. nd the eigenvectors of A in order to
  • 18. nd our matrix S. This is done by solving the equation (A I)x = 0 4
  • 19. for each . First, we choose = 1. 2 1 1 0 1 1 x1 x2 = 1 1 0 0 x1 x2 = 0 0 Converting this to equations, we gets that x1 + x2 = 0 ) x1 = x2 and 0x1 + 0x2 = 0 Since the second equation tells us nothing, we use the
  • 21. nd that the basis vector x=1 = 1 1 . Doing the same thing for = 2, we
  • 22. nd that x=2 = 1 0 . Now we put these two eigenvectors into Matrix S, remembering that the order we put them into the matrix should match the order we put the eigenvalues into D. So, S = 1 1 1 0 . 4.3 Computing S1 Recall that the inverse of a 2x2 matrix A = a b c d = A1 = 1 Det(A) d b c a So S1 = 1 (1)(0) (1)(1) 0 1 1 1 = 1 0 1 1 1 = 0 1 1 1 4.4 Dealing with A = SDS1 So all put together, A = SDS1 = 1 1 1 0 1 0 0 2 0 1 1 1 It is a simple matter of matrix multiplication to verify the truth of this. Now recall that Mn+1 1 = An M1 1 5
  • 23. 5 Computing the Closed Formula The reason we diagonalize matrices is because An = SDnS1 and Dn is easily computed. So Mn+1 1 = 1 1 1 0 1 0 0 2 n 0 1 1 1 M1 1 Now realize that 1 0 0 2 n = 1n 0 0 2n = 1 0 0 2n So we have Mn+1 1 = 1 1 1 0 1 0 0 2n 0 1 1 1 M1 1 Now we can do some matrix multiplication to simplify this. We get Mn+1 1 = 1 1 1 0 1 0 0 2n 0 1 1 1 M1 1 Mn+1 1 = 1 2n 0 2n 0 1 1 1 M1 1 Mn+1 1 = 2n 2n 1 2n 2n M1 1 Recall now that M1 = 1. So we have Mn+1 1 = 2n 2n 1 2n 2n 1 1 Now we can convert this back into equational format and we
  • 24. nd that Mn+1 = 2n(1)+(2n 1)(1) = 2n +2n 1 = 2 2n 1 = 2n+1 1 (1) This is ok, but we want a formula that gives is Mn. We can get this by using our original recursive formula. Mn+1 = 2Mn + 1 (2) Substituting (2) into equation (1) we get: 2Mn + 1 = 2 2n 1 Now we simplify this. 2Mn + 1 = 2 2n 1 2Mn = 2 2n 2 Mn = 2n 1 So we
  • 25. nally have our closed form. The minimum number of moves for a tower of n discs is 2n 1. 6