ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e...
Transcript of ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e...
![Page 1: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/1.jpg)
V ~ T I O N S ON THE TOWER OF HANOI PUZZLE APPLIED'TO
SORTING PROBLEZMS
A Thesis Submitted to the Cornmitta on Gmduate Studies
in Putiril Fulfilmcnt of the Requiremenb for the
Dcgree of Master of Science
in the Faculty of Arts and Science
TRENT-
Peterborough, Ontario, Canada
@Copyright by Alma Iridia Barranco-Mendoza 1996
Applications of Modeüing in the Naharai and S o c s Sciences M.Sc Program
May 1997
![Page 2: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/2.jpg)
National Library 1*1 ofCanada Bibliothèque nationale du Canada
Acquisitions and Acquisitions et Bibliographie Services s e w b bibliographiques
The author bas granted a non- exc1usive licence aliowing the National Library of Canada to reproduce7 loan, d&ibute or s d copies of M e r thesis by any means and E any form or format, making
The author retains omership of the copyright in his(her thesis. Neither the thesis nor substantial exîmcts from it may be printed or otherwise reproduced with the author's permission.
L'auteur a accordé une licence non exclusive permettant à la Bibliothèque nationale du Canada de fepr-, prêter, disai%uerou vendre des copies de sa thèse de
firmie que ce soit pour metîre des exemplaires de cette thèse à la disposition des pasornes intéressées.
L'auteur conseme la propriétte du droit d'auteur qui protège sa thèse. Ni la thèse ni des extraits substantieis de celle-ci ne doivent être Hnprimés ou autremenîreproduitssansson autorisatin*
![Page 3: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/3.jpg)
Variations OP the Tower of m o i Puzde Appüd to Sorthg ProbIems
Alma Iridia Bnrlnco-Mendoza
In this thesis, two variations of the Tower of Hawi puzzle were defined to solve
sorting problem that require the merge of stacks meintainhg the priorities of the stacks as
well as the order of theV elements. One variation was the Coloured Towers Merge
(CTM) Problem and the other was the Three Coloured Towers Merge (TCTM) Problem.
Mathematid models were ddoped to obtsined the optimal solutions for the TCTM
problem and for the particular case of CTM problem with two towers. From these
mathematicai models, a gened equation for the solution to the CTM p r o b b with rn
towers, where m is an integer, was deriveci. These models iàcilitate the representation
and the caldation of the minimum number of moves to solve the specified sorthg
problems as weil as aid in the development of cornputer algonthms to paform these sons.
In addition, they help to analyse the feaSib0ity and advantages of certain solutions above
others.
![Page 4: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/4.jpg)
Arno-
h~ making these ackwwledgements, 1 wotiid ld iike to give my sincerest
to my supervWr, Dr. David Poole; not ody for bis critique, &ght and
cornmitment to my nsemch but also for his fnendship, which I hold very dear to me, his
great commitment to education and his love for Mathemtics, wbich 1 m t l y admire and
have daply inspirecl me. My gratihide also goes out to Dr. B a Zhou for introducing
me 4 a rather abrupt w a p to the Tower of Hanoi problern and for his imights on this
research. The same goes to Dr. Richard Hurley and Dr. George Hamilton for theit
Uisights and winments while carefùliy proof-reading this thesis. To my fliends Cindy
Awe, Haiying Zhang, Marianne Maijaars, JamiIeh Naidj, other feiiow students and
profkssors of the AMINSS, Mathematics ami Cornputer Studies programs and the Trent
International Program 1 say thank you for making this leamhg experience a pleasant and
fulfilluig jomey. Finally, to the people tbat have always been there for me, my husbanci
Deryck Persaud, rny Trinidadian and Canadian parents Lloyd and Sheiia Persaud and Bob
and Jean Oliver, my love and gratitude, always. En especiai quiero agradecer a mis padres
Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m
amor y apoyo moral de siempre. Un agdecimiento especial a mi papa y a mi abuelito
Lupe por constniirme el mode10 de rnadera de las Torres de Hanoi utiüzado para esta
![Page 5: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/5.jpg)
Variations on the Tower of Hanoi Puzzle Applied to Sorting Pro blems
TABLE OF CONTENTS
................................................................................................ 1 .O. INTRODUCTION 1
2.0. L ITERATURE R E W AND OBJECTIVES .. .. ................................................ 9 ..................................................... 2.1 . History of the Towa of Hanoi p d e 9
.................................................... 2.2. Interesthg characteristics and properties 10
................... ..................... 2.3. Variatiom on the Tower of m o i puzzie* .... 12
2.3.1. Variations on the number ofpegs- .............................................. 12
2.3 .2 . Variations on the number and characteristics of the disks ............ 12 . 0 ............................... 2.3.3. Vana~ons on the des ...... .... 12
2.3 .4 . Variations on the number of towers ............. .,. ..,. ................... 13
............................. ......................... 2.4. The Coloured Towers Merge Problem 14
........................................ ................... 2.5. Objectives of this researc h. ....... 15
.......................................................................................................... 3.0. ANALYSIS 16
. . ..... .........*.......*.............*...*.........*..............*............... 3.1. Defirution S.. .... 16
................................................................ . 3 .2 CTM problem with two towers 17
. .... ................. 4.0. THREE COLOURED TOWERS MERGE PROBLEU ...... ... 39
5.0. A GENER4L SOLUTION TO THE COLOURED TOWERS MERGE
........................................................................................................... PROBLEM 68
....................................................... 6.0. APPLICATIONS AND CONCLUSIONS 80 . . ...................................................................................... 6.1. Applications 8 0
.......................................................................................... 6.2. Open questions 84
.......................................................... ........................... 6.3. Conclusions .,., 8 4
......................................................................................................... MPENDIX A 8 7
................................................. Solution of second order recurrence relations 87
![Page 6: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/6.jpg)
Al . Nonhomogeneous reamence relation in which qn) is a
poiynomid ................................~............................................... 87
A2 . Nonhomogmews recurreace rektion in which Rn) is an *
e x p o n d .............................................................................. 8 9
APPENDIX B ......~...................................................................................................... 90
REFERENCES ......................................................................................................... 9 3
![Page 7: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/7.jpg)
TABLE OF FIGURES
Figure 1 .
Figure 2 .
Figure 3 .
Figuse 4 . Figure 5 .
Figure 6 . Figure 7 .
Figure 8 .
Figure 9 .
Figure 10 .
Figure 1 1 .
Figure 12 . Figure 13 .
Figure 14 .
Figue 15 .
Figure 16 .
Railway SWifching network wit& thtee tracks and two traiiy with n = 4 .......... 2
........... .............................. Desired d t afhr merging two trains with 4 cars 3
.............................................. The commoa components of cornputer mems 4
Graphitai representation of a stack ...........~................................................... 5
a) Graphical representation of the pmgram, b) physicai structure, and
................................................................... C) mode1 of finite element d y s i s 6
.......................... ...................... The onginai Tower of Hanoi puzde ...... 8
....................................... Strategy to solve the Tower of Hanoi puale 9
Hanoi Graph H,, Pascaits triangle (mod 2) and Sierpinski's gasket ................ 11
Initial coafiguration ofthe CTM merge problem with m=3 and n=4 .............. 14
initial and final configuration for the CTM problern with two towers ............ 18
Sequence of steps to obtain T(2,n) ........................................................... 1 9
.................................. ........................ Strategy to obtah M&n) ............ 2 5
........................................................................... Strategy to obtain M2(2.n) 26
........................................................................... Strategy to obtain M,(2,n) 2 7
............................................. Strategy to obtain M,(2,n) .................... ... 31
initial and fiaal configuration on Peg 2 for the TCTM problem .................... 40
............................... Figure 17 . AU possible elernents of S3 ................................... ... 40
Figure 18 . Strategy to obtain T(n) for the TCTM probl em. ........................................... 41
Figure 19 . Strategy to obtain T(n) for the TCTM problem .......................................... 45
Figure 20 . Possible strategies to obtaiD s,, (n) for the TCTM problem ............................. 57
Figure 21 . Strategies to obtain &(m, n) for the CTM problem on Peg O ........................ 74
Figure 22 . Strategy to obtain Wm(m.n) .......................................................................... 76
Figure 23 . Rdway switchiog nnwork problem represented as CTM problem ................ 80
Figure 24 . Graphical representation of the structures of the program on Chapter 1 ........ 81
vi
![Page 8: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/8.jpg)
Order is an intrinsic part of Natwe. EverythiPg thaî is natural fouows a vey
s p d c pattern or has a particular place in the Universe!. Humaiis bave fie nanatural
instinct of sortiag thiiigs, Le., putthg them in a certain phce or rank accordhg to kind,
class or type, in order to visualize. understand or utiiize them betta.
Sorting cm often be the simplest oftasks but, @en artain conditions, soning can
also be a very challengïng problem. The complaity of sorthg is diredy proportional to
the number of elements to be sorteci and the complexity of these elements. The more
cornplex the sort iq the longer it will take to be completed.
Throughout history, people have also aied to do things nister, more efficiently and
with the least amount of effort. Ahost aü the methods and technologies that have been
developed had one or all of these objectives.
When one needs to sort a @en set of objects it is sometimes very difEcult to
figure out the fastest way to do so. Supposing there is a set of n distinct objects in a he,
where n is any finite imeger, there would be n! diierent possible ordered arrangements of
ri elements [42]. Every t h e an element is moved and set somewhere else in the line a
dEerent arrangement out of the n! possible ones is obtained. So, it can eady be observed
that selecting the correct and miaimm sequence of arrangements needed to obtain the
desired order is quite a cornplex task when it cornes to moderately large 0's.
In addition to this, sometimes the type of sort requed possesses ceriain
characteristics and conditions that make a strategy to solve it difljcult to visuaiize. The
following example, although not totdy realistic, shows this cleady.
Suppose there is a railway switching network with three tracks like the one shown
in Figure 1. On the left vadr is a train facing west with n cars containhg cargo to be
deiivered for Company A The n cars are numbered consecutively according to each of
their weights (all different) and are ordered in such a way that the heaMest car, numbered
![Page 9: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/9.jpg)
n, is next to the engine; the lightest one, numbed 1, at îhe end; and no heavier car is
behind a lighter one for dety reasons. 0ii the right tfack is an identicai train faciog east
containing cargo to be delivered for Company B. On the pewdicular&ack there is just
YI.
Fi y r e 1. Railway switching network with thne tracks and two trains, with n = 4.
It is necessary to merge aii the cars of both trains behind the engine faciag south, in
such a way that the heaviest car is closest to the engine and the lightest one at the ead;
and, in the case of cars with the same number, the one with cargo for Company B must be
behind the one with cargo for Company 4 as show in Figure 2. This is to avoid
confusions when the cargo k picked up. In addition, while moving the cars, no car can
ever be behind a car with less weight and ody one car at a time uin be moved. Suppose
every t h e a car is moved costs the railway Company $5.00. What is the fastest and,
hence, cheapest way to do this mage following the conditions, and how many rnoves are
required?
![Page 10: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/10.jpg)
Figure 2. Desired r d t &a merging two trains with 4 cars.
Even though it may look simple, fjnding the best solution to the trains problern
above stated is not easy for moderately large n. The number of possible soiutions is quite
large and it grows exponentially as more cars are added to the trains. This is the type of
problem that wiil be discussed in this researcb,
The invention of the computer bas drasticaliy changed the way problems are
solved. Computations that before would have taken hours or even days to pefiorm uui
now be solved in a matter of fiactions of a second. Jobs tbat would have required
hundreds of workers are now autornated and controlled by a single person and a computer
or network of cornputers.
A computer system, regardless of its sophistication, will dways have certain
common components. The cornmon hardware components an primary and secondary
storage, processing unit, and control unit. There may be one or more of these
components. In addition to the hardware there WU be a software structure which can
Vary in complexity fiom a single executable program to a large set iacluding operating
systerns, editors, compiler, user prograrns, applications, etc. [20]. The way these
common components interact can be observed in Figure 3.
![Page 11: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/11.jpg)
Figure 3. The comrnoa componems ofcornputer system.
Hardware improvement is an important &or in the iacrease of power of
computer qstems. However, it shouid not be forgottea that t is the software that
indicates to the computer the steps to foilow to solve the problem and its optimality is
very important to the improvement in the operation of the hardware components.
Two very important elements to consider while developing software are the
maaipulation and representation of data. These are represented through ab~lruct riata
w s . The definition of an abstract data type involves a description of the way the data
components relate to each other and the operations that can be perfomed on these
elernents [29]. In this research, we are interested in the abstract data type calleci a stack.
A stack is a finite sequence of elements in which ail the ber&ioas and deletions are made
at one end, caiied the top of the stack. Figure 4 &es a graphical representation of a
stack.
![Page 12: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/12.jpg)
Figure 4. Graphical representation of a stack
The stack is one of the shplest absttact data types to manipulate as it is
only wcessary to keep track of the top of the stack to insert and delete elements. As
simple as it is, this data type is widely used and there are rnay ways to implement it.
Suppose there is a cornputer program that is composed ofm processes with the
followîng characteristics. Each one of these m processes has to perform n routines in the
foiiowing order: Routine n obtains some partial results and then calls Routine ml, which
obtains other partial resuits and then cak Routine n-2, which obtains partiai results and
caUs Routine n-3, and so on und Routine 1 is d e d by Routine 2. Once Routine 1 is
finished, its partial results wiU be used by Routine 2 and then it wili finish, then Routine 3,
and so on. Thinking of the structure of this, each one of the m processes forms a stack
with the partial results of Routine n at the bottom and the ones of Routine 1 at the top.
- However, Routine 1 of Process m requires the r d t s of Routine 1 of Proeess m-1 which
requires the results of Routine 1 of Process m-2 and so on for aii routines of d processes.
This can be observed in Figure Sa
This specifïc type of program c m be used, for example, to mode1 the technique of
finite element anelysis applied in the field of engineering. Tbis technique consists of
approximating a physical structure (a piece of machinery or a section of a building, for
example) by a series of plane elements. The mechanical properties will be described by
equations including constants, such as the tende strenght of steel, and variables, such as
![Page 13: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/13.jpg)
the thickness of the materid and the stnssu applied at specific points. Such stresses
appîied to each dement by the adjohhg elements, which in tum are affected by their
neighbours. Hence, the series ofequatiom descriiig the entire structure are ail Iinked . and the result of one wilI affect the 0th- 1201. Figure Sb shows an structure with
stresses applied on specific poims (represented by mm) and Figure Sc shows the model
of the nnite element analysis of the structure (each box repfesents an equation or series of
equaîions descniig an specitic element of the structure). To caldate the &ect of the
stresses first the stress is a pplied to Elemaits a, b, and c of the structure. The stress on c
is passed on toJ then to i and W y to 2. But to h o w the nal stress on 1, it is required
to know the stress on k which requkes aiso the stress on j.
Figure S. a) Graphitai representation of the program, b) physicai structure, and
c) model of finite element analysis.
![Page 14: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/14.jpg)
The best way to nm aU the processes in the least amount of tiw wouid @e m
processors nrnniag in pacatlel. Howevm, most of the computer systems on the market
have a single p r d g unit since each uMt ù expensive. To avoid the expense, it wodd
be aecessary to simulate thekarailel proctssmg by fïrst m a h g the m process &ks aad
then mer& them into a single stack such that the results of Routine 1 of Pracess 1 is at
the top, then the ones of Routine 1 of Process 2, etc., with the ones of Routine rt of
Process m at the bonom of the stack 1s this second solution truiy les expensiw than
buying the processors?
Regardles of how dinérent it looks, this programmiDg probiem is quite simiiar to
the trains problem stated before.
By utiluing mathematical modds to solve problem it is easier to idemte similar
problems, regardless of how different they are in nature. The objective of this research
was to develop a mathematical model to solve sorting problems that require merging two
or more stacks whose elements have certain priorities imo one stack rnaintaining the
priorities of the elements.
A variation of the Tower of Hanoi puzde was used ss a model for this kind of
problem The original Tower of Hanoi puzde consists of a board with three pegs,
numbered fiom left to right O, 1, and 2, and a set of concentric rings, aü of difEerent sizes,
inserted in one of the pegs, as show in Figure 6. The objective of the puzzle is to
trader in the least number of moves the tower of rings fiom one peg to another by
moving one Nig at a the fkom the top of a tower and neva setting a bigger ring on top of
a smaiier one.
![Page 15: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/15.jpg)
Pigun 6. The originai Tower ofHanoi p d e .
It can be cfearly observeci that a Tower of Hanoi is a physicai representation of a
stack whose elernents have a pnonty (the size of the rings). As for the stack, in a Tower
of Hanoi the elements caa only be added or removed âom the top.
In this research, the original p d e has been rnodified by adding towers of
differenat colours and more pegs with the objective of merging the towers in a required
colour and size order without alterhg the original des.
In the foiiowing chapters some variations on the Tower of Hanoi p d e that have
beui studied wiil be discussed and how they rekte to the variation presented here wili be
sbown Optimal solutious wiiî be &en for the specinc problems of merghg two and
tbree towers with n rings each using thrw pegs and a generai solution to merge m towers
with n ~ g s using m+l pegs will be presented, although the optimafity of this Iast one wili
not be proven.
![Page 16: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/16.jpg)
2.0. LITERATURE REWEW AND OBJECTIVES
2.1. History of the Tower of Hanoi puzzit,
In 1883, the nmber theorkt Edouard Lucas, unda the pseudonym "Professor
Claus", presented in Paris for the fht tim the Tower of Hanoi puzzle [39]. This original
version consisteci ofa board with three wooden pegs &ed to it and a set of eight disks,
aii of différent d i e t e n , inserted on one of the pegs in a decreashg sire order fiom the
base fonning a tower. The objective was to W e r the tower to another peg moving one
topmost disk at a the without mer placing a disk on top ofa srnalier one.
k 1884. Mardice and Fraser presented the fmt so1ution of the Tower of Hanoi
puzzie to be published in the mathematical literature [Il. If the p d e is generalu:ed in
mathematid terms as a tower of n disks, to obtain the minimum number of moves to
trader the tower fiom one peg to another the following strategy cm be used. Since the
largest disk bas to be moved fiom the initial peg to the target peg, first transfer the top n-1
disks fkom the initial peg to the araàliary peg using the least number of moves. IfMn) is
de- to be the least number of moves tu Cransfer a tower with n disks Born one peg to
another, then it wilî take h(n-1) moves to traiufer the top n-1 disks fiom the initial peg to
the aiwliary one. It wiii take one more move to tratisfer the largest disk fiom the initiai
peg to the taqpt one. Fùially. it takes h(n-1) moves to trander the top n-1 disks fom the
auxiliary peg to the target one. Figure 7 illustrates this strategy which wiU give the
recurrence relation
h(n) = 2yn-1) + 1.
Figure 7. Strategy to solve the Tower of Hanoi p d e .
9
![Page 17: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/17.jpg)
If h(0) = O is taken as the initial condition, the abow recurreace caa be soived
d i r d y to obtain the wd-knowu solution
Mn) =Zn - 1. Reg,ardless of the clarity of this p r o 4 it does mt indicate the opthdi& of the
solution. In fkct, it was not until 1981 that Wood [Sl] showed that this solution is
optimal and that the optimai sequence of moves U unique*
2.2. Intcresting characteristics and properticr.
A lot has been witten about this p d e sin& it was tint introduced more than a
century ago, but it has ody been in the past two decades that mathematicians and
computer scientists have regaineci a stronger interest in the Tower ofHanoi puzzle.
It is kcbting to reaüze that a simple problem like t h with such a weii-known
and clear solution can have so -y properties and characteristics worth wrîting about.
In his books 122, Chapter 6 and 23, Chapter 21, ûardner explains how ushg a
binary'hy code can help to determine the squmce of disk moves, a fact probably
known to Lucas himseK The symmetry of the rnoves to solve this problem has led
computer scientists to use the Tower of Hanoi p d e as a good example to srplab -and
sometimes even debate over- the meris and dserences of iterative and recursive
algorithms to solve this problexn [5,7,9,1 l,25,30,49]. In fiict, it is ofken included in
Cornputer Science textbooks as a prognimmiPg exercise [29].
It has also been proved that, when pafomhg the optimal solution to the Tower of
Hanoi puzzle with n disks, a sequence of moves is neva imaiediately repeated [2].
With a legd configuration of disks denned as any contiguration obtained by
performirig any number of disk moves following the Tower of HMoi rules where no disk
is on top of a s d e r one, Er [12-141 has wnsidered the problem where the initial
configuration can be any legal configwation of disks aMS they have to be moved to a single
tower. This has been called the "Generulized Tower of Hanoiw problem.
![Page 18: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/18.jpg)
Consider every possible dBxent Iegd coiiEiguration with n rings to be a vertex
and draw an edge between every two configurations if one CM be obt9ined f h n the other
with oniy one legal disk move. This set of vertices and edges will give the gtqh of Iegal
moves of the Tower of m o i problem with n rings. These grapbs, one for each &teger n,
have been r e f d to as Hknoi Grqhs or H' [3 l,4SS8,2q.
These graphs display some very interesthg chairacteristics. It has ban obsaved
that as n becornes larger, H, becornes a h c t d [4n. in fiict. it has a ciear resemblance to
the Sierphki gasket, a weH known hctal, PSI and P d ' s triangie [48,50], as shown in
Figure 8. In fiict, Poole proved that there is agr<p>h isomorphim, defmed as the one-to-
oae correspondence of the elexnents of a graph onto the elements of auother graph,
between the Hanoi Graph and the graph obtaimd fiom dnwmg edges between adjacent
odd numbers in Pascal's Triaagie; this was named the Lucm c o r r e ~ ~ n c e 1411.
Hanoi Graph H3
1
1
Figure 8. Hanoi Graph H,, Pascal's triangle (mod 2) and Sierpinslals ga~ket.
![Page 19: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/19.jpg)
2.3. V h t i 0 1 1 ~ on the Tower of Hiwi p d e .
In addition to the study of the characteristics ad pm@es of the original Tower
of Hanoi puzzle other studies have been done by changing one or more characteristics of
the p d e . These variations have ken donc on the mimba of pegs, numba of towers,
characteristics of the ~ g s , des or strategy to soive the pmblcm.
2.3.1. Vm*ations on the number of W.
Incfe8shg the nurnber of pegs is, so far, the most challaiging variation to the \
p d e . Dudeney presented a version of the pmbfeh where he had four stook (the pegs)
and cheeses of different &es (the rings) stacked on one of the stools. He d e d it "The
Reve 5 P d e n [IO]. Since then, several solutions and algonthms to sdving the problem
with four or more pegs have been presented [4y21,43,46], h ~ w e v e r ~ nobody has yet
proven the minimality of these solutions. To prove this mbimüty has been obsetved to
be a very difl6dt problem, as explaineci in [q, [34]¶ the aAerword of 122, revised dtion],
and the editorial note following [46].
2.3.2. Variations on the number and characteristics of the &bs.
Another variation to the p d e can be achieved by hahg several copies of disks
of the same size and these copies may be distiaguishable or not. For crrample, Wood
pnswts a *roblem where there are d copies of each disk ad the usud ruies apply [Sl].
In [24 exercise 1-12]. a more general version of this problem is presented with 4 copies of
disk i, for every i n.
2.3.3. Variations on the d e s .
Several authors have modifieci the original rula of the puale, developiog new and
interesthg problems. 'WaightIine Hmoi" [36] is a variation obtained by adcüng the
restriction that a disk may oniy be moved to or h m Peg 1 1451. In "CycUc Hmtoi", the
pegs are ananged in a circle such that the disks may oniy be moved one at a tirne in
![Page 20: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/20.jpg)
hahg dish of metent colours aad using these coloun to cesfric# the mwment of the
disks. Er considen in [lq the pmblem of havuig each colouf move in a different
direction, and Minsker in [37i forbids disks of the same dour to be adj& to one
another. In the tY3~ttIene~k Tawers of Hmoii" p m b h [a], baseci on the work by Wood
in [51], Poole ad6 to the onginal set ofnila the condition thrt a dUk i may not be placeci
on a tower of disks T if i N(I) + b-1, where N(l) is the number of the amalfest disk in T
and b is the bottleneck si=, Le-, the maxiinum &e of an ïaverted tower which can be
legaiiy fomed.
2.3.4. Variations on the number of towers.
The "Twn-T'' Problem", proposed by A.J. van Zmten, wnsisted of a tower of
n black disks and a tower of white disks and the objective was to interchange these
towers, moviog one disk at a tirne, and using an a d a q peg. No disk may ever rest on
top of a smaiîer one, and in the case of disks of the same size, the white disk must aiways
be on top of the black one 1521. Another example of this kind of variation is the "Tmers
of Antwerpen" problem presented by Minsker 137- This problem has a r d tower on Peg
O, a white one on Peg 1 and a blue one on Peg 2 as initial coufiguration. The object of
the problem is to traasfer the reâ, white and blue towers to pegs 1,2, and 0, respectively,
following the same d e s as the original puzzle. In this case. disla of the same size can be
on top of each other, regardkss of colour.
The variation t&at will be analysed in this research beiongs to the types of variation
on the number o f towers and on the number of pegs. This variation will be d e d "The
Coiwed Towers Merge Ptobiem".
![Page 21: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/21.jpg)
2.4. The Coloured Towers Mecge ProbItm
Consider a bard .with 111+1 pegs a e d to if numbaed &om left to right
0, 1,2, ...,mnr. The initial configuration of the Colound Towas Merge Problan copsiDsts d
m towers withn disks ofMereat Jues each ioserted on pegs Osls ...,m- 1. Each tower is
coloured in a Wêrent colour, oamed CO, ci, q..,c,,,-,. cotfespoIidiog to the munber of
the peg in which it is insefiecl. Numbet the disks h m * 1 to n, d e s t to kgest. AU the
towers have the same n &es of disks Figure 9 displays the initiai coafiguration of the
Coloured Towers Merge problem with nt = 3 and n p 4.
Figure 9. Initiai configuration of the CTM mefge problem with m=3 and A.
The object of this problem is to merge the m towers in the least nurnber of moves
foUowhg the original Tower of Hanoi d e s in such a way tbat the rings are in decreasing
order fiom bottom up and, in the case of dislrs of the same size, the cn,-~ disk is on the
bottom of the set foiîowing a deaeasing colour orda up to the CO disk on the top of the
set. Note that during the intemediate steps the CO~OUT orda for disks of the same size
does not matter. Aithough for the case ofm = 2 this pmblem looks quite similar to the
partial solution of the "Twin-Tower Problem" [52L by not restricting the colour order
![Page 22: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/22.jpg)
during the intemediate stepq t&e solution to this problem is very ditterrit fkom -arid a
lot more chailenging thabthe so1utïon of [S2].
2.5. Objectiva of thir res~ucb. . The centrai objective of- nseanh was to tiid a general solution for any m m 2
to the Colour Towers Merge (CTM) Problan B caa &y k observed kt . , in fact, . there are different solution^ to this problmi dependhg on wbich one of the m+ï pegs the
towers wiU be merged onto.
As the nrst step of the investigation, the solutions to the CTM problem with two
towers was obtained and proved optMal. Bascd on these optimal solutions, an optimal
algorithm to solve the problem was developed This is presented in Chapter 3. In
Chapter 4, since proving optimality to any variation on the Towa of Hanoi p d e with
more than three pegs has not yet been possible, it was decided to anaiyse a stight variation
to the CTM problem with three towers where the number of pegs was thme, not four, in
order to find the optimal solutions and use this solutio11~ as upper boundary for the
anaiysis of the reai CTM problem with three towers. This variation is somewhat simiiar
to the "Tawers of Anfwe'pen" problem [373 as the initial mafiguration is the same,
however the objective of that study and the one of this research are quite difrent.
FinaUy, in Chapter 5, based on the above d y s i s andon the nsults of the papers on the
variations of the Tower of Hanoi puzzle with more than three pegs presented in
Section 2.3.1.. the general CTM problem was anaiyseâ and a solution was proposeci,
howwa, the optimality proof was beyond the sçope of tbis research
In the final chapter. it is shown how these solutions are applied to sortbg problems
of the type preseated in the introduction.
![Page 23: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/23.jpg)
To start with the anaiysis of the problem, it W repuind first to define some term.
3.1. Defiaifioiw.
Let a tower of die n be a stadr of n disks of d i&mt diamden stacked in
deaeasing orda of size (srnailest on the top, largeSc on the bottom). Nimber the disks
fiom 1 to n, s d e s t to largest.
Define a mixed tower of slze mi as a towq with mn disks, n c o l o d with some
colour ç,, n coloured with some coIour c,, ..., n coloured with some colour c,, with the
same n different s k s for aU m colours. Define the correct coIozw or&t of a set of m
disks as that which occurs d e i the diameter of al1 the disks in the set is the sarne and the
colour order is increasing fiom bottom up, Le., the cm, disk is at the top of the set and the
c, one is at the bottom ofthe set. However, ifthe colour order is deaeasing fkom bottom
up then t is d e d the imerted co lm or&r.
By an optimal soIution we refer to a solution tbat requires the least nurnber of
steps to be obtained, Le., to obtah any other possible solution we will require more or
equal number of steps.
Now, define the Coloured Towers Merge (CTM) problem. As the initial
cod&on of the CTM problem, there are m towers of size n, one with ai i its disks
coloured in c, on peg y, for aü yé (O, 1,2, ...pz- 1). The n disk sizes of aü the towers are
equai, except for their colour.
The object of the CTM problem is to merge, using the foiiowiag des, al1 the disks
into a mixeci tower of size mn with the correct wlour order for al1 n sets of m disks of the
sanie size. The rules are:
1. Oniy one disk at a time rnay be moved;
2. Only the top disk in a tower rnay be moved;
![Page 24: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/24.jpg)
3. A disk may ody be plaad on top of a disk of equai or larger
diameter, regardles of douq
4. The towen are to be merged in a miiàmum number of moves.
La Ma2,tz) be the miaimUm number of moves requirrd to wlve the CTM problem
on peg x, where x~(O,l ,2 , . . .~} for a board with Hl pegs, mimbaed fiom left to right
O, 1, ..., m respednrely. The problem is to determine a g e n d formuia for each of Man) ,
for ail x a (0, ..., m).
Dehe a legal c~@@r&~dion a~ any arrangement of disks on the Hl pegs
obtained by repeatedly applying any combinan'on of des I thmugh 3.
Now, define the functioa T'(Zn) to be the minimum number ofmoves required to
trader a mixed tower of ske mn fiom one peg to a legai configuration on another peg.
In addition to T(2,n), define the fiinction T(2,n) to be the minimum number of
moves required to t r d e r a mked tower of size mfi nom one peg to a legai configuration
on another peg, maintahhg the original wlour order of al1 the n sets of disks of the same
size.
3.2. CTM problem with two towers.
We start by analyzhg the CTM problem where m = 2. Figure 10 shows the initial
configuration and a final one on Peg 2.
![Page 25: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/25.jpg)
Figure 10. Initial and nnal configuration for the CTM problem with two towers.
Füst we analyse the fbnctioas T(2,n) and T(2,n) for m = 2.
Lemma 3.2.1: The hction T satisEies the recurcence relation
T(2,n) = 2T(2p1)+2 , for d n 2 1.
ProoE In order to transfer a mixed tower of size 2n, the pair of âisks n must move
to the target peg Accordkg to the niles, they m o t be placed on top of
a tower containin8 an. of disks 1, 2, ... , nl; hence, these caanot be on
the target peg. So fint move the to n-1 pairs of dWks to the spare peg in
T(2,n-1) moves. Then move the remainbg pair ofdisks to the target peg
using amther 2 moves, inverting the wlour order (this must be part of a
minMal sequence for othwise at least one of the disks of the bottom pair
* will be moved twice). F i i y , M e r the mixed tower of size 2(n-1) on
the spare peg to the target peg in T(2,n-1) movw. This establishes the
reaurence. The steps are show grapbicaüy in Figure 1 1.
![Page 26: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/26.jpg)
Figure 11. Sequence ofsteps to 06taia T(2,n). .
Add the initial condition T(2.0) = O to sdve the rec~nence relation This has a
physical meaning since no moves are nqued to move an empty toweq and it is also
consistent with the recurence.
Corollvg 3.23: For al n 2 1. the hction T, when applied to a mixed tower of
size 2n, wiU giw as resuit a mixed tower of size 2n preserviog the
original colout order for aii the top n-l pairs and invating it for the
bottom pair n.
ProoC W e prove this by induction on n.
Let n = 1. T(2.1) = 2T(2,0)+2 = 2 by Lemma 3 2 .1 . To transfer a mked
tower of size I to another peg in the le& nwiber of moves the top disk
must be moved to the target peg and then the bottom disk to the target
peg. This &es a mùced tower of size 2 inverthg the original colour order
in 2 moves. Any other le@ co&guration would be obtained using more
moves. Hence, it is mie for n = 1.
Induction hpothesib Suppose t is tnie that, for ail n s k, T(2,n), when
applied to a mixeci tower of size b, wül give as r d t a mixed tower of
size Zn preservhg the original colour order for all the top n-1 pairs and
inverthg it for the bottom pair n.
Now it has to be provd for n = k+l. Suppose tbere is a mixed tower of
ske Z(k1) . Apply T(2,M). By Lenima 32.1, T(2,hl) = 2T(2,k)+2.
Physicaly, this means that first the top k pairs have to be transferred to the
![Page 27: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/27.jpg)
spare peg. By induction bvpotbesî~, the first traasfa of the top k pairs will
resuit into a mixed tower of s k 2k Witb the colour order of the bottom
pair k inverteci on the span peg; hmce, to obtah the least nwnber of
rnoves. T(2,k) is used. Then, transfer the bottom pair to th &et peg.
This will take 2 moves and obtain a mixed tower of& 2 with the colour
order berteci on the target peg as arplauied earlier. F d y , transfèr the
mixecl tower of size k to the target peg by u h g T(2.k). By induction
hypothesis, the colour orda of the top k pain will be the ntunied to the
origiaal oae since the colour order of the bottom pair wiU be inverteci,
gMng as r d t a mixed tower of size 2k with the origmel colour order on
top of an inverteci pair. Hence, the coroiiary is m e for aü n 2 1.
Proposition 3.23: T(2,n) = 2(2*-1), for ail n 2 1.
Fwthennore, T is the optimal soiution to traosfer a mixed
tower of sise 2n âom one peg to another.
ProoC From Lernma 3 -2.1. T(23) = 2T(2,n-1)+2. Consider the initial condition
T(2,O) = O. The solution wiU be of the form T(5n) = &, where r is
the mot of the characteristic equatioa, b is a coustant depending on the
independent tenu 2 of the origmal function, and a is a constant dependiig
on the initial condition w e r to AppendUc A for m e r details on the
solutioa of remence relations.)
It can easily be obse~ed that r=2.
For simpticity, ignore the texm cd: since it only depends on the initial
condition T(2,0)=0, and let "r(2~~) = b and T(2.n-1) = b.
Substituting, b = 2H2. Hace, b = -2. So, since T(2,n) = a2"-2,
T(2.0) = a-2 = O. Therâore, u = 2. which leads to T(2p) = 2(2"-1).
It is not bard to prove that tbis solution is optimai. To t d e r a mixed
tower of sue Zn we must, at some point, move the pair of disks n at least
![Page 28: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/28.jpg)
once. To do this we rapuire thk pair to be aione in the on- peg and
one other peg to be empty. Thdore, the srminer n-1 pairs ofdisks must
be on the remaining peg Kence, no otha possible aigorithm can do M e r
thaa fiirst moviag the top ml pain Born the original peg to the &an peg
to the target pe& then the bottom disk n h m the origmal peg to the target
ptg on top of the other dùk n ~ l ~ l ~ w h g the colour order of the pair), and
noally transfmg again thc top ml pairs h m the *are peg to the target
peg, on top of the pair ofdisks n, using the optimai strategy. Therefore, if
OT(n) denotes the total number of moves used by the op- mtegy to
d e r a mixed tower of size 2n âom one peg to mother, it can be
observeci that OT(n) >_ 20T(n-l)+2
Since OT(0) = O, it follows that OT(n) 2 2(2m-1). Hence, T is oprimal.
Lemma 3.2.4: The fùnction T satkfies the relation
T(2,n) = 4T(2,n-1)+3, for al1 n 2 1.
ProoE In order to traasfer a mixed tower of size 21, the pair of disks n must be
moved to the target peg wbiie stül maintahhg their colour order. To
maintain the order it is required to nnt move the top ring of the pair to the
spare peg, then move the bottom ring to the target peg and, finally, move
the ring on the spare peg to the target peg, on top of the other ring (any
other sequence to move two rings maintaining the colour order would
require more t h 3 moves and, therdore, it would not be minimal).
According to the des, they uumot k piaced on top of a tower wntainiog
any of disks 1,2, ..., n-1; hence, these m o t be on the spare peg for the
top disk to move. So, nrSt the top ~1 pain of disks are moved to the
target peg in T(2,n-1) moves. Then, the top disk n of the bottom pair is
moved to the spare peg using one more move. Then, the rnixed tower of
![Page 29: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/29.jpg)
site Z(n-1) onthe target peg is traasfarrd to the spare peg in orda to
move the bottom disk n to the target peg. This is dow in T(2,n-1) moves.
It takes another move to tmd& the bottom di& n to the target peg. 0
Then it is requïred to move again the top n-1 pairs ofduLs fom the spare
peg to the original-peg in orda to m e the top di& n to the target peg;
& takes T(2,n-1) moves. Another niove is requmd to tranifa the top
disk n to the target peg. F e , the mixed tower of size 2(n-1)
original peg is transferred to the target peg in T(2,n-1) moves.
establisha the recurrencec
on the
This
Note that the colour order of the top n-1 pairs is pceserved since they were
trderred four times.
CoroUary 3.2.5: T(2,n) = 2*'-5, for al l n à 1.
From Proposition 3 -2.3, T(2,n) = 2(2*-1).
Substituthg T(2,n) = 4T(2p-1)+3 (fiom Lemma 3 -2.4) Ieads to
T(2,n) = 2w2-5.
Ta sohre the CTM problems with two towas, it is fint neassary to define three
other hctioos. Let M0(2,n) be the minimum number of moves reqwred to merge a c,
tower and a c, tower into a mixed tower of size Zn, with the correct colour order for the
top n-l pairs of disks and inverthg it for the last pair, on Peg O, Mi(Z,n) be the minimum
number of moves to merge thern with that colour order on Peg 1, ad W2(2,n) be the
mioimum number ofmoves to merge them with that colour order on Peg 2.
It is necessary to anaiyse some relaiionships between these aad &(2,n), Mi(2,n),
and M2(2,n).
![Page 30: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/30.jpg)
Lemma 32-6: For d n 2 O, W(2p) = WL(2,n)
Pmfi To obtain h&(2,n) it is requind to have the Q &k n at the bottom of
Peg O to have the bottom pair in correct d o u r orda. Since the c,, disk n
is already there, it is just necessary movt the top m-1 ç, disks anci the top
n-1 cl dislts nom their Rspective pegj to Peg 2, which wiü aiiow us to
move the cl dUk n on Peg 1 to Peg O on top of the c,, disk n. To have a
legal mafiguration, it is necessary to-merge a c,, tower of size n-1 and a c,
tower of size n-1 into a mixed tower of size 2(n-1) on Peg 2 using the
minimum nwber of moves. In the ssme way, to obtain M1(2,n) it is
necessary to have the c, disk n at the bottom of Peg 1 to have the bottom
pair in inverted colour order. But this U already in place so it is necessazy
to move the top n-1 co disks and the top n-1 c, dUks Born their respective
pegs to Peg 2, which wiîi allow w to move the c,, disk n on Peg O to Peg 1
on top of the cl disk n Hence, it is required to merge a cl tower of size n-
1 and a c,, tower of size n-1 iato a &ced tower of size 2(n-1) on Peg 2
using the minimum number of moves; which clearly shows that
&(Zn) = M.'1(2,n).
Lemma 3-2-7: For aii n 2 O, Ml(2/i) = Wo(2,n)
Proot: This is similu to the last proof, hence it is omitted.
Lemnu 3-2.8: For ail n 2 2, $(2,n) = M!l(2,ml)+T(2,n-1)+T(2,n-1)+2, with
M&2,0) = O and 4(2,1) = 2.
Pro& To prove the initial conditions, for n = O it is trivial since no moves are
required to mage empty towers. For n = 1, the c, disk has to be
trderred fiom Peg O to Peg 2 and then the c, disk fiom Peg 1 to Peg 2.
This takes 2 moves. For n 2 2, to obtain A4(2,n) it is nexessary to move
the c, disk n to Peg 2 to have the bottom pair in comct cdour order;
hence, it is required to merge the top n-l ç, disks and the top n-1 c, disks
![Page 31: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/31.jpg)
into a niixed tower of size 2(n-1) on Peg 1 using the minimum wmber of
moves. To have the mini'mm number of moves, the r d - mOred
tower of size 2(n-1) on Peg 1 wiii have imrcrted colaur order for the pair
n-1, i.e, it would take h&(2~-1) moves (tbis has to be part of s'minimal sequence for otherwise the c, di& PZ-1 hs to be moved, incce8sing the
number of moves). Then it takes one move to traasfer the c, ring n i?om
Peg O to Peg 2. It is necess~ry to transfi in the minimum mimber of
moves the top mixed tower of size 2(n-1) with inverted colour order for
pair n-l nom Peg 1 to Peg O to dow the c, disk n to be transfecfed to
Peg 2. This wiU take T(2,n-1) moves and wül give a mixeci tower of N e
2(n-1) on Peg O with correct cdour order for ali the rings. Take then one
more move to traiisfer the cl disk n to Peg 2 on top of the c, disk n.
F i d y , transfer in the minimum number of inoves the mixeci tower of sue
2(n-1) on Peg O to Peg 2, mru'ntainiug the wlour order (othhse a tower
with the correct colour order for all the rings wouid not be obtained).
This wiii take T(2,n-1) moves r(2,n-1) would invert the colour order
of the pair n-1). This stnitegy is shown graphically in Figure 12.
Note that ifT(2,n-1) was used where T(2,n-1) was, then T(2,n-1) would
have to be used at the end, othennrise, it could not have the correct colour
order for ali the pairs (specirically for pair ml). In either case the total
number of moves is the same.
![Page 32: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/32.jpg)
with M2(2,0) = O and W2(2, 1) = 2.
Proofi As in Lemma 3.2.8, it is hivial to prove it for n = O since no moves
. are required to merge empty towas. For n = 1, &er the c1 disk fiom
Peg 1 to Peg 2 and then the c, disk h m Peg O to Peg 2. This takes 2
moves. For nS, to obtain M2(2,n) it is necessary to move the c, disk n to
Peg 2 to have the bottom pair in inverted colour ordeq hence, merge the
top n-1 co disks and the top n-1 cl disks into a mked tower of size 2(n-1)
on Peg O using the minimum nmber of moves. To have the minimum
number of moves, the resdting mixed tower of size 2(n-1) on Peg O wiil
have the correct colour order for al1 the pairs, Le., it would take &(2,n-1)
moves (this has to be part of a midmal sequence for othefwise the c, disk
n-l has to be moved, increasing the number of moves). Mer that, it takes
one move to d e r the cl h g n fiom Peg 1 to Peg 2. Then, trader in
the minimum number of rnoves the top mixed tower of s k 2(n-1) fiom
Peg O to Peg 1 to d o w the q, disk n to be transfemed to Peg 2. This wiil
take T(2,n-1) moves and will giw a mked tower of size 2(n-1) with pair
n-1 in inverted colour order on Peg 1. It takes take then one more move
to trader the c, disk n to Peg 2 on top of the c, disk n. Finally, W e r
![Page 33: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/33.jpg)
the mixed tower of size 2(n-1) on Peg 1 inverthg the c01our order of pair
n-l in the mmimum number ofwnns to Peg 2, to obcain the correct colour
order (othe*se a mked tower of size 2n with aîî pairs in c o m a coiouf
orda wouid not be obtamed). This wül take T(2,n-1) moves.* ïb is
stra;tegy is shown in Figue 13.
8
Proposition 3.2.10: For al1 n 2 2, &(2,n) = Mi(2,n)+2"-3
ProoC: By Lemmas 3.2.8 and 3.2.9,
W(2,n) = M' (2,n-1)+T(2,n-l)tT(2,n-1)+2 and
M2(n) = W(2,n-l)+ 2T(2,n-1)+2.
=hiTl foralln, byLcama3.2.6. Hence,
&(2,n) = Mo(2pl)+ T(2,n-1) +T(2,n-1)+2
= Af2(2,n)-T(2,n- l)+T(2,n01).
By Proposition 3.2.3 and CoroUary 3.2.5,
T(2,n) = 2(Zn-1) and T(2,n) = 2n+2-5, for di n à 1.
Hence,
U,(2~z) = M2(2,n)- 2(2'C1-l)+ 2*'4
Therefore, for ail n 2 2, W(2,n) = W2(2,n)+2"-3.
![Page 34: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/34.jpg)
Lemma 3e2.11: For d n > 2, &(2,4 = M2(2,n-l)+T'(2/r-4)cl with w2.0) = O
and W(2,I) = 1.
Proofi As above, the initiai condition for n = O is trivkd since no moves are
reqwted to merge empty towers. For n = 1, it is just necessary to 'transfier
the c, dkk fkom Peg 1 to Peg O, on top ofthe q, disk This takes only one
move. For n r 2, in order to merge a C-tower of size n on Peg O and a cl
tower of size n on Peg 2 hto a mixed tower of size 2n with ali pairs in
correct colour order on Peg O, remove the top n-1 disks fiom both towers
and merge them on Peg 2. This is so the c, disk n on Peg 1 can be moved
to Peg O on top of the c, disk n. At this point, it does not matter if the
merge of the towers is into a mixed tower of size 2(n-1) with the colour
order of the bottom pair correct or inverted. However, it is necessary to
choose the colour order inverted for minimafity purposes since
W2(2,n) < w(2,n). Hence, it takes M'2(2,n-l) moves to do the merge.
Then, it takes one more move to eansfer the c, disk n fiom Peg 1 to Peg O.
F i y , transfer the mked tower of sue n-1 with imrerted colour order for
pair n-l fkom Peg 2 to Peg 0, inverting the colour order of the pair n-1 to
obtain a mixed tower of s k 2n with correct wlour order for ali pairs.
This will take T(2,ml) moves. nie strategy is shown in Figure 14.
Figure 14. Strategy to obtain MJ2,n).
![Page 35: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/35.jpg)
and W2(2, 1) = 2.
Pmofi From Lemma 3 .Z.9, for all n 2 2, M2(2,n) = &(2,n-i)+2T(2,n-1)+2, *
with M2(2,0) = O and MI2(, 1) = 2.
By Proposition 3.2.3, T(2,n) = 2(2*-1). for aII n r 1.
Hence, W2(2,n) = N(2,n-1)+ 4 ( 2 ' % ~ .
a d M2(2, 1) = 2-
Corollary 3.2.12: For ali n r 3, &(2,n) = ~0(2,n-2)+2*'-3, with &(2,0) = 0,
Proof: Using Lemmas 3 2-10 and Propositions 3.2.3 and 3.2.1 1,
for ai i n 2 2, N(2,n) = M!2(2,n-1)+T'(2,n-1)+l with &(2,0) = O and
Ma(2,i) = 1 7
W2(2,n) = &(2,n-i)+2*'-2, with M1(2,0) = O and M2(2, 1) = 2, and,
for aU n r 1, T(2,n) = 2(2*-1). Hence, &(2,2) = 2+2+1= 5.
Substitutbg, h&(2,n) = &(2,n-2)+ 2"-2+2(2*'-1)+1, for I n 2 3.
nierefore, for aii 11 2 3, &(2,n) = &(2,n-2)+2"+'-3, with N(2,O) = O,
&(Z7 1) = 1 and a(2,2) = 5.
Proposition 3.2.13: N(2,n) = -(1114)+(1/12)(-l)n+(8/3)2n-(3i2)n, for al1 n r O.
Proofi From Corollary 3.2.12, for ail n r 3, &(2,n+2) = &(2,n)+2"%, with
&(&O) = O, &(2,1) = 1 and w2,2) = 5. So the solution will be of the
fom e ( 2 , k ) = a(-l)k+b+~f+dib, where c and d are r d constants that
depend on the terrns 2%, and a and b are real constants depeading on
the initia1 conditions. Omitthg the terms a(-l)C+b as to simplify
Substituting hto the non-homogeneous recurrence:
![Page 36: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/36.jpg)
Hence, 8 =-u-(8/3). Foiiows theta= 1/12 ead b=-(1114).
Therefore, &(2,n) = ((1/12)(-l)"-(1 I/4)+(8/3)2''-(3/2)n. for aii n 2 O.
Further details on the solution of remmence relations are &en in L
Appendix A.
C o d u p 3m2.14: M'fin) = -(i314~i/12~-l~+C10n)2n-(3/2~, for di n z 1,
n&(2,0) = o. Pmofi From Propositions 3 -2.1 1 and 3 2-13, for al1 n 2 2,
M2(2,t1) = ~(2,n-n-1)+2*'-2, with M2(2,0) = O and M1(2, 1) = 2, and,
for al1 n 2 O, &(2,r1) = (1/12)(-1)"-(11/4)+(8/3)2'-(3/2)n.
Substituthg M,,(2,n-1) in W2(2,n),
M2(2,n) = (111 2)(-1)*L-(11/4)+(8/3)2*1-(3/2)(n- 1) +2"+'-2.
Hence, sbplifying, W2(2,n) = -(13/4)-(l/12)(-l)"+(10/3)2n-(3/2)n, for aii
n r 1, M2(2,0) = 0.
Coroihry 3.2.15: U,(2,n) = -(25/4)-(l112)(-l~~13B)2n-(3/2~, for ali n 2 2,
&(2,0) = O and $(2, 1) = 2.
Pro& From Proposition 3 -2.10 and CoroUary 3 2.14, for ail n 2 2,
3(2,n) = M2(2,n)+Zn-3 and,
for aü n r 1, M2(2,n) = -( 1 3/4)-(1/12)(- 1)- 1 0B)2n-(3/2)n.
Substituthg, M&n) = -(13/4)-(l/l2)(-1)~'+(1013)2*~-(3/2)(n-l) +Zn-3.
Hence, simpüfying,
W(2,n) = =((25/4)-(1/12)(-l)*ql 3/3)2n-(3/2)n, for aii n 2 2, &(2,0) = O
and &(2,1) = 2.
![Page 37: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/37.jpg)
Lemma 3.2.16: For di n r 2, M,(2,n) = ~(2p-l)c2T'(2,n-l)+ T(2,n-1)+3 with
M,(2,0) = O and Ml(2, 1) = 3.
Proof= As in Lemma 3.2.8, the imtial condition for n = O is trivial since no
moves are required to mage empty towers. For n = 1, it is nece'ssary to
tramfier the c, disk fiom Peg O to Peg 1, so nnt transfer the cl disk ftom
Peg 1 to Peg 2. Then trarufer the c, di& fiom Peg O to Peg 1 and, W y ,
traasfw the cl disk nom Peg 2 to Peg 1 on top ofthe c, disic and this takes
3 moves. For n r 2, in order to merge a q, tower ofsize n on Peg O and a . ci tower of size n on Peg 2 into a &ed tower of sh 2n with aü pairs in
correct colour order on Peg 1, it is reguired to traasfer the ç, disk n to
Peg 1. To do this, first remove the top n-1 c, duh âom Peg O and the
entire c, tower nom Peg 1 and merge them on Peg 2. So, start by
merging the top n-l disks fkom both towers on Peg O, which wiii take
W(2,n-1) moves (this has to be part of a miaimal sequence for otherwise
the c, disk n-1 has to be moved, inaeasing the number of moves). This is
such so the c, disk n on Peg 1 «ui be transferred to Peg 2, which takes one
move. Then, naosfer the top mixed tower of size Zn-1 to Peg 2, inverting
the colour order of pair IZ-1 (since T(2p) < T(Z,n)), which takes T(2,n-1)
moves. It takes one more move to traosfêr the c,, disk n ftom Peg O to
Peg 1. Transfer the top mked tower of size 2(n-1) with pair n-1 in
inverted colour order nom Peg 2 to Peg O. It takes T(2,n-1) moves and
retums the mixeci tower to the correct colour order for aii the pairs. Then,
make one more move to t r d e r the c, disk n fiom Peg 2 to Peg 1.
F i y , traader the mixed tower of size
2(n-1) fiom Peg O to Peg 1. Since the correct colour order is required for
all the pain, it wiU take T(2,n-1) moves.
The strategy is show in Figure 15.
![Page 38: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/38.jpg)
- -
Pire 15. Stmtegy to obtain M1(2,n).
Coroilary 3.2m17: M,(Z,n) = -(29/4~1/12X-1)n~16B)2R<3/2)nl for d n 2 2,
M,(2,0) = O and M,(2,1) = 3. .
Proof: From Lemma 3 -2.16 and Proposition 3 -2.13,
M,(2,n) = h&(2,n-1)+2T'(2,n-I)+ T(2p1)+3, for di n r 2,
with M,(2,0) = O and M1(2,,J) = 3, and,
W(2,n) = -(1 114)+(1112)(-l)n+(8/3)2n-(3/2)n, for di n n O.
By Proposition 3 2 . 3 and CoroIlary 3 .Z.5,
T1(2,n) = 2(2'-1) and T(2,n) = 2*2-5, for ali n 2 1.
Substituting,
M,(2,n) = -( 1 U4)+(1/12)(- 1)"~+(8/3)2~~-(3/2)(n- 1) +4(2*'- i)+2"'5+3.
Hence, simpLifying,
M,(2,n) = -(29/4)-(1112)(-1)"+(16/3)2n-(3/2)n, for dl n r 2, M1(2,0) = O
and M,(2,l) = 3.
Coroiiaq 3.2.18: For aii n 2 2, N(2,n) 6 W2(2,n) s W(2,n) s M,(2,n).
Proof: By Proposition 3 -2.13 and Coroflaries 3.2.14,3 2.15, and 3.2.17:
M&,n) = -(1 1/4)y1/12K-l)n~)2n-(3/2~, for ai i n 2 û,
M1(2,n) = -(13/4)-(1/12)(- l)n+(10/3)2n-(3/2)n, for ail n r 1, M2(2,0) = 0,
M42,n) = -(~5/4)-(1112)(-l)"+(I3/3)2~-(3/2)n, for al1 n n 2, 5 ( 2 , 0 ) = O
and W(2,l) = 2, ad,
![Page 39: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/39.jpg)
M,(2,n) = -(29/4Hll12)(-l)n+(16/3)2n<3/2)n, for l n 2 2, M,(2,0) = 0
and M1(2, 1) = 3.
From these it can be c k d y seen that, for d n 2 2,
Finally Ï t is necessary to prove that the given solutions to the CTM problerns with
two towers are optimaL A solution to this problan is optimal when it requins no more
steps than any other possible solution obtaimd f0110wing the CTM problem des .
Define OMJi) as an optimal solution to & CTM problem with two towers on
peg x, where xe (0,1,2)and n is the wmber of disks in each tower.
Lemma 3.2.19: For n à 2, any soiution to the CINI problem with two towers on
Peg O which transfers a mixed tower of size 2(n-1) fiom one peg to
another more than once c a ~ o t be optimal.
ProoE By way of contradictioq let b ( n ) be an optimal solution to the CTM
problem with two towers on Peg O which tfansfers a mixed tower of size
2(n-1) fiom one peg to mother more than once. It can be observed that,
in addition to callUig T(2,n-l), which is the optimal number of rnoves to
W e r a tower of size 2(n-1) nom one peg to another by
Proposition 3 3.3, at least twice, it must cal1 a mage A&(2,n-l), where
x E (0,1,2), at least once since it is r@ed to remove ail the top n-1 c,,
disks on Peg O and the top n-1 c, disks on Peg 1 in order to transfer the c,
disk n ftom Peg 1 to Peg O, to be on top of the ç, disk n.
By Proposition 3.2.3, T(2,n-1) = 2(2*1-1).
By the de£initions of M,,(Z,r) and W'(2,n), for aii y E (O, 1,2),
Coroiiary 3 2-18 and Proposiiion 3.2.13, yX2,n-1) must be at least
&2,n-l) 2 h4(2,n-1) = -(11/4)t(l/l2)(-1~~~8/3)2~'-(3/2)(n- 1)
= -(5/4)-(i 11 2)(- l)n+(4/3)2n-(3 /ZN.
![Page 40: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/40.jpg)
So7 2T(2,n-L)+h4(2,n-1)+1 L 41 7/4)-(1112)(- l)n+(l 0/3)2'-(3/2)n.
Hence, h ( n ) 2 -(17/4)-(111 ZK-L)*+(10/3)2*<3/2)n-
However? b y Proposition 3 2.13, for al! n 2 2,
y ( 2 ~ 1 ) = -CI 1/4)+(1112g~)~y8n)z~<3/2*
W e obsem that, for aU n r 2,
-(i7/4)-(il12)(-L)nYI 0/3)2"-(3/2)n > -(1 lM)Y Y12X-1 r+(8/3)%(3/2)n.
Hence, for aU n 2 2, A&n) > &(2,n), which contradicts the assumetion of
&(n) being optimal.
Therefore, for n t 2, any solution to the CTM problem with two towers on
Peg O which tranders a mixeci tower of size 2(n-1) h m one peg to another
more than once carmot be optimal.
Proposition 3.2.20: For aii n 2 0, li&(z7n) is the optimal solution to the CTM
problem with two towers on Peg O.
proof: By Lemma 32-19, the optimal solution to the CTM problem with two
towers on Peg 0, O&(@, must transfer a mixeci tower of size 2(n-1) nom
one peg to another at most once in orda to be opthai.
R e d that the objective of the CTM problem with two towers on Peg O is
to merge a c, tower of size n initidiy on Peg O and a c, tower of site n
initiaiiy on Peg 1 into a mixed tower of size 2n with the correct colour
order (cl disk on top of the Ç, disk of the same size) for ail pairs on Peg O,
using Peg 2 as an auxhry empty peg. Since the disk n is already on
Peg O? it is required to move the cl disk n ftom Peg 1 to Peg O. To do
this, remove the top n-1 c, disks fiom Peg O and the top n-1 c, disks from
Peg 1 and merge them into a mixed tower of size 2(n-1) on Peg 2. There
are three possible ways to do this: (a) merge them into a mked tower of
sue 2(n-1) on Peg O and then transfer this mixed tower to Peg 2, (b) merge
them into a mixed tower of size 2(n-1) on Peg 1 and then transfer this
![Page 41: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/41.jpg)
mixed tower to Peg 2, or (c) mage them h o a mixed tower of size 2(n-1)
on Peg 2. Once we have mer@ the top n-1 cl and ml c, disks on Peg 2
and traasfened the c, di& n h m Peg 1 to Peg O, traasfkr the mixed tower
of size 2(n-1) ikom Peg 2 to Peg O in such a wry that a mixed towk of size
2n with the correct colour order for d p h on Peg O is obtained. Since
for thïs last part it is required to transfet a mixed tower of size 2(n-1) once,
by Lemma 33.19, t eliminates the merge options (a) and (b), l e h g
option (c) as the ody possibiby to obtain an optimal solution Now, by
dennition, W(2,n-1) and W2(2,n-1) are the two options to merge on Peg 2
a c, tower of size n-1 and a c, tower of size n-1 in the least mmber of
steps. IfW(2,n-1) is chosea as the merge, we must use T(2,n-1) as the
transfer to obtain a mixed tower of size 2n with the correct colour order
for ali pairs. In the other hancl, if M2(2,n-1) is chosen as the merge,
T(2,n-1) must be used as the W e r to obtain a k e d tower of sïze Zn
with the correct colour order for aii pairs.
By Proposition 3.2.3 and Cotoliaries 3 2S,3 -2.14, and 3 -2.15,
3(2,n)+T(2,n) = <45/4H1/12~1M25/3)2n-(3/2)n, for al1 n 2 2,
w(2,l)cT(2,1) = 5, and nZ,(Z,O)+T(Z,O) = O.
M2(2,n)+T(2,n) = -(2 l/4)-(l/l2)(-l 6/3)Zn-(3/2)n, for aU n 2 1,
M'2(2,0)e'r(2,0) = o. Hence, for aIi n 2 0, W2(2,t1)+T(2,n) s &(2,n)+T(2,n).
Since the minimai solution is rquired, use MZ(2,n-1) as the merge on
Peg 2 and T(2,n-1) as the W e r from Peg 2 to Peg O.
Therefore, for dl n 2 1,
O&(n) = M2(2,n-1 )+T(2,n-1)+ 1 = -(1 l/4)+(1/12)(- lMS/3)2n-(3/2)n,
OW(0) = O.
By Proposition 3.2.13,
![Page 42: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/42.jpg)
W(2,n) = - 1 1/4)+(1/12X-l~)2n<3/2)n = O, for all n 2 O.
Therefore, for aii n 2 O, M&2,12) is the optmial soiution ta the CTM
probiem with two towen on Peg O. -
Lemma 3.2.21: For n b 2, any solution to the CTM problem with two towen on
Peg 2 which trangfii a mixed t o m of size 2(n-1) fiorn one peg to
another more than twice canuot be o p W .
Proof: By way of contradiction, assuxne 4(n) be an optimal solution to the
CTM problem with two towers on Peg 2 which transfers a &ed tower
of size 2(n-1) ficm one peg to another more tban twice. It can be
observeci thaî, A,(n) in addiion to a i h g T(2pl), optimal solution to
tmosfer a mixed tower of size 2(n-1) Born one peg to another by
Proposition 3 -2.3, at least t h e times, it must call a mage q(2 ,n- l ) ,
where x E {0,1.2), at lem once since it is necessaxy to remove aii the top
n-l c, disks oa Peg O and merge them with the top n-1 c, disks on Peg 1 in
order to transfer the c, disk n fiom Peg O to the empty Peg 2 in one move.
Then it is newssary to tramfier the mixeci tower of size 2(n-1) to Peg O,
using one of the T(2,n-lys, in order to transfer the c, disk n fiom Peg 1 to
Peg 2 on top of the c, disk n in one move. By Proposition 3.2.3,
T(2,n-1) = 2(2-'-1).
By the definitions of W2,n) and W,,(2,n), for aii y E (0,1,2},
CoroUary 3 2-18 and Proposition 3.2.13, %(2,n-1) must be at least
MJ2,n- 1) 2 q(2,n-1) = 41 114~1/12~-1)*'~~13)2*~-(3/2~n- 1)
= -(S/4>(l/12~-l)R+(4/3)2n-(3/Z)fi
3 OT(n-l)+W2,n- 1)+2 à -(5/4)=(l/lZ)(-l)"+( 1 3/3)2"-(312)n.
Hence, 4(n) t -(5/4)-(1/12)(- l)"+(13/3)2"-(3-
However, by Coroiiary 32.15, for d n 2 2,
y ( 2 , n ) = -(25/4)-(l/ 1 2)(-1)n+(1 3/3)2@-(3/2)n
![Page 43: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/43.jpg)
-(S/4)-(iA2)(-l)*+(i3/3)2*-<3/2)n > =(25/+(l/lZ)(- 1)"- 1 3M)Zn-(3/2)n.
Hence, for aii n r 2,4(n) > M&2,n) which contradicts the assumption of
4(n) being optimal.
Therâoce. for n 2 2, any soiution to the CTM problem with two towers on
Peg 2 which Unrokes T(2,n-1) more than twice cannot be optimal.
Proposition 3.2.22: For all n r O, U,(2,n) is the optmnil solutioa to the CTM
problem with two towers on Peg 2.
By Lemma 3.2.21, the optimal solution to the CTM problern with two
towers on Peg 2,OU,(n), musi transfer a mked tower of s i n 2(n-1) fiom
one peg to another at most twice in order to be o p W .
It is necessary to transfer the c, disk n ftom Peg O to Peg 2. To do tbis
remove the top n- l co disks f?om Peg O and merge than with the top n- 1 c,
disks on Peg 1 since Peg 2 is required to be empty. There an three
possible ways to do this: (a) merge them hto a mked tower of size 2(n-1)
on Peg O and then aansfer this mixed tower to Peg 1, @) merge them into
a mixeci tower of size 2(n-1) on Peg 2 and then t r d e r this mixed tower to
Peg 1, or (c) rnerge them into a mixai tower of size 2(n-1) on Peg 1.
Once we have merged the top n-1 c, and n-1 c, diiks on Peg 1 and
tranderred the c, disk n nom Peg O to Peg 2. M e r the rnixed tower of
size 2(n-1) fiom Peg 1 to Peg O since it is required to move the c, disk it
fkom Peg 1 to Peg 2, on top of the 6 disk n alnady there. Once we have
transferred the cl disk n fkom Peg 1 to Peg 2, trader the mixeci tower of
size 2(n-1) fiom Peg O to Peg 2 in such a way that aü the pain have the
correct colour order. S k for this last part it is required to transfer a
mixed tower of size Z(n-1) twice, by Lemma 3.2.21, it efiminates the merge
options (a) and O>), leaving option (c) as the only possibiüty to obtain an
optimal solution. By definition, M,(Z,n-1) and hiP,(2,n-1) are the two
![Page 44: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/44.jpg)
options to mage on Peg 1 a c, tower of size n-1 and a c, tower of size n-l
in the least aimber of steps. IfM1(2pl) U chosen ar the merge, there are
two possible combiions of transfers in order to keep the colour order:
(i) 2T(Z,n-l) = 2*2-10, or
c i 2T(2,n-I) = Zml4.
For ail n 2 2, 2T(2,n-1) > 2T(2*1), hena choose option Ç i as the
transfer combination to obtain a mixed tower of size 2n with the correct
colour order for ail pairs in the lem number of moves. In the other hand, 8
ifM1(2,n-1) is chosen as the merge, use T(2,n-I)+T(Z,n-l) as the transfer
combination to obtain a mixed tower of size 2n with the correct colour
order forall pairs.
By Proposition 3 -2.3 and Coroîiary 3.2.17,
ML(2,n)+2T(2,n) = -(45/4)-(1112X-l~28/3)Zn<3/2)n, for ail n r 2,
M1(2, 1 )+2T(2,I) = 7, and M,(2,0)+2T(2,0) = 0.
By Proposition 3.2.3, Corollary 3.2.5, Lemmui 3.2.6 and
Proposition 3 -2.13, Ml(2,n) = &(2,n).
M! ,(2,n)+T(2,n)+T(2,n) = 43 9/4)+(l/l2)(- lM26/3)2n-(3/2)n, for al l
rt z 1, M1(2,0)+T'(2,O)+T(2,0) = O.
Hence, for a l l n 2 0, M',(2,n)+T(2,n)+T(2p) s MI(2,n)+2T'(2,n).
Since the minimal solution is requked, use M,(2yn-l) as the merge on
Peg 1 and T(2,n-l)+T(2,n-1) as the t r d e r cornôidon.
Therefore, for all n 2 2,OM&n) = M',(2,n4)+T(2,mI)+T(2,n- 1)+2
= -(25/4)-(i/l2)' 1 r+( l3/3)2~-(3/2)n, Ow(1 md OU,(O) = O.
B y CoroUary 3 -2.15,
W(2,n) = -(25/4)-(1/12)(-1M l3/'3)2n<3/2)n, for aii n 2 2, w(2,1)=2 and
n4(2,0) = 0.
Hence, O&(n)=U,(2,n), for ali n 2 0.
![Page 45: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/45.jpg)
Therefore, for ail n L O* &(2,n) n) the optimal dutioa to the CTM
probkm with two towers on Peg 2.
Lemm 32.23: For n 2 2, any solution to tbe CTM pmblem with two towers on
Peg 1 which transfèrs a &ed tower of size Z(n-1) nom oie peg to
aaother more than thme times a m o t be optimsl.
Proofi This is simüar to the proofb of Lemmas 3 2-19 and 3.231, hence ornitteci.
Proposition 32.24: For I n r O, M,(2,n) is the optimal soldon to the CTM
problem wii two towas on Peg 1.
Proofi This is similar to the proofk of Lemmas 35.20 and 3.2.22, hence omitted.
Therefore, by Lemmas 3.2.20, 3222 and 3.2.24, the op- solutions to the
CTM problem with two towers are:
G(2,n) = 4 1 1f4~1/12)(-l)ny%n)2n<3/2)n9 for aîi n 2 0, for the rnerge
on Peg 0,
M,(2,n) = -(29/4)-(1/12)(-1)n+(16/3)2n-(3/2)n, for aii n 2 5 M,(2,0) = O
and M,(2,I) = 3, for the merge on Peg 1, and,
h4(2,n) = -(25/4)-(lfl2)(-l)*+(l3/3)2'1(3/2)n, for aü n 2 2, &(2,0) = O
and &(2, 1 ) = 2, for the merge on Peg 2.
From these resdts it can be o b m e d that the Ieast number of rnoves occur when
the merge is done on the peg where the dîsks of colour c, were initially, the second best
resdts occur when the merge is done on the empty peg and the most moves occur when
the merge is done on the peg where the disks ofcolour c, were initidy.
![Page 46: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/46.jpg)
Now, a m*ation to the CTM proMem wül be anaiysed. The Tbrce Coloured
Towers Merge (TCTM) problem is quite simünr to the CTM problern with thrœ towers,
with the exception that the TCLU pmblem takes piace on a board with three pegs, not
four. As initial configuration for the TCTM pmblem, thae is a towa of size n with
colour Q on Peg O, a tower of size n with colour cl on h g 1, and another tower of size n
with colour Q on Peg 2. The disks of ail the to- are equal (same n dinerent
diameters), except for their colour.
The objective of the TCTM probiem is to merge, using the following des, ail the
disks into a mixed tower of size 3n with the correct colour order for di trios. The des
are:
1. Ody one disk at a time may be moved;
2. Oniy the top disk in a tower may be moved;
3. A disk may only be placed on top of a disk of equd or larger diameter,
regardless of colour;
4. The towers are to be merged in a cninhum number of moves.
Define a legui configtafrun as any arrangement of disks on the three pegs
obtaiaed by repeatedly applyiag des 1 through 3.
As it can easiiy be observeci, this problem, in fact, poses three different problems
accorduig to whether the merge is dom on Peg 0, 1, or 2. The initiai and £inal
configuration for the TCTM problem on Peg 2 are shom in Figure 16.
![Page 47: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/47.jpg)
Fi y re l a Initial and nnal configuration on Peg 2 for the TCTM problem.
in order to explain this problem better, sow pemnttation group notation bas to be
defïned.
Let S' denote the set of aü one-to-one bctions fiom the set of colours (G, cl, Q}
to itself. S, = {~,~,qza,~>zo*) and its elements are defineci as:
where the order [c, c, CJ meam that the ring coloured c, is at the bottom of the ring trio,
the one coloured cl in the middle knd the one coloured c, at the top. This is show
graphicdy in Figure 17.
Figure 17. AN possible elemnts of&.
![Page 48: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/48.jpg)
The elements of S3 give aü the possible colour orders of a tno, where & is the
correct coiour order and m2 is the inverteci colour order. 4 is a non-abelian group, i-r.
non-commutatives of six elements d e r fhctioa composition, usually d e d the
symmebic group on &ee eiemenis, and the notation is the standard for ttiis group:
Now, defhe the Wction Tm to be the niinimum numba of moves needed to
transfer a mixed tower of sue 3n nom one peg to a legai configuration on another peg.
Lemma 4.0.1: The hction T' satisfies the recurrence relation
T(n) = 2T(n-1)+3 , for all n r 1.
Proof: In order to traoder a mixed tower of size 3n, the trio of disks n m u t move
to the destiaation peg. According to the dess they cannot be placed on
top of a tower containhg any of dida 1,2, ... , n-1; hence, these cannot be
on the destination peg. So first move the n-1 trios to the spare peg in
T(n-1) moves. Then, move the remahhg trio to the destination peg using
another 3 moves, inverting the colour order (this must be part of a minimal
sequence for otherwise at Least one of the di& of the bottom trio wiü be
moved twice). F d y , &er the mUred tower of size 301-1) on the
spare peg to the destination peg in T(n-1) moves. This establishes the
recurrence. This strategy is shown in Figure 18.
Figure 18. Strategy to obtain T(n) for the TCTM problem.
The initial condition T(O)=O is added to solve the recurrence relation. This bas a
physicai meaning since no moves are required to move and empty tower; and it is also
consistent with the recurrence.
![Page 49: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/49.jpg)
C o r o b y 4.0.2: For aii n r 1, the hction T'(a when applied to a d c e d tower
ofsite3n,wJLgiveasdtamaedtowaofSze3nmaimauua . - 1
g
the colour order of the top n-1 trios and applyhg the fûuction id
to the nh trio, Le., ifthe orÏgiiurl colouf orda W b
[Q ci QI then the finai colour order wül be [Q cl QI. Pro& This wül be proved by induction on n.
Let n = 1. T(1) = 2T(0)+3 = 3 by Lemma 4.0.1. To trander a mDred
tower of size 1 to another peg in the least nuinber of moves, move the top
disk to the destination peg ami then the middle disk and fiaally the bottom
disk to the destination peg. This gins a mixed tower of size 3 inverthg
the originai colour order in 3 m m . Any other legal conf~gwation wouid
be obtained ushg more moves. Hence, it is tme for n = 1.
Induction hpothesis. Suppose it is me that, for ail n a k, T(n), when
applied to a mixeci tower of size 3n, will give as resuit a mked tower of
size 3n preserving the origiaal colour order for dl the top n-1 trios and
inverting it for the bottom trio n.
Now prove it for n = h l . Suppose there is a mixed tower of size f i l .
Applyiag T'(fil), by Lemma 4.0.1, T'(hl) = 2T(k)c3. Physidy, this
means that it is fint necessary to transfer the top k trios to the spare peg.
By hypothesis, the first iraasfer of the top k trios wül result i ao a mixed
tower of size k with the colour order of the bottom trio k inverted on the
spare peg since, to obtain the least number of moves, by definition, use
T(k). Then, transfer the bottom trio to the destination peg. This will take
3 rnoves and obtain a mixed tower of size 3 with the colour order inverted
on the destination peg, as shown above. Finally, transfer the mixeci tower
of size k to the destination peg by using TV(k). By hypothesis, the colour
order of the top k trios wiil be the retumed to the original one since the
![Page 50: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/50.jpg)
colour order the bottom trio wül be imrerted, giving as a resuit a niixed
tower of size &1 with the origiaal coiouf order for the top t trios and
inverteci colour order fbr the f l trio. Hence, the coroihuy is true for all
n z l .
Propasitiott 4.0.3: T(n) = 3(2n-1), for ail n r 1. Furthermore, T(R) n) the
optimal solution to transfkr a mixed tower of size 3n fiom one peg
to another,
PmoE From Lemma 4.0.1., T(n) = 2T(n-1)+3. Consider the initial condition
T(O)=û. So there d l be a solution of the form T(n) = d f b , where r is
the root of the characteristic equatioa, 6 is a constant depending on the
independent term 3 of the onginai fhction, and a is a constant depending
on the initial condition.
In this case r = 2. For simplicity, ignore the term m" and let T(n) = b and
T9(n-1) = b. Substituting, b = 2M3. Hence b = 3 . Since T(n) = a2"-3,
T(O)=cr-34. Therefore, a = 3, which leads to T(n) = 3(2'-1). Further
details on the method to sohre recurrence relations are given in
Appendix A
Now, we witl prove that this sotution is optimal. To transfer a mixed
tower of sue 3n we must, at some point, move the trio of disks n at least
once. To do this we require this trio to be alone in the original peg and
one other peg to be empty. nierdore, the smaller n-l trios of disks must
be on the remaining peg. Hence, no otha possible algorithm can do better
than first moving the top PZ-1 trios fiom the original peg to the spare peg
using the optimal strategy, then movhg the top disk n fkom the original peg
to the target peg, then the tniddle disk n fiom the original peg to the target
peg on top of the other disk n an4 finaüy, the bottom disk n fkom the
original peg to the target peg on top of the other two disks n (iiverting the
![Page 51: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/51.jpg)
colour order of the mo). Fdy, we transfer again the top n-1 pain fiom
the spare peg to the target peg, on top of the trio n, ushg the optimal
strate8y. Therdiore, TOT@) deaotes the total aMba of moves used by
the optimal strategy to tranSfkr a &ed t o m of Jize 3n nom one peg to
another, t cm be obaemd that
OT(n) > 20T(n-l)+3. Since OT(0) = O, it follows that OT(n) r 3(2n-1).
Hence, T is optimai-
Now, define the hction T(n) to be the minimum number of moves r d e d to
transfer a mixed tower ofsize 3n fiom one peg to a legal configuration on another peg,
maintaining the original colour order for al l the di& trios.
It is worth noting that the initial configuration ofthe TCTM problem is exactiy the
same as the one for the "Tmers of Antwerpenn problem, discussed in Section 2.3.4. In
fact, one of the subalgonthms presented by Miosker in [37j performs the same hnction as
Tt@) and in his Lemma 1 he shows that 3(2"-1) is the least number of moves required,
v e m g Proposition 4.0.3. UnfortunateLy, wne of the other r d t s in [37] can be
applied to this research.
Lemma 4.0.4: The bction T satisfies the relation
T(n) = 4T(n-1)+5, for aU n 2 1.
Prool: In order to transfer a mixed tower of size 3n, the trio of disks n must move
to the destination peg maintainhg their colour order. To maintain the
order, first rnove the top and middle rings of the üio to the spare peg, then
move the bottom h g to the destination peg and, fhaiiy, move the two
rings on the spare peg to the destination peg, on top of the other ring (any
other sequence to move three ~ g s maintaining the colour order would
require more than 5 moves and, therefore, it would not be minimal).
According to the niles, bey cannot be placed on top of a tower cootaining
![Page 52: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/52.jpg)
any of disks 1,2,...,n-1; hence, these cannot be on the spare peg for the top
disk to move. So nrst move the top n-1 trios to the destination peg in
T(R-1) moves. Then move the top disk n of the bottom trio to the spare
peg using one more move. Then, transfkr th mixed towa of si& 3(n-1)
on the destination peg to the *are peg iu orda to move the bottom and
middle disks n to the destination pce. . This is done in T(n-1) moves.
Take another two moves to -et the bottom disk n to the destination
peg and then the midde one aiso to the destination peg. Then it is
required to again move the top n-1 trios of disks f?om the spare peg to the
original peg in order to move the top and middie disks n to the destination
peg; this takes T(n-1) moves. Another two moves are required to move
the middle disk n and then the top disk n to t&e destination peg. F'mdy,
d e r the rnixed tower of size 3(n-1) on the original peg to the
destination peg in T(n-1) moves. This establishes the recurrence. The
strategy is show in Figure 19.
- - - - -
Figure 19. Strategy to obtain T(n) for the TCTM problem.
Note that the colour order of the top n-l trios is pnsmed since they were
transferred four times.
![Page 53: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/53.jpg)
Coroiia y 4.0.5: T(n) = 3(2*')-7, for all n n 1.
Pmofi From Proposition 4-0.3 ., T(n) = 3(*1).
Substitutin8 in T(n) = 4T(n-IFS (eom Lemma 4.0.4.) leads to
T(n) = 3(2*')-7.
Define, for any n E 4, T'rt) to be the minimum number of moves rquired to
t r d e r a mixed tower of size 3n nom one peg to a legai coafiguation on another peg,
maintainhg the colour order of the top n-1 trios and applying the bction n to the n& mo.
By this definition, note that T(n) = T a n ) and T(n) = T=(n).
Lemma 4.0.6: For al1 n r 2, T,(n) = T(n) = 3(2*')-7, TJO) = 0 and T&) = 4.
ProoE For al l n 2 2, in order to transfer a mixed tower of sk 3n, the trio of disks
n must move to the destination peg changing its colour order f b m
[Q cl e] to [cl Q CO]. To do this first move the top and middle rings of
the trio, Q and cl respectively, to the spare peg. According to the niles,
they cmot be placed on top of a tower wntaining any of disks 1,2, .. .,n- 1 ;
hence, these caanot be on the spare peg for the top disk to move. So first
move the top n-1 trios to the destination peg in T(n-1) moves. Then
move the top disk n of the bottom trio to the spare peg and then the middle
one on top of it using two more moves. After that, d m the mixed
tower of size 3(n-1) on the destination peg to the initial peg in order to
move the top and rniddle disks n to the destination peg. This is done in
Tt(n-1) moves. Take another two moves to d e r the middle disk n, cl,
to the destination peg and then the top one, cz, also to the destination peg.
Then it is required to m o n again the top n-1 trios of disks fozm the initial
peg to the spare peg in order to move the bottom disk n to the destination
peg; this takes T'(n-1) moves. Another move is required to move the
bottom disk !i, Q, fiom the kitid peg to the destination peg. Fially,
![Page 54: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/54.jpg)
traaâer the mixed tower of site 3(n-1) on the spare peg to the destination
peg in T(n-1) moves. This establishes the reaimnce. Note that the
colour order of the top ml trios s pfe~enred since bey were transfmed
four thes. These steps mwt k part of an o p W saKs since, otberwise,
the bottom ring n must move more than once and the middle and top rings
n mon tban twice, or the top n-1 trios must be transfened more than four
times.
The above shdws tbat Ta@) = 4T(n-1)+5, for aii n r 2, which is the same
as T(n), by Lemma 4.0.4. Thetefore, for aü n 2 2,
T,(n) = T(n) = 3(2*1)-77 by CoroUary 4.3.5.
Now, for n = O, TJO) = O siaa no moves are requird to transfer an empty
tower. For n=l, TJ1) = 4 since wc: fïrst move the top disk âom the
original peg to the spare peg, then the mÏddle one fiom the onginai peg to
the target peg, then we again move the top disk fiom the spare peg to the
target peg on top of the middle disk and, M y , we move the bottom disk
&m the miguial peg to the target peg on top of the other two. Tbis takes
4 moves.
Lemma 4.0.7: The fiinction T, satisfies the relation
Proof: The objective is to W e r a mixeci towa of size 3n, where the trio of
disks n must be moved to the destination peg changing its colour order
nom [Q CI c2] to [cl a. The proof is similar to the proof of
Lemma 4.0.6, hence it is omitted.
Coroiiary 4.0.8: Tm@) = 3(2"+')-8, for d n r 1, Tm(0) = 0.
Proof: From Proposition 4.0.3, T(n) = 3(2'-1).
Substituthg this in T,(n) = 4T(n-1)M (fiom Lcmma 4.0.7) teads to
Tm@) = 3 (2*')-8.
![Page 55: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/55.jpg)
Lenuua 4.09: The bction T, satisfies the relation
T %(n) = 6T(nD1)+6, for ai i n r 1, T,(O) = 0.
ProoE The objeztbe is to ttansfer a mixed tower of 9ze 3n, where the trio of
disks n must be moved ta the destia8tion peg chmghg its colow order
fiom [Q cl 4 to [ci-, q cl]. The proof Y similar to the proof of
Lemma 4.0.6, hence it is omitted.
Coroüacy 4.0.10: T ,(n) = 9(27-12, for ail n r 1, T,(O) = 0.
Proof: From Proposition 4.0.3 ., T(n) = 3(2"-1).
Substituting this in T@) = 6T(n-l)% (fiom Lemma 4.0.9) lads to
Tc@) = g(2")- 12.
Lemma 4mO.11: The bction T, satisfies the relation
T ,(n) = 4T(n- 1)+T(n- 1 )+4, for aii n r 2, T&) = O and
T,(l) = 4.
Prook The objective is to tramfer a mixeci tower of size 30, where the trio of
disks n must be moved to the destination peg changing its colour order
fiom [c, cl CZ] to [% cl]. The proof is simiiar to the proof of
Lemma 4.0.6, hence it is omitted.
Coroiiary 4.0.12: T,(n) = 9(2")-15, for ail n 2 2, T a ) = O and T,(I) = 4.
Proot: From Proposition 4.0.3 ., T(n) = 3(2'4) and T(n) = 3(2*')-7.
Substituthg these in T d(n) = 4T(n-l)+T(n-l)+4 (fiom Lemma 4.0.1 1)
leads to T,(n) = g(20)- 15.
Coroilary 4.0.13: For ail n 2 2, T(n) s T,(n) s T d n ) = T(n) s T&) s T@).
ProoC: By Proposition 4.0.3 and CoroUaries 4.0.5,4.0.6,4.0.8,4-0.10 md 4.0.12,
T(n) = 3(Zn-l), for all n r O,
T,(n) = 6(2")-8, for ail n 2 1, T,(O) = O,
Ta@) = 6(2n)-7, for aU n 2 2, TJO) = O, TJ1) = 4,
T(n) = 6(2+7, for aU n 2 1, T(0) = 0,
![Page 56: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/56.jpg)
T,(n) = 9(2n)-12, for all n 2 1, T,(O) = O, and
T&) = 9(2m)-15, for a i l n 2 2, T a ) = O, h ( 1 ) = 4.
From these it cm eady be observecf tht, for aii n r 2,
T(n) a Tm@) 5 TJn) = T(n) a Te@) s Tt@).
Lemma 4.0.14: Ifthere is a mixeci tower of size 3n with the correct colour order
for the top n-1 trios and the d o u r order r for the h tno then, the
least aumber of steps r w e d to traosfer it to another peg in such a
way that aii trios have the correct colour order is,
a) transfedg it once: T&) = 9(2n)-12, for ail n 2 1,
T,(O) = O.
b) transferring it twice: T,(n)+T'(n) = 9(2n)-10, for al1 n 2 2,
Ta(0)+T(O) = O, T,(I)+T(I) = 7.
c) transferring it three times: 2TW(n)+T,(n) = 12(Zn)-14,
for d n 2 1, 2Tf(0)cT,(O) = 0.
d) transferring it four times: 3T(n)+Tu(n) = 1 5(Zn)-16,
for ail n r 2, 3T(0)+Td(O) = 0,
3T(I)+T,(1) = 13.
Proof: a) Trivial, by definition and Coroliary 4.0.10.
b) It is necessary to h d the s d e s t value of adding two transfers that,
when applied to a mixed tower of s k 3n, will modify the colour order of
the n<h trio nom [cl c3 y] to [ci q ci]. By Coroiiary 4.0.13, T(n) is the
traasfer with srnalier value. T(n)+T(n) does not give the required colour
order, hence, try all the possibte combinations of using it and another
trader that wül give the desud result. T&z)+T"(n) = 9(2n)-10 and
T(n)+T&) = 12(2")-18 are the only co@inations of two using T(n) that
will give the desired colour order. Since T,(n)+T(n) 5 T'@)+Ta@), then
![Page 57: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/57.jpg)
TJn)+T'(n) = 9(Zn)-10 is the solution. Any other wmbiïon will give a
iarger value.
c) As above, look for the best comôiion ofthree trarisfers using T(n).
3T(n) does not #ve the nqi9red colour order, heace3 try di the 'pssible
combinations of using two T(n)s and another traasfa that wül give the
des- resuit- 2T(n)+Tr(n) = T&)+2T(n) = l5(Zn)-l8 and
2T(n)+TW(n) = 12(Zn)-14 are the possible combiasttions. Hence,
2T(n)+T,(n) = 12(Zn)-14 U the solution as any other combination will
give a greater value.
d) Following the same strategy, obsave that 4Vn) does mit give the
desired colour order, hence, try di wmbuiations ushg three T(n)'s and
another transfer.
ObseMng that applying 2T'(n) the initiai colour order will be obtained, use
the r d t on @) to say that 2T(n)+TQ(~)+T((n) = 15(2+16 is the desired
r d t .
Any other combination of four traders will give a greater value.
Lemma 4.0.15: Ifthere is a mixed tower of size 3n with the correct colour
order for al1 n trios then, the least number of steps required to
transfer it to another peg in such a way that ail trios maintain the
correct colour order is,
a) transferring it once: T(n) = 6(2n)-7, for ail n 2 1, T(0) = 0.
b) transfemhg it twice: 2T(n) = 6(2n-1), for ali n 2 O,
c) transferring it three times: 2T(n)+T(n) = 12(Zn)-13, for aiî n 2 1,
2T(O)+T(O) = O.
d) transfening it four times: 4T'(n) = 12(2n-l), for ail n 2 0.
ProoC This proof is similar to the proof of Lemma 4.0.14, hence it is omitted.
![Page 58: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/58.jpg)
Lemma 4.0.16: If there is a mixed tower of sjze 3n with the correct colour
order for the top n-1 trios md the colour order d for the n' trio
then, the least number of steps rrquind to transfer it to anothet peg
in such a way that ali trios have the correct colour order is,
a) transferring it once: T(n) = 3(Zu-l), for ail n à 0.
b) transferriag it twice: T(npT(n) = 9(2m)-10, for ai i n 2 1,
T(O)+T(O) = O.
C) Werriag it three times: 3T(n) = 9(2"-1). for aü n 2 0.
d) M e r r i n g it four times: 3T'(n)+~(rz) = l S(2.)-16, for aU n r 1,
3T(O)tT(O) = O.
ProoT: This proof is similar to the prwf of Lemma 4.0.14, henco it is omitted.
h m m a 4.0.17: If there is a mixeci tower of size 3n with the correct colour
order for the top n-l trios and the colour order 7 4 for the # trio
thers, the least number of steps required to aaasfer it to another peg
in such a way tbat al1 trios have the correct colour order is,
a) d e r r i n g it once: T&) = 6(2-8, for al1 n r 1,
Tm@) = O.
b) traderring it twice: T'(n)+T(n) = 9(29-IO, for ali n r 2,
T(O)+T,(O) = O, T(l)+T,(l) = 7
C) tramferring it tbree times: 2T'(n)tTDd(n) = 12(23- 14,
for all n 5 1,2T(O)+T,(O) = O
d) traderring it four h e s : 3T(n)tT,(n) = 1 S(2n)- 16,
for aU n 2 2, 3T'(0)+Ta(0) = 0,
3T(1)+Ta(1) = 13.
ProoT: This proof is similar to the proof of Laiima 4.0.14, hence it is omitted.
![Page 59: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/59.jpg)
Lcmma 4.0.18: If there is a mixed tower of size 3n with the correct colour
order for the top n-l trios and the colour orâer 4 for the n0 trio
then, the least number ofsteps required to transfer it to another peg
in such a way that aii trios have the corna colour order is, * *
a) transferring t once: Ta@) = 6(2*)-7, for ali n 2 2,
Tac!!) = 0,
T&) = 4.
b) tmm$erring it twice: T(n)+Ttb(n) = 9(2~)-11, for aii n 2 1,
T(O)+TJO) = O.
c) fiansferring it three times 2T(n)+Ta(n) = 12(2n)-137
for dl n r 2, 2T(0)+Ta(0) = 0,
2T(l)+T,(I) = 10.
d) transferring it four times îT(n)+T&) = 1 5(2n)-I7,
for ail n 2 1,3T(O)+T,(O) = 0.
ProoC This proof is similar to the proof ofLemm 4.0.14, hence it is omitted.
Lemma 4.0.19: If there is a mixed tower of sue 3n with the correct colour
order for the top n-1 trios and the colow order a for the & trio
the% the Ieast number of steps required to traasfer it to awther peg
in such a way that d trios have the correct colour order is,
a) traasferrhg it once: T&) = 9(2n)-1S, for ail n 2 2,
TAO) = O, TJ1) = 4.
b) transferrjng it twice: T,(n)+T(r,) = 9(2@)-11, for all n r 1,
T,(O)+T(O) = O.
c) tramferring it three times: 2T(n)+Ta(n) = 12(Zn)-1 3,
for aU n 2 2,2T(O)+TJO) = O,
2'r(l)+Ta(l) = 10.
d) transferfing it four times: 3T(n)+T,(n) = 15(2n)-17,
![Page 60: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/60.jpg)
for aü n à 1.3 T(O)+T,(O) = 0.
P d This p r d i s sidar to the proofof Lemma 4-0.14, hence i t is omitted.
For simplicity, define xJn) as the amiimiai number of moves to mage the three
toweis on peg y, wherey~(O,1.2), where the trio haJ the wlour order x, where xaS3,
and the top n-1 trios have the correct coloin order, e.g, ifwe want to merge the three
towers on Peg O wiîh the correct colour order for al1 trios, tben the minimal numba of
moves required are c&2) since the colour orda for the last trio is e = 1% el QI. Let F3,;
be the set of a& possible 5(n), as d&ed above. It can be eesily observed that there are
1 8 elements in qJ.
To solve the TCTM problem, first it is required to analyse some relationships
among the elements 0 fF3~ .
Lemma 4.0.20: For d n r 0, %(n) = q ( n )
Proof: To obtain ~ ( n ) it is necessary to have the q disk n at the bottom of
Peg O to obtaia the bottom trio in correct colour order. But it is already in
place so it is neceJsaiy to move the top n-1 disks and the top cl disks
fiom their respective pegs to Peg 2, which will allow to move the cl disk n
on Peg 1 to Peg O on top of the Q disk n. To have a legal contiguration,
merge a Q tower of sue n-1, a CI tower of ske n-1 and a cz tower of size
n-l hto a mixed tower of size 3(n-1) on Peg 2 using the minimum nwnber
of moves. In the same way, to obtah ~ q ( n ) it is necessary to have the cl
disk n at the W o m of Peg 1 to have the bottom trio in sa colour order.
But this is already in place so it is necessary to move the top n-1 Q disks
and the top ci disks fiom thir respective pegs to Peg 2 which wiU aiiow
to move the Q disk n on Peg O to Peg 1 on top of the cl disk n. To have a
legai configuration, merge a q tower of sLe n-1, a cl tower of sue n-1 and
![Page 61: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/61.jpg)
a tower ofsize n-l into a mixeci tower of size 3(n-1) on Peg 2 using the
minimum number of moves; wtiich cl* shows that &r)3mL(n).
Lemma 4.0.21: For a l l ~ 2 O, %(n) = &n).
Proof: This proof is simüar to the pmof of Lemma 4.0.20, henœ it is omitfed.
Lemma 4.0.22: For aii n 2 O, al@) = tdZ(n).
ProoC: This proof is simiIar to the proofof Lemma 4.020, hence it is omitted.
Lemma4,0.23= For I n 2 O, q(n) = zz(n).
Proofi This proof is simüar to the proofofkmma 4.0.20, hence it is ornitted.
Lemma 4,0.24= For di n 2 O, q(n) = Y@).
Proofi This proof is similar to the proofofhnmui 40.20, hence it is omitted.
Lemma 4.0.25 For dl n 2 O, o20(n) = t&(n).
PmoE This proof is simiiar to the proof of Lanma 4.0.20, hence it is omitted.
Lemma 4.0.26= For all n 2 0, too(n) = CF&)).
ProoE This proofis similar to the proof ofLemma 4.0.20, hence it is omitted.
Lemma 4:0.23: For ali n 2 O, a&) = sat(n).
Prooc This groof is similar to the proof ofLemma 4.0.20, hence it is omitted.
Lemma 4.0.28: For aN n B 0, ro2&) = a2&z).
ProoT: This prwf is similar to the proof of Lemma 4.0.20, hence it is omitted.
with ~ ( 0 ) = O, dl) = 2, and %(2) = 11
Proof: To prove the initiai conditions, the cese n = O is trivial since no moves are
required to merge ernpty towen. For n = 1, the q, disk is aiready at Peg O,
so traasfer the CI disk fiom Peg 1 to Peg O and then the Q disk f b m Peg 2
to Peg O. This takes 2 moves.
![Page 62: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/62.jpg)
For n r 2, to obtain q(n) it is nquired to move the ci disk n nom Peg 1 to
Peg O to have the bottom trio in correct colour orda; hmce, merge the
top 13-1 dUks of the thne towas iato a maed t o m of size 3(n-1) using
the minimum number of moves. It is possiile to merge the towérs on i )
Peg 5 Ü) Peg O, or iiii Peg 1.
i ) If the merge is on Peg 2, to have the minimum numkr of moves, the
resuiting mixeci tower of size 3(n4) WU have the disk size n-l at the
bottom of the n-l trio. Hence, the dour order for the aio n-1 will be
either rcr2 or a*.
Since m22(n-1) = o ,(n-I) @y Lemma 4.0.22) it wodd take
min[aZ2(n-1), ~ a ~ ~ ( n - l ) ] = min[oz3(n-l), q(n-l)] moves. Then take one
move to trader the ci disk n nom Peg 1 to Peg O. Traiisfer in the
minimum uumber of moves the top moted tower of sizt 3(»-1) âom Peg 2
to Peg 1 to aiiow the q disk n to be transferred to Peg O. It wiii be
discussed iater what kind of tramfier this wül be. Take then one more
move to t r d e r the cz disk n to Peg O oa top of the ci disk PZ. Finally,
transfer in the minimm number of moves the mixed towa of size 3(n-1)
on Peg 1 to Peg O obtaining a towec with the correct colour order for aii
the ~ g s .
If ~nb[a*~(n-l) , ~a~~(n- l ) ]= td2(~91), the colour order of the trio n-1 of
the mixed tower of size 3(n-1) wiil be d. Hence, to oôtain the correct
colour order in the least -ber of steps using two transfers, by
Lernma 4.O.l6b, use T(n-l)+T(n-1) = 9(2=1)-10.
Therefore, in this case, q,(n) = ol(m 1)+9(Zw1)-8.
New. if min[a2(n-1) , t&(n-1)] = d2(n-1), the wlour orda of the trio
n-1 will have to be 2. Hence, by Lanma 4.0.l8b, use
T(n-l)+T,(n-1) = 9(2"-1)-11.
![Page 63: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/63.jpg)
Therefore, in thÎs case, ~ ( n ) = a5(n-1)+9(2*[)-9.
Ïii) Iî the top n-1 trios are merged ont0 Peg 0, it w d d take &,,(fi-1) seps
and d the tnos wiU have the comct cdour orda. Then move the ci ring
sire n from Peg 1 to Peg 2 in one move. T d e r the mixeci tow& of size
3(n-1) nom Peg O to Peg 1 in the Ieast number of moves. Then move the
cl ting n âom Peg 2 to Peg O and the *ring n âom Peg 2 to Peg 0, which
wodd take 2 moves. Finally, W e r the mixed tower o f s h 3(n-1) h m
Peg 1 to Peg O. By Lemma 4.O.lSb, 2T(n-1) = 6(2*L1) are required as
the MO trders- Hence, in îhk case, ~ ( n ) = %(n-1)+6(2"1)-3.
Now solving q,(n) = q(n-l)+6(2.1ci)-3 by the traditionai method to solve
first order recurrence relations, q,(n) = 6(2n)-3n-7 for d n r 1.
Nvie that if the merge ont0 Peg O had been chosen to have the colour
order to for the trio II-1 of the r d h g mked tower of size 3(n-1), it
wodd take
T&I-1) = cZ,(n-1) moves, by Lemma 4.0.21, plus the number of rnoves for
two trders for a mixed tower of site 3(n-1) and 3 more moves, which
are more than &,,(n) = ~r~~(n-1)+9(2~~)-9 prewiously obtaimd.
üii Ifthe top n-1 trios are merged onto Peg 1 there wodd be more moves
than the obtained above since it would imolve a,(n-1) or
so,(n-1) = &,,(n-1) moves plus three -ers and two moves.
This strategy is shown in Figure 20.
![Page 64: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/64.jpg)
Figure 20. Possible strategies to obtain ~ ( n ) for the TCTM problem.
with q(0) = O, q(1) = 2, md q(2) = 10.
Proof: This proof is similai to the proof of Leauna 4.0.29, hence it is ornitteci.
Lemma 4.0.31: Forailn23, .
i q ( n - 1) + 9(zR-I) - 9 c r 2 2 ( n ) = min *(n - 1) + 9(ZR-') - 8
12(2") - 4n - 18
with aZ2(0) = O, ~ ' ~ ( l ) = 2, and a2((2) =
Proof$ This proof is s d a r to the proof ofLema 4.0.29, hencx it is omitted.
Corollary 4.0.32: For d n 2 1, ~ ( n ) = 6(2n)-3n-7.
ProoC: Lemma 4.0.29 States Uiat, 02&2 - 1) + 9(2"-') - 9 o,(n-1) +9(2"-')-8
q2") - 3n- 7
with ~ ( 0 ) = 0, ~ ( 1 ) = 2, and e,,(2) = 11.
From this it can be observed that %(PZ) = 6(2n)-3n07 a for aü n r 3,
CF&~) 2 3(2*l)-3n+l and a2&-1) r 3(2*1)-3*2.
From Lemmas 4.0.30 and 4.0.3 1, for ail n 2 4,
![Page 65: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/65.jpg)
with aL(0) = O, = 2, and q(2) = 10; and -2) +(9 12x2"-') -9
~ * t ( f i - 1) = - 2) t (9 I2X2"") 8 12(2*') - 4n - 14
with C J ~ ~ ( O ) = 0, 0~~(1) = 2, and d2(2) = '1 1.
From the above it can clearly be seen that for dl n 2 3, g(n-1) a 3(2"-1)-
3Hl and a22(n-l) 2 3(2&1)-3n+2.
Coronary 4.0.33: a&) = 6(2*)-3n-8 for aii n 2 2, q(0) = O and q(l) = 2.
ProoT: From CoroUary 4.0.26, for d n 2 3, d 2 (R - 1) + 9(2"-') - 8
a,@) = min E&- 1) + q2"-') - 4 i 9(2") - &i - 8
with q(0) = O, q(l) = 2, and a1(2) = 10.
Substituthg 8 (rl-1) = 3(2n)-3n4, fkom Coroiiary 4.0.32, for ali n 2 3, 022(n - 1) + 9(2"-') - 8
O,@)= min . 6(2")-3n-8 f 9(Zn) -&r - 8
From this it can eanly be obsemd that q(n) = 6(2n)-3no8
if 02*(n-1) 2 3(2*l)-3n, wbich in the above proof has been shown to be
CoroU~ry 4.0.34: ~ ~ ~ ( n ) = 15(2*l)-3n-14, for aü n 2 3, 0 ~ ~ ( 0 ) = O, ~ ' ~ ( 1 ) = 2
Prooc This proof is similar to the proof ofcorollary 4.0.33, hetm it is omitted.
![Page 66: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/66.jpg)
Lemma 4.0.35: For a i i n r 5
with al(0) = O and q(1) = 4.
pmofi Siaiilar to the proof ofLanma 4.029, hence it is omitted.
Lemma 4.0.3& For ai i n 2 2,- ~(n-1)+3F(n-l)+T, , (n-1)+6
c2, (n) = min ~~(fi- l)+3l"(n- 1)+T,,(n- 1) t 5 1"'
ProoC: Similar to the proof of Lemma 4.0.29, hence omitted.
Lemma 4.0.37: For al1 n r 3 Y ,
with 0*~(0) = O, oz0(i) = 4 and m20(2) = 15.
Proof: Similar to the proof of Lemma 4.0.29, hence ornineci.
Lunma 4.0.38: For aii t 2 r 2, -
with Q(0) = O and a*(l) = 5.
Proof: Similar to the proof ofLemma 4.0.29, hence omitted.
Lemma 4.0.39: For ail n r 2, p
ProoT: Similar to the proof of Lemma 4.0.29, hence omitted.
Lemma 4.0.40: For all n r 2, q(n-1)+22'(n- l)+Td(n- l )+4 eo(n -1) +2T(n- 1) +Tm(?? - 1) + 4
witb O@) = O and al) = 4.
Proof: Similar to the proof of Lemma 4.0.29, hence omitted.
![Page 67: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/67.jpg)
ComUvy 4.0.41: ol(n) = 9(2")-3n-13, for all n 2 4, q(0) = 0, q(1) = 4,
~'(2) = 16 and q(3) = 49.
Prao E From Lemma-4.0.3 5, for all n 2 2,
with ~ ~ ( 0 ) = O and ~ ( 1 ) = 4-
From Proposition 4.0.3 and Corollaries 4.0.5,4.0.8,4.0.32 and 4.0.34,
oZ2(n) = 1 5(2*L)-3~-14, for aii n r 3, = O, t~*~(1) = 2 and
~ ' ~ ( 2 ) = 1 1, and, for d n è 1, ~ ( n ) = 6(*3n-7, %(O) = û, T(n) = 3(2"- 1 ),
T(0) = q
T(n) = (3)2*'-7, T(0) = O, and ~&)=(3)2*'-8, T(0) = O.
Substituthg and simpiifjkg,
gl(n) = 9(2R)-3n-13, for al1 n r 4, q(0) = O, q(1) = 4, q(2) = 16 and
~ ~ ( 3 ) = 49.
Note that the reason why the equation does not hold for n 5-3 is because
for that range ç,(n) = a2&) and T(n) à T-(n).
Codary 4.0.42: dl@) = 21(2*')-3n- 12, for aU n z 3, oZi(0) = 0, ~ ~ ~ ( 1 ) = 5
and d 1(2) = 20.
ProoE Simiîar to the proof of ~orolky 4.041, hence omitted.
CoroU~ry 4.0.43: a*&) = 1~(2~')-3n-10, for aii n 2 3, &(O) = 0, ~ ~ ~ ( 1 ) = 4,
and aZ0(2) = 15.
ProoE Similar to the proof of CoroUary 4.0.4 1, hence ornittecl.
CoroUary 4.0.44: oo(n) = 9(23-3n-11, for d n 2 2, ao(0) = 0 and q(1) = 5.
PmoE Similar to the proof of Coroiiaq 4.0.41, hence ornitteci.
ComUug 4.0.45: a&) = 9(2")-3n-6, for aii n r 3, a#) = O, a2(1) = 4 and
02(2) = 16.
Proofi Similar to the proof of CoroUary 4.0.41, hence omitted.
![Page 68: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/68.jpg)
CoroUUp. 4.0.46: &fi) = 9(2")-3n-10, for d n 2 2, %(O) = O and 4 1 ) = 5.
Proof: Simüar to the proof of Coroky 4.0.41, hence omitted.
ComiiUp. 4.04% for ail n r O,
- ci(n) k %(pl) a oz&) s o20(n) a u@) s ~ ( n ) s Mn) s s?(n) s d ( i r )
Pmofi From corollaries 4.0.32 to 4.0.34 aad 4.0.41 to 4.0.47,
a,@) = 6(29-3n-8, for all n è 2, q(0) = O, ai(l) = 2,
Finally, it is necessary to prove that the given solutions to the TCTM probtems are
optimal. A solution to this problem is optimal when it requires less than or qua1 number
of steps to any other possible solution obtained folowing the TCTM problem rules.
Define ONfi# as an optimal solution to the TCTM problem on peg x, wbere
XE (0,1,2}, for towers of size n
![Page 69: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/69.jpg)
Lemma 4.0.48: For n 2 2, any solution to the TCTM probkm on Peg O which
&ers a mixed towa of size 3(n-1) fiom one peg to another
more than twice aiowt be opîimai
P m f i By way of c o d c t i o n , assume Bo(n) be an optimal solution to the
TCTM problem on Peg O which traasférs a mixed tower of size 3(n-1)
nom one peg to another mon thau twice. It can be obsemd that, Bo(@
in addition to &g
T(n-1) (which is the optimal m e r by Proposition 4.0.3) at least three
times, it must c d a mergey.&z-1) E F3>, where x E [O, 1.2) and y E S , at
least once since it is necessaiy to remove ail the top n-1 c,, disks on Peg O
d aii the top n-1 c, disks on Peg 1 and merge them with the top n-1 c,
disks on Peg 2 in order to transfer the c, duk n fiom Peg 1 to Peg O on top
of the c, disk n in one move. Then it is necessary to transfer the mked
tower of size 3(n-1) to Peg 1, using one of the at least three T'(n-lys, in
order to transfer the c, disk n nom Peg 2 to Peg O on top of the c, disk n in
one move.
By Proposition 4.0.3, T(n-1) = 3(2*1-1).
By coroiiaries 4.0.33 and 4.0.47, yx(n-1) must be at least
y&l) 2 q(n-1) = 3(2")-3n-5, for all n r 3, q(0) = 0, q(1) = 2,
Hence, 3T(n-l)+yx(n-l)c2 2 1 5(2*')-3n-l2, for ail n 2 3,
Bo@) 2 i 5(2"')-3n- 12, for ail n a 3, B,(2) r 13, BO(1) 2 2, Bo@) = 0,
By Coroliary 4.0.32, q,((n) = 6(2%3n-7, for ail n r 1, %(O)=û.
Heace, for all n 2 2, 1 ~ ( 2 ~ ~ ) - 3 n - l 2 > 6(2")-3n-7.
Therefore, B&) > E&) which contradicts the assumption of Bo@) being
op W.
![Page 70: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/70.jpg)
Hence, for n 2 2. any solution to the TCTM problem on Peg O which
traders a mixed tower of size 3(n-1) from one peg to another more than
twice c a ~ o t be optimaltimal
Proposition 4.0.49: For aiI n 2 O, %(n) is the optimal solution to thegTCTM
problem on Peg O.
ProoE By Lemzna 4.0.48, the optimal solution-to the TCTM problem on Peg 0,
ON&), must transfer a mixeci tower of size 3(n-1) tiom one peg to
another at most twice in order to be optimal.
It is necessary to transfer the c, and c, disks n fiom pegs 1 and 2,
respectively, to Peg O. To do this it is required to merge fint the top n-1
c, cl and q disks fkom pegs O, 1 and 2 since it is necessary to move the c,
or Q disk ~2 (moviog the Q disk n would cause unnecessary moves as it is
already in the desired place). They can be merged into a mixed tower of
size 3(n-1) on (a) Peg O, @) Peg 1 or (c) Peg 2. After merging it is
possible to (i) traosfer the resuhing mixeci tower of size 3(n-1) to another
peg or Cu") move one of the disks n with no other disk on top.
ai and bi) If the merge is on Peg O or 1 and then it is decided to t r d e r the
resuiting mixeci tower of size 3(n-1) to another peg, t r d e r it to Peg 2 in
order to move the cl disk n nom Peg 1 to Peg O, on top of the q~ disk n
(othecwise, to obtaïn the correct colour order for the f l trio, it would
require one addition transfer). Then tramfier again the mixed tower of site
3(n-1) fkom Peg 2 to Peg 1 to dow moving the 9 disk n fkom Peg 2 to
Peg O. Fhaiiy d e r a third t h e the mixeci tower of size 3(n-1) to Peg O,
contradicting Lemma 4.0.48, and hence proving that these are not optimal
solutions to the TCTM probkm on Peg O.
ciJ In a similar way it can be shown that merging on Peg 2 and then
transfemng the resulting mixed towa of size 3(n-1) to either of the two
![Page 71: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/71.jpg)
remaining pegs, it WU require at least uiree -ers to obtah the desired
setiip and, hence, showing this U not an optimal solution to the TCTM
problem on Peg O.
a If the merge is on Peg 0, it Y posiible to d e r move the ci disk n f?om
Peg 1 to Peg 2 or the 9 disk n fkom Peg 2 to Peg 1. Then tramfier the
mixed tower of size 3(n-1) h m Peg O.to the empty peg (any other move
wouid not be optimal).
lf the 9 disk n is on the top of Peg 1, in order to have the correct colour
order for the BIh trio, it wiU be recp.i.red to Vansfer the mixed tower of size
3(n-l), at least, two more times in addition to the one already done.
Hence, by Lemma 4.0.48, this is not an optimal solution to the TCTM
problem on Peg O.
If the cl disk n is on the top of Peg 2, move it to Peg O on top of the co
disk n. Then move the 9 disk n f b m Peg 2 to Peg O, on top of the ci
diskn. Fdy, ,transferthe mixed tower of sis 3(n-1) fiom Peg 1 to
Peg O, in such a way that aii the trios have the correct colour order in the
least wmber of steps- This option r w e s two transfers, hence it could
be opthai, by Lemma 4.0.48.
Suice the three towers of size 12-1 are merged on Peg O, to have the least
number of moves t is necessaqr to have the colour order e or t for the
(el)& trio, Le., the co disk n-1 would be at the bottom of the mixed tower
of size 3(n-1). By definition, the minimum nurnber of seps to obtain these
are
eo(n-1) = 6(2*1)-3n-4, for aiI n 2 2, ç,(û) = O, (by Corollary 4.0.32) , and
~ ~ ( n - 1 ) = oz&- 1) = 1 5(2m2)-3~-1 1, for ail n 2 4, &(O) = 0, cZ2(l) = 2,
![Page 72: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/72.jpg)
a',(2) = 1 1, @y Lemma 4.0.21 and Corollary 4.0.34). respectively. If the
order of the rilii mo is E, by Lcmmii 4.0.15b. the two required transférs to
obtain the correct colour order in the le- d e r of steps will be
2'T'(1-1) = 6(2*1-1). for all n h 2.
Since q,(n-l) S ~(Iz-1), for aii n 2 1.
Hence, ~,,(n-l)+2T(n-1)+3 = 6(20)-3n-7, couid be the optimal solution
If the merge is on Peg 1, move the Q disk n h m Peg 2 to Peg O or the
Q disk n fiom Peg O to Peg 2, but in order to obtain the correct colour
order for the n" trio, it is required to transfer the mixed tower of six
3(n-l), at least, two more times in addition to the one aiready done.
Hence, by Lemma 4.0.48, this is not an optimal solution to the TCTM
problem on Peg O.
If the merge is on Peg 2, it is possible to either move the cl disk n fiom
Peg 1 to Peg O or the CO disk n fiom Peg O to Peg 1 (which would not be
optimal). Then traasfer the mixed tower of size 3(n-1) fkom Peg O to the
empty Peg 1 (any other move would not be optimal).
Then move the disk n to Peg O, on top of the cl disk n. F i y , trader
the mked tower of size 3(1z-1) fkom Peg 1 to Peg O, in such a way that al1
the trios have the correct colour order in the least number of steps. This
option requires two transfers, hence it codd be ophxd, by Lemma 4.0.48.
Since the three towen of size n-1 are merged on Peg 2, to have the lest
nurnber of moves it must have the wlow order 7 0 2 or ~2 for the (n-l)h
trio. By definition, the minimum number of steps to obtah these are
~ g ~ ~ ( n - 1 ) = a,(ri-1) = 6(2*1)-3tt-5, for all n r 3, q(0) = O and q(1) = 2,
@y Lemma 4.0.22 and Coroliary 4.0.33). and ~ ~ ~ ( n - l ) = 15(2+3n-11,
for dl n 2 4, c2*(0) = O, aZ2(l) = 2 and a2*(2) = 11, (by CoroUary 4.0.34).
respectively. If the order of the t f l t i o is TG', by Lemma 4.O.l6b, the two
![Page 73: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/73.jpg)
requïred trausfiers to obtain the correct colour order in the least m b e r of
seps will be T(n-l)+T(n-1) = 9(2el)-10, for ail n 2 2.
Since q(n-1) 1 ~2~(tz- i ) , for ail n t 1,
q(n-i)+T(n-l)+T(n-l)+2 = 15(2*l)-3n-l3, wuld be the o p W SoIution.
Comparing with the solution obtained in (aiii, obsave that
1 S(2fi')-3nœI3 r 6(2n)-3n-7, for d n 2 1.
Therefore, for d n 2 1, ON,(n) = ç,(n-1)+2T(n4)+3 = 6(2*)-3n-7,
ON,(O}=o. -
By CoroUary 4.0.32, %(II) = 6(ZN)-3n-7, for ail n 2 1, %(O) = 0.
Hence, ON&) = q,(n), for aU n 2 0.
Therefore, for dl n 2 O, ~ ( n ) is the optimal solution to the TCTM problem
on Peg O.
Lemma 4.0.50: For n 2 2, any solution to the TCTM problem on Peg 1 which
transfers a mixed tower of size 3(n-1) fkom one peg to another
more than three times cannot be optimal.
Proof: Similar to the proof of Lemma 4.0.48, hence ornitteci.
Proposition 4.0.51: For d n r O. €,(II) is the opthai solution to the TCTM
problem on Peg 1.
Proof: Similar to the proof of Proposition 4.0.49, hence omitted.
Lemma 4.0.52: For n r 2, any solution to the TCTM problem on Peg 2 which
transfers a mixed tower of size 3(n-1) fiom one peg to another
more than four h e s cannot be optimal.
Proof= Sünilar to the proof of Lemma 4.0-48, hence oinitted.
Proposition 4.0.53: For ail n 2 O, %(n) is the optimal solution to the TCTM
problem on Peg 2.
Proof: Similar to the proof of Proposition 4.0.49. hence omitted.
![Page 74: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/74.jpg)
Ging back to the problem, fiom the above r d t s it can be obsmred that the
sofutions to the Three Coloured Towen Mage Problem are:
q,(n) = 6(2R)-3n-7, fÔr ali n 2 1, @) = O, for the mage on Peg O;
el@) = 9(2")-3n-i3, for all a4, e@) = O, ~ ~ ( 1 ) = 4, e1(2) = 16 ad
~(3 ) = 49, for the mage on Peg 1; and
~ ( n ) = 9(2")-3n-10, for aU n r 2, @(O).= O and ~ ( l ) = 5, for the merge on
Peg 2-
These results show clearly that, as on the results on the CTM problem with two
towers, the least nurnber of moves occur when the merge is perfom on the peg where the
disks of colour c, were initidy.
![Page 75: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/75.jpg)
5.0. A GENERAL SOLUTION TO THE COLOURED TOWERS MERGE
PROBLEW
After dys ing specinc cases, a general solution to the CTM problem wiil be
presented in this section. As meritioned in S d o n 2.3.1, proving the optmiaiky of
variations of the original Tower of Hanoi problem with more than th- pegs has beea
observecl to be a very dificuit probkm as shom in [q and [W. Hence, we did not tiy
to prove the optimality of the general solution in this section. Howmr, this should not
invalidate the importance of the resuits here offered since they are correct and also show
strong indication to be optimal- As wek the insight to the general problem obtained fiorn
them is valuable.
From Chapters 3 and 4 it can be obsened that the best solution ocaus when the
merge is performed on Peg O as the Q disk n is aiready on the target peg and does not
require to be moved. Hence, thk section d only focus on the CTM problem on Peg O.
Recaiî that the objective of the CTM problem is to merge on a board with m+l
pegs, numbered O to m fiom left to nght, m towers of m dEerent colours, Q through
~ , , ~ - b with n disks eaçh into a mixed tower of size mn with the correct colour order for al1
the n sets of m disks of the same size using the following des:
1. Only one disk at a t h e may be moved;
2. Only the top disk in a tower may be moved;
3. A disk may only be placed on top of a disk of equal or larger diameter,
regardles of colour;
4. The towers are to be merged in a aiinimum nimber of moves.
Let MJm,n), where x E (O, 1, ..., m}, be the minimum n u m k of moves needed to
solve the CTM problem with m towers on peg x.
![Page 76: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/76.jpg)
M e the timction T'(m,n) to be the minimum number of moves needed to
traasfer a mked tower ofsize mn firom one peg to a legal configuration on another peg.
D&e the on'gimi peg as the whem the tower lies Înitially, the target peg as
the peg where the tower has to be transfetfed to, and the mnilicny pogs as d *the other
m-1 pegs that are aeîther the originaI nor the target pegs.
Lemma 5.0.1: For aii n s m, T'(.*fi) = m(2n 4). with T(nr,O) = O, when the
original colour order of the top n-1 sets of m disks will be
maintainecl and for the set of m disks of size n the colour order wiU
be inverteci-
Proof: in order to transfer a mixed tower of sue ntn, the set of dûks n must move
to the target peg. According to the des, they cannot be placed on top of
a tower coataining any of disks 1, &...fi-1; hence, these cannot be on the
target peg Since there are mtl pegs and n 5 m, each one of the top n-1
sets of diffèrent size can be moved in rn steps (ïuivening the colour order of
the set) to one of the auxüiary pegs. Then, it takes m steps to transfer the
set of disks n fiorn the original peg to the target peg, inverthg the colour
order of this set. Finally, trarisfer one by one each of the top n-l sets of
disks fiom the auxiliary pegs to the target peg in m steps, changing them
back to the original colour order. In total this wili take
T(rn,n) = m(n-1) + m + m(n-1) = m(2n- 1).
The initial condition T(m,O)=û is trivial since no moves are required to
move an empty tOWer.
in the case where n > m. the solution to obtah the least number ofmoves is net so
simple. For certain values of m there may be a unique solution to obtain the Ieast number
of steps T(m.ta), in othet cases there may be more than one. One of these solutions wiii
be discussed ne*.
![Page 77: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/77.jpg)
It is evideot that halfway tbrough the process of transfecring a mixed tower of size
mn the set o f m dWks of size n iie done in the original peg, say Peg 0; the target peg,
Peg m, is empty and the top n-1 sets ofm disks are disiributed among the remaining m-1
auxiliary pegs. It may be assulled tbat the k, kgest d i b are ou Peg 1, the neh k, disks
in Peg 2, ... . and the smallest k,, disks are on Peg mol, where
(50.2) k&+. ..+km, = n(n-1).
The reason why in each of the nt4 a m h y pegs the dWks may be anangeci in
consecutive size is because since the mailest di* sïze (disks 1) wili cover any of the other
n-1 disk sizes, it is most efficient ifthe disks they cover be the smallest ones so these ones
in tura do not block other pegs. As weli, it is most dcient if the piles with the smaller
disks contain more elements since there be more auxiiiary pegs adable during the
transfer. Zn other words,
(5.0.3) nt S kl 5 4 5 ... Skm1*(n-1).
Since the disks in the piles are in consecutive order then we wiN restrict aü of the
m disks of the same size to be on the seme peg. Hence, k, = O mod nt, for al
i = 1,2 ,..., m-1.
So, ifr, = (k,)ln, for all i = 1,2, ... ,ml, to reach this intermediate configuration, the
number of steps repked are
(5.0.4) d(m,n-l) = T'(1 ,rI)+T'(2,r&..+T(m-1 ,r,,), where r, +r2+-. .+r,,=n- 1.
It wiii take m steps to transfer the m disks of size n fiom the original peg to the
target peg, inverting the originai colour order of this set of disks. Finaiiy, we need to
transfer the top n-1 sets ofdisks ftom the d w pegs to the target peg Since this is
the inverse of distnbutitig n-l sets ftom one peg to m-1 auxGary pegs, then it gives us the
same number of steps, 4m, ml), as (5.0.4).
So, the total number of steps to transfer a mixed tower ofsize mn frorn one peg to
another on a board with m+l pegs following the above strategy k
(5.0.5) T(m, n) = rn+2d(m,n-1) = m+2[T(1 ,rJ+T(2&+. ..+T(m-I ,rml )],
![Page 78: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/78.jpg)
where rt+r2+ ...+r mt=n-l.
ifthe optimal dimibution of the top m(n-1) di& onta the in-1 d a r y pegs was
kI+k+. ....+k,, = m(n-i), as in (5.0.2). Ho-, this is not neaJsarily the optimal
By induction it can &y be proved that, following this strategy, a rnEced tower of
size mn w d i be transferred fiom one peg to another m g the wlour order of the top
11-1 sets of m disks, since they are transfied an emn number of times, and inverting the
colour order for the B set of m disks, since they are ody tmx&erred once &om the
original peg to the target peg.
Keeping ali the disks of the same size together on the same peg @es the
advantage that each size can be considered as a single di&, transforming Ir(m.n) into the
solution of the Tower of Hanoi puzzle with nrtl pegs aad n disks, which here will be
callai H(mtl,ir). To obtain the total number of rnoves required to solve T(m,n), it is just
Several solutions and algonthms to solve H(m+l,n) have been presented in the
iiterature, as uidicated in Chapter 2. However, none of these have been proved optimal.
Since proving the mbhahty of the solutions of variations of the Tower of Hanoi problem
with more than three pegs is apparently a very ciifficuit problem [6,46], we do not intend
to prove optimality for the CTM problem with more than thra pegs. Hence, the solution
to H(m+l,n) presented by Frame in [21] will be useci, since his strategy is simiiar to the
one presented above and the proof of his sohtion is w d qlained.
He presents his solution to H(kn), where m. as the minhum number of moves
required to move n disks, given by the followhg fôrmula: ( k - 3 + i ) ! (k +s- 3)!
H(R, n) = C 2' (5.0.7) ( k - 3 ) ! t ! (k - 2)!(s- l)! 1
![Page 79: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/79.jpg)
where s is the largest integer for which the last tenn on the right of equation (5.0.7) is
positive. a!
R e d that the binomial coefficient
where a and b are non-negative integers.
Remrithg (5.0.7) for H(m+l,n), we have that
H(nz+ln1 = 2 t t (n+: -2 )+2s [n - ("+ss2 ) ] (5.0.8) t=o S-1
where s is the largest integer for which the last term on the right of equation (5.0.8) is
positive.
Hence, for n > m and m 2 2,
(5.0.9) e o
Vewng (5.0.9) for m = 2, s = 11-1 Y?-2
~ ( 2 , n ) = 2C2' +Y =2(2" -1) (5.0.10) r=O
which is the same optimal result obtained in Proposition 3.2.3.
Going back to the CTM problem on Peg O, using (5.0.9) as the solution for
T(m,n), a solution to &(m,n) WU be presented.
First, define M"'m,n), where x E (0,l. ..., m}, as the minimum number of moves,
using Ml pegs, to merge m towers with n rings into a mo<ed tower of size mn on peg x,
such that the top n-1 sets of m disks are in the correct colour order and the te set of m disks is in the inverted colour order.
![Page 80: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/80.jpg)
Lemma 5.0.11: For ali n r 2 and all m 2 3,
i Mo(m,n- 1) +ZT(m,n- 1)+m-1 Mo (m, n) = min
W,(m,n-l)+T(m,n-l)+m-1 9
where M,(m,O) = O and &(m, 1) = ml.
ProoE To prove the initial conditions, f9r n = O it is aMal since no moves are
required to merge empty towas. For n = 1, the q disk is alnady at Peg O,
JO traasfer the ci disk Peg 1 to Peg O, then the ~2 disk fiom Peg 2 to
Peg O, and so on uotil the cm-1 disk is trrinsfened tiom Peg m-1 to Peg O.
This takes m-l moves-
For n r 2, to obtain &(m.n) it is requked to move the m-l disks size n
nom the aUlCili;uy pegs to Peg O to have the bottom set of m dùks size n in
correct wlour order; hence, merge the top n-1 disks of the na towers into
a müced tower of size m(n-1) using the minimum number of rnoves. It is
possible to merge the towers on 6) Peg O or any of the ml auxGary pegs,
or (ii) Peg m.
( i ) If the merge is done in either of the m-1 auxiiiary pegs or Peg O
(Figure 21a), in order to be aMe to set aii the disks of s ize n on Peg 0, the
mixed tower of size m(n-1) wouid have to be t d e r r e d to Peg m (empty
peg) using T'(rn.n-1) moves (Figure 21b). Once aii the m disks size n are
in correct colour order on Peg û, usine m-1 moves (Figure 21c), the mked
tower of size m(n-1) would have to be traosferred h m to Peg m to Peg O
using another T(m,n-1) moves (Figure 21d). To be able to use T(m,n-1)
twice as the tramfer to have the rninhm nimber of moves, it is necewuy
that the resuithg mixed tower of ske m(n-1) on Peg m have the correct
colour order for aü the disb. As disnuseci above, the merge that would
reqwIe the least number of moves is the merge on Peg 0, as the q~ disk n-1
is already on Peg O. Hem,
![Page 81: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/81.jpg)
M,(m,n) = M,(m,n-1)+2T(mIn-1)cm-1
If the merge is on Peg m ody one transfef wouid be required. To be
able to use T(m,n-1) as the traiufi to have the minimum mmber of
moves, it is necessary that the resuiting mixeci towa of sis ni@-1) on
Peg m have the inverteci wlour order for the sa of dUks size rrl at the
bottom Hence, it would take Mm(m,n-1) moves to merge the top n-1
disks fiom the m towers on Peg n, Wgure 21e). Then, another m-1 moves
would be required to move the disks size n in the correct colour order on
top of the CQ disk n on Peg O Figure 219. F i y , it wodd take
Tt(m,n-1) moves to transfer the mixed tower of size m(n-1) fiom
Peg m to Peg O (Figure 21g), obtaioing on Peg O a mked tower of size mn
with the correct colour order for aii the disks. Hence,
&(m,n) = Mm(m, n-l)+T(mtn- 1 )+m-1.
Figure 21. Strategies to obtain M,,(m,n) for the CTM probiem on Peg O.
Lemma 5.0.12: For ali n r 2 and aIl m 2 3, Mm(m,n) = M,,(m,n-1)+2T(m,n-l)+m,
where M!m(mIO) = O and Mfm(m, 1) = m.
PmoE To prove the initial conditions, for n = O it is trivid since no moves are
required to merge empty towers. For n = 1, we transfér the Q disk fkom
Peg O to Peg m, then transfer the cl disk fiom Peg 1 to Peg rn, the Q disk
![Page 82: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/82.jpg)
fkom Peg 2 to Peg m, and so on untii the h.1 disk is traasferred fiom
Peg ml to Peg m. This takes rn moves.
For n 2 2, to obtain Mm(m,n) it is n<iuired to move the m disks ske n h m
the origiael and a d h y pegs to Peg m to have the bottom set o h disks
size n in correct coiour orda; hence, merge the top n-1 disks of the m
towers into a moted tower of ske m(n-1) ushg the minimum wmber of
moves. It is possible to merge the towers on (i) Peg m, or (ïi) Peg O or
any of the m-1 arutüiary pegs.
O If the merge is done on Peg m. it is necessary to trader the mixed
tower of sue m(n-1) f?om Peg m to any of the otha pegs, say Peg m-1,
since the disks size n have to be moved to Peg m. This takes T'(m,n-1)
moves. Since it would be inefficient to traasfer the tower on top of the
c,,~ disk n, we have to mon this disk to Peg m-2. Then, the disks size n
have to be transferred to Peg m in the imrerted colour order first moving
the c,~ disk ri nom Peg nl-2 to Peg m, thenethe c d disk n from Peg nl-2
to Peg m, then the c,3 dgik n Corn Peg m-3 to Peg m, and so on untit the
q disk n is transferred h m Peg O to Peg m. This would take m moves.
Fiody, it is required to tradetled the mixed tower of size m(n-1) f?om
Peg m l to Peg m in T(m,n-1) moves. Hence,
M',,,(m, n) = M!,,,(m,n-1)+2T(ni.n)+m+l
Ci) Now, if the merge is done in either one of the m-1 d a r y pegs or
Peg O, in order to be able to set ail the disks of size n oa Peg m. the ma<ed
tower of sue m(n-1) would have to be transferred to an empty peg once
the disks of size n on such peg has been transferred to Peg m using
T(m,n-1) moves. As discussed above, the merge that would require the
least number of moves is the merge on Peg 0, as the 9 disk n-l is already
on Peg O. Hence, we merge the top n-1 disks fiom the m towers on Peg O
![Page 83: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/83.jpg)
in M,(m,n-1) moves mgure 22a). Mer that, we fwst move the cm, disk n
fiom Peg m-1 to Peg m. then the c,, disL n fiom Peg m-2 to Peg m, and
so on until the cl disk n U m o d b m Peg 1 to Peg m. This takes m-1
moves (Figure 22b). Then, the mixeci towa of size m(n-1) wodd have to
be transfkrred nom to Peg O to Peg 1 using T(rn.n-1) moves (Figure 22c).
It takes one move to t r d e r the co àiik n fiom Peg O to Peg m
(Figure 22d). Finally, we transfiér the mixed tower of size m(n-1) on Peg O
to Peg rn in T'(m,n-1) moves obtaining a mked tower of size mn with the
correct colour order for the top n-1 sets ofm disks and the inverted colour
order for the tlta set (Figure 22e). Hence,
Mm(rn,n) = M,(m,n-1)+2T(m,n-l)+m.
Cornparhg the above results with Lemm 5.0.1 1, it can be easiiy observed
Figure 22. Strategy to obtah Mm(m,a).
![Page 84: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/84.jpg)
CoroiJary 5.0.13: For aU n 2 2 and aU m 2 3,
where M,(m, O) = O and h ( m , 1) = m-i .
Proof: From Lemma 5.0. 1 1. for I - n r 2 and all m r 3, M,(m,n-l)+2T(m,n-1)tn-i
Mo (m. ri) = 1Cf,(n,n-l)+T(m,n-l)+m-1
and fiorn Lemma 5.0.12, for aU n 2 2 and di m 2 3,
Substituthg Lem- 5.0.12 into Lernma 5.0.1 1, for aU n r 2 and ail m 2 3, M,(m,n-1)+2T(m,n-1)+m-1
Mo (m, n) = M,(m,n-2)+2F(m,n -2) +T(m,n - 1) +2m- 1
Hence, for all n r 2 and d m 23, M,(m,n-2) +2T(in,n-2) +2T(m,n - 1) +2m- 2
Mo (m, 82) = Mo(m,n-2) +2T(m,n-2) + T(m,n-1) +2m- 1
Since, T(m,n-l)>l for aii n 2 2 and di m 2 3, then
M,(m, n) = %(m,n-2)t2T(m.n-2)+T'(m,n-l)Ç2m- 1,
where &(m. O) = O and &(m. 1) = ml.
![Page 85: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/85.jpg)
By substituthg equation 5.0.9 and Lemma 5.0.1 in Coroiiary 5.0.13, we have that
the solution to the CTM problem on Peg O is
where Mo(m,0) = 0 and M0(m,l) = m - 1.
Foralln>m+2 and d m 22.
where n is the largest integer for which n - 1 r (m z; 2), r ia the Iargest integer for
which n - 1 > (y2)* To ve* this result for the cases where m = 2 and nt = 3, it will be compared with
the r d t s obtained in sections 3.2 and 4-0,
When n>m, m = 2, s = n-3 and r = n-2. Hence,
SimplifLing (5.0.15) we have,
(5.0, 16) M&,n) = &(2,n - 2) + 2*1- 3, where &(2,0) = O and &(2,1) = 1.
It c m be obsewed that equatioo 5.0.16 is the same as Coroliaty 3.2.12. Solving
the remence we obtah the expticit solution
(5.0.17) &(2,tt) = = (1 114) + (1/12)(-lp + (8/3)2" - (3/2)n, for al1 n 2 O,
![Page 86: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/86.jpg)
which on Lemma 32.20 is proved to be the o p t i d solution of the CTM problem
with two towers on Peg O.
Now, when m = 3,
Hence, for al i n 2 5,
SimpIir;ling (5 .O. 1 8) we have,
From these results, it c m be observed that the finai results WU be of the order
0 ( 9 ( 2 ) ) . Comparing this with the optimal r d t , %(n) = 6(2'~)-3n-7, of the Three
Colour Tower Merge Problem on Peg O obtained in Cahpter 4, cleady shows that, for aü
n 2 5, by adding one more peg the number of moves will decrease.
Unfortunately, the optimality ofthe proposed generai Solution 5.0.14 to the CTM
problem on Peg O can not be proved since fint it would be neassary to prove the
optimality of H(m,n) wbich, as stated before, is a very ciifficuit problem. However, there
is a strong indication that the solutions to H(m,n) offaed in the literature are in fact
optimai, dthough no formal p m f of optimality has yet been presemted. Hence, we cm
venture to clah that Equation 5.0.14 is a vety good solution to the CTM problem on
Peg O.
![Page 87: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/87.jpg)
6.0. APPLICATIONS AND CONCILUSLONS.
In this nnal d o n , some applications of the g e a d solution of the CTM problem
wiii be presenîed. Mer that, open questions wiU be posed and the conclusioqs wül be
givea
At the end of Chapter 5, a general solution to the CTM problem in tenns of the
number oftowers, m, and the number ofrings, n, was pnsented.
So, now we can go back to the problems pcesented in the introductioa
Recali that the initial problem consistecl of a railway Jwitching network with three
tracks where two trains had to be merged preserving the order of the cars onto a third
engine, nwer setting a heavier car behind a lighter one. The question was to find the
fastest way to perforrn the merge and the number ofmoves required.
If the tracks are numbered O, 1, and 2, as show on Figure 23% uieo this system
can be represented as the initial con6gwation of the CTM problem with two towers, as
shown on Figure 23b.
Figure 23. Railway switching mtwork problem represented as CTM problem.
Shce it can be represented as the CTM problem, by the work done on Section 3.2,
it is clear that the best way to do the required merge is by foilowing the strategy to obtain
![Page 88: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/88.jpg)
U,(2,n), which is expIained in the prwf ofLemma 32.8- This strategy is the best since
K(2,n) was proved optimal in Lemma 3.222.
Hence, the nimber of rnoves required to merge the-two trams are obtained by the
equation *.
(6.1.1) &(2,n) = -(25/4)-(i/12)'1M16D)2n<3/2)n, for aii n r 2,
~(2,0)=0 and &(2.1)=2.
nie other problem presented in the introduction is of a more redistic nature.
Figure 24 shows once again the graphid representation of the program explaineci in
Chapter 1 where each routine of each process r-es the results obtained by the other
routines-
Figure 24. Graphical representation of the structures of the program on Chapter 1.
To avoid the expense of buying m proce~sors ta run this program in parailel it was
proposeci to simulate it by first creating the m process stacks and then merging then into a
single stack such that the results of Routine 1 of Process 1 are at the top, then the ones of
Routine 1 of Process 2, etc., with the ones oPRoutine n of Procws m at the bottom of the
stack.
![Page 89: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/89.jpg)
If each one of the results was a ring with the size accordhg with the routine
number and ai l the rings belonging to Process m were set on Peg 0, the ones belonging to
Process m-1 on Peg 1, and so on, and leaving an empty Peg m+l, the structure of the
program wouid be isomorphic to the initiai configuration of the C'ïM problem with m
towers.
Hence, the number of required moves to paform the merge would be determineci
by equation 5.O.Pi.
Suppose there are ody 3 processs, Le., nt = 3. As shown by equatiou 5.0.19, the
number of moves required will be of the order O(2 t*7 11 Lr- ). If the number of routines in
each process is, for example, n = 500, then the nwnber of moves wül be in the order of
O(243). R d that each move, in abstract data type ternis, consists in traasfeniag a di&
which in fact is a data unit, fiom one stack to another. If the stacks are implemented as
linked iists, the operations cequird to perfom a move are, first, to compare the size of the
disk to be moved with the size of the disk at the top of the target stack. If the disk is not
larger, the pointer of the top disk of the target stack to the disk to be moved.
Remove the Iuik f?om the disk origindy below of the moved disk and set this disk as the
top of such stack Finally, set the moved disk as the top of the target stack If our
processor could perfiorm IOf0 moves per second, it w d d take about 29 yean to rnerge
the three stacks of results into a single stadc in the required order. Therefore, it is
certainly advisable to buy the other two procasors.
However, in the case of the finite element analysis presented in Figure Sc, where
m = 3 and n = 4, the proposed simulation t h e is reasonable. If the TCTM model is
implemented the solution will require 77 moves but if the CTM model is used, by addhg
an empty stack, it wül require 46 moves.
This example shows the importance of this kind of mathematical modei. The
proposed solution, an alternative to buyhg the processors, seerned very efficient and
simple to implement. It was only through the numerical result that the reai problem of
![Page 90: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/90.jpg)
this proposed solution for a relatively large n became evident. If no mathedcal mode1
had been dewloped before implementhg. the waste of t h e and resources would have
been considerable. As well, for a s d n, the mode1 cleady shows a more efficient way to
impiement the solution shce if no auxîkuy stack nicl had ben wed the problem would
have changed to the Three Colound Towers Merge prob1em ami the order of the solution L4iZï-1J would have been O(29 iostead of O(2 1-
Another use of this kind of anaiysis usiag Towers of Hanoi is in the area of
combuiatorid design. The dewlopment of optimal amputer algorithuis using stacks is
not always so simple. The Tower of Hanoi &es a clear physid representation of a
stack Once a recurrence relation, similar to the oaes pnsented in the previous sections,
has been established, the r d v e algonthm to represent the function foliows directly.
For example, fmm Lemma 3.2.1, we have that T(2,n) = 2 T ( 2 1 2 for all
ri 2 1. Hence, the optimal cecursive algorithm to irnplement a W e r T of a mixed
tower of sue 2n Znom peg x to peg z using the aWtijiayy pegy is the followiag:
Procedure Transhv(n,~y,z); i f e 0 then
i fn = 1 then
else
end.
fori = 1 to2do popm PuSh(2)
end; TmInv(n- 1,x.z.y); f o r i ~ l t o 2 d o
Pop(x); l'ush(2)
end; TransUiv(n- l,y,xz);
Here the subrouthe Po&) removes the top disk fiom Stack x and Push(z) insens
the disk in Stack z. For interest sake, a pseudocode to hplement the solution to the CTM
problem with two towers has been induded in Appendk B.
![Page 91: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/91.jpg)
6.2. Open questions.
The applicaîions preseated in the previous section are just a féw specific examples,
however, it is belimd that the soIutioas presented in uW thesis muid be applied in other
cases-
In the abstract of [27], Hinz mentions that H(4,n) "might be of some interest in
problems of sorting ordered instnictioos in a p d d cornputet'. By the nature of the
CTM problem, it is strongly believed that p a d e l cornputhg is, in fact, the area for direct
application of this model and more research foaised on this might show interesthg nsuIts.
During the process of this research some aaalysis on specinc 8r;iphs of the set of
valid moves in the CTM problem, where m = 2 and n = 2 and where m = 2 and n = 3,
was begua Udortunately, due to time constraints, it was not cotnpleted. It would be of
great interest to observe and analyse the charactenstics of these specinc graphs and maybe
fiom them the generai pattern to build the graphs of the CTM problem could be
determùied. From the work done, the graphs show a continious pattem. If these
patterns show âactal characteristics some of uiem may be icomorphc to other hctals,
much like the graphs of valid rnoves ofthe onguial Tower of Hanoi problem, the graphs of
the Pascal Triangle and the Sierpinski gasket, which would open a great number of
possibilities for very interesthg research using this model.
Cenainly, another question that still rernains open is the prwf of optimaiity of the
solution to H(m.n) which in tum wül lead to the proof of optimality of the solutions to the
CTM probien
6.3. Conciusions.
In this research it has been shown how, by introducing certain smd variations to
the original Tower of Hanoi puzzle, several very interesthg and challenging new
mathematical problems have been developed.
![Page 92: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/92.jpg)
The Coloured Towers Merge probIem of m t o m with n disks varied fiom the
Towa of Hanoi puzzle by increasing the mmiba ofpegs to e l , increasing the number of
towen to m. colouring each in a dinaent colour, and by h h g as objective to merge aU
disks of the same size- The Thrw Coloured Towas Merge problem is a slight dation
of the CTM problem with thne towers where instead of four there are thne pegs.
Solutions to the CTM problem with two towers and to the Three Colourd Towers Merge
problem were obtained for every peg and proved optimal. As weii, the g d solution
to the CTM problem on Peg O was obtained, where
where M0(40) = O and Mo@, 1) = m - 1.
For al1 n = m+2 and all m r2,
For ailn>mt2 and d m >3, m + t - 2
Mo (m, n) = Mo (m. r* - 2) + 2 m c 2' r=O ( ) + ~ + i ~ [ ~ - 2 - ~ ~ ~ ~ ~ ) ]
These variations were used as mthe1118tica.t modeis to solve sorting problems of
the type where ni ordered sets with n o r d d elements each have to be mergeâ together
with the restriction that the elements maintain their original order and the elements with
the same order would be priotitize according to the order of the sets.
85
![Page 93: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/93.jpg)
The use of the mathematical modeIs &&tatecl the caldation of the m b e r of
moves required to perform the sort as d as aided in the demiopment of compter
algoritbms to perform these sorts. In addition, they helped to d y s e the feasibüity
andor advantages of certain sohtious above others. .
Finaüy, it was suggested tbat fûttue studies focus on the application of these
models in the area of pataiiei cornputhg as wen as the andysis of the grapb of valid
movements, which could lead to m e r areas of application, and the proof of optimality
of the general solution.
![Page 94: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/94.jpg)
Solution of second ordcr rccurrence dations.
(In this Appendk the so1utioas presented foffow the wthods used by sandefùr in'[44]).
Let A(rrt2) = ciA(*I) + c2A(n) +An) be a second order nonhornogeneous
recurrence relation, where cl and c2 are @en constants anci f is a ninction ofn.
D&e x2 = C ~ X f cz as the chwacteMc etpatron of the above ceamence
relation. Let x = r and x = s be the roots of the cbaracteRstic equation
Al. Nonhomogeneous recumnce dation in wbichfln) b a polynomiai.
([Ml Theorem S. 1 1)
Consider the recuneace relation
(A. 1.0) A(te2) = clA(n+l) + c2A(n) +An), where the roots of its characteristic equation are r and s andffn) is an m-th order
polynomial, i.e.,An) = a j P + a,,tPL + ... + aln + a,
AI.1.Ifrt 1,sf 1 andr*sthenthegeneral solutionoftherecurrencerelation k1.0 is
of the form A(k) = dl+ + + b p + bicl)rl + ... + blk+ bo.
A. 1.2. Ifr + 1 and s +. 1 and r = s then the general solution of the reairrence relation A 1.0
is of the fom A(k) = (dl + dJ)+ + b> + b , , F + ... t b,k + b,.
A 1.3. Er # 1 and s = 1 then the general solution of the rewrence relation A. 1 .O is of the
form A(k) = dl+ + 4 + b p i + b,,F + ... + b,k2 + b&.
A 1.4. If r = s = 1 then the general solution of the recunence relation A 1 .O is of the fom
A@) =dl +q+ b p 2 + b , , W + l + ... + b,P +b&
In the four cases, dl and 4 depend on the initial vaiues and b, , where z = O, 1, ..., m,
depend onfln). These last ones can be obtained by substiMing into the remence
relation and then solving m+l equatiow for the m+l uhowns by sethg the coefficient
of the ivn te cm,..., the coefficient of the 11 terrn and the constant tem equal to zero.
![Page 95: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/95.jpg)
Suppose, for example, that we have the r-euce
A(n+2) = cLA(*1) f qA@) + ap + a, Let x2 = clx + c2 be its characteristic equaîion , wae x = r and x = s, such that
r ;t 1, s # 1 and r t s, are the roots. Hence, we have a solution of the type ~ l . l,'i.e.,
A@) = dl+ + ù# + b,k + bo.
To determitle O , and b,, we substitute into the recumnœ,
A(n+2) = dlr<**) + Qire*) + b @2) f b,,
A(n+l) = dlfi*L) + + b,(n+l) + b,,
A(n) = d , ~ + d p + b p + bo.
So, we have
d,r<W + &W2) + bl(n+2) + bo = cl(dlt(ncl) + + O I ( . l ) + bO) + cZ(d1p + @' +
b p + bO) + aln + aO.
Mer cancehg the P and s" terms, collectmg aU the teniis on the left, grouping
the oaes involving n together and factoring out the n, we have
(bi - clb, - c& - al)n + (26, + bo - q b , - clb, - c+,, - a,,) = 0.
We require to choose b, and b, so that the equation be satisfied for every value of
n. Hence we need
b, - q b , - czb, - a, = O and 2, + bo - q b , - clbo - c2b, - a, = O.
SolWig for b, and bo, we get
4 = a1 and b, = a0 +c2 - 2 . 1-cl -c* 1- c, - c,
The computatiom can be simpMed by simply omittllig the t e m clp and c2p.
This can be done since these ternis depend ody on the initial conditioas of the recurrence.
Hence, we only require to substihite A(n+2) = b,(n+2) + b, A(rrt1) = b1(*l) + bo and
A(n) = bl)t + bo into the recurrence, gMng us the same r d t s for O, and bo as above.
To obtain the values for dl and 4, we need to solve
A(0) = dl + d, + ‘70 cc, - 2 and A ( l ) = d , r + G s + a1 +a0 +c, - 2 . 1 - c, - c, 1 - Cl - c,
![Page 96: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/96.jpg)
([44] Theorem 5.14)
Consider the recwrence relation
(A.2.0) A ( M ) = clA(*l) + czA(n) + a#,
where a. a d p are @en constants and the mots of its charactefistic quation are r
and S.
A2.1. If r # p, s + p and s * r then the general soIution of the reaurence relation A.2.0 is
ofttse form A&) = d,r' + + b&
A2.2. Ifr # p and s + p and r = s then the general solution of the recurrence relation k2.0
is of the form A@) = (d, + @)+ + b&.
A2.3. Ifs # p and r =pl then the general solution of the reaurence relation A2.0 is of the
fomi A(k) = 4& + (dl + b&)+-
A2.4. Er = s = p then the general solution of the remence relation A2.O is of the form
A(k) = (d, + 4 k + b,,k2)rC.
In the four cases, dl and d, depend on the initial values and b, can be obtained by
substituting into the recurrence relation.
![Page 97: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/97.jpg)
The procedure TraasImr transfers a mixed tower of size rn fiom peg x to peg z us* y as d a r y peg, inverting the colour order of the mth pair of disks. This corresponds to hction T(2.m).
The procedure T d e r -ers a mixed tower of size m h m peg x-to peg z using y as d a r y peg, maintahhg the colour order of ail the disks. Tbis comsponds to hction T(2,m).
Pop ftom (Push to) peg[x] refers to remove the top dkk @sert the removed disk) on peg x
TrQ7tSIm(m-i,x,z, y); Popfiom pe8I~l~ Push tu&];
Popfrom pegCx1; Push to peg[z]; Trd'(m-i,y,x,z) ;
end; {else) end; f lrmsl i i )
![Page 98: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/98.jpg)
The pcocedwe MergeCInv merges two towers on Peg 2 with the berted COIOLK order for the mh pair and the correct colour order for the RSt. ThiS corresponds to M o n M'42,n).
The procedure Me@ merges two towers on Peg 2 with the c o r n colour order. This corresponds to bction M&).
MergeCInv (n:lnleger); Me@ (n: Infeger);
begm Vn=l ihen ksm Popfrom pegC01:
to p g m ; po~fiom peg[l]; pldl îo pegpj;
e?ui fi3 e k
fn=2 tkn
k8in P o p m n peg[OI;
to peg[I]; Popfiom pegC~I; Push io peg[2/; Tramhv(., 1.2. O) ; Popfiom peg[fl; Push to peg[2]; Trms$er(l. 0.1.2);
end (iB el' begin
MergeCIm(n-2); Popjrom pegr01; Push to peg[I]; TrcmsInv(ii-2,2. O, 1); po~from pegP1; h s h 20 peg[]; Trdnv{n-1.1.2. O); Popfnm pegfll: Push to peg[]; Tta@er(n-1. O, 1.2);
end; teLe) end; WergeC}
![Page 99: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/99.jpg)
Procedure MergeA merges two towers on Peg O with the correct colour order. This corresponds to W(2,n).
Procedure Mer@ merges two towers on Peg 1 with the correct wlour order. This conesponds to M1(2,n).
MergeA (n: Inieger); M i B (in: Iweger); .
kgin 0 - 1 tiren bel@ p o ~ f i m ~ g r w Pus. to peg[2]: POP l iom pegI0I: puda 10 peg[fI; P o P I ~ o ~ pegt-1: Pwh to peg[l];
end fi3 else begh
MergeR(n-l); Popfiom p e g m Push 10 peg[2]; TrQltSlm(n-1, O, 1,2); Popfrom pegP];
- Push to peg[I]; Trca2sii(n-I, 2.1, O); POP Pom pegP1; P d to peg[l]; Trcntsfw(n4, û, 2.1);
enci; (else) end; WergeeB)
![Page 100: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/100.jpg)
REFERENCES.
R E. AUardice and AY. Fraser. La Tour d'Hanoi. Prcu. GfMurgh Mdh. Soc. 2 (1884), 50-53. J. P. Mouche, D. Astoo- J. Randail and J. Shaliit. Morphisms, Squarefiee Strings, and the Tower of Hanoi Puele. Amer* Màth Month& 101 ( l m ) , 651- 658, M. D. Atkiasoa The cyclic Towers of HawL IIi#oanr. Proicess. Lett 13 (1981), 118-1 19. A Brousseau. Tower of Hanoi with more pegs. J Recreatromî Mafk 8 (1976), 169-178. P. Buneman and L. Levy. The Towers of %moi Problem. I'ionn. Prucess..Leit. 10 (1980), 243-244. P. C d and E. F. Ecklund, Ir. On the Towers of Hanoi and generalized Towers of Hmoi probiems. Congr. N i e r . 35 (1982). 229-238. P. Cd and E. F. Ecklmd, Jr. Towers of Hanoi and analysis of algonthms. Amer. Maih Monthly 92 (1985), 407-420. P. Cd and C. Gerety. 1s Towers ofHanoi r d y hard?. Congr. N i e r * 47 (1985). 23 7-242. A K ~ewdney The Amchair UnÏverse. W. H Fr- New York 1986. K E. Dudeney. The Cmterhqy P d e s and Other Cun'ous Problems. E.P. Dutton, New York, 1908; Fourth edition, Dover Publications, hc., Mineola, NY, 1958. M. C. Er. A representation approach to the Tower of Hanoi Problem. C o m w J. 25 (1982), 442-447. M. C. Er. An iterative solution to the generalized Tower of Hanoi Problem. BIT 23 (1 983). 295-302. M. C. Er. An analysis of the generalizsd Tower of Hanoi Problern. BIT 23 (1983), 429-43 5. U C. Er. The generaiized Towers of Hanoi Problem J. Inform. Oprim. Sci. 5 (1984), 89-94. M. C. Er. The cyclic Towers of Hanoi: A representation approach. Cornput. J . 27 (1984), 171-175. M. C. Er. The generalized colour Towers of Hanoi: An itaative algorithm. Conpflf, J. 27 (1984), 278-282. M. C. Er. A generaiization of the cyclic Towers of Hanoi: An iterative solution. htemat. A Comp~~t. Math- 15 (1984). 129-140. M. C. Er. The complexity of the genedhed cyclic Towers of m o i Problem. J Algorifhs 6 (1985), 3 5 1-3 58. M. C. Er. An optimal aigorithm for Reve's puzzle. Inform. Sci. 45 (1988). 39-49. T. J. Fountain. P d l e l Computng, principles and pructice. Cambridge Univ. Press, 1994. J. S. Frame. Solution to Problem 39 18. Amer. Muth Monthly 48 (1941), 2 16-2 17.
![Page 101: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/101.jpg)
M. Gardner. nK Sciennïpc American Book of Mathematical Pucles md Diversiom. Simon and Schuster, NY, 1959; reviœsed editioa, Hexoflexc~gons and Other MofhematidDiversio?t~. U& of Chicago Press, Chicago, 1988. M Gardner- Knoied Daughts and Otkr Mhthelltan-cd EntettQimnents. W. H. Freeman, NY, 1986. R L. Graham, D. E. Knuth and 0. Patashaik, Conmete Mafhe-a Addison- Wesley, Reading, M& 1989. P. J. H&yeses A note on the Towers of b o i probim C O ~ W . J. 20 (IWO), 243- 244- A M. Him. The Tower o f m o i . Enrei' Mah. 35 (1989), 289-321. A M Hinz An itemive algoritbm for the Tower of Hanoi with four pegs Cornpumg 42 (1989), 133-140. A U Hiaz and A. Schief. The average distance on the Sierpinski gasket. Pro&. Th. Rel. F ie l ' 87 (1990). 129-138. R L. Kruse. Data Smcfures und Program DeSigri. Second edition, Preatice-HaU, Iac. 1987. 1, Lavdée. Note sur le problème des Tours de moï. Rev. R0tnn-e Math Pures AppL 30 (1985). 433-438. X M Lu Towers of Hanoi graphs. Internat J. Comput. M d 19 (1986), 23-38. X. M Lu. Towers of Hanoi with arbitrary W pegs. Intemat. J Cornput. Math. 24 (1988), 39-54. X M. Lu. An iterative solution for the 4peg Towers of Hanoi. Cornput. J. 32 (1989), 187-189. W. F. Lumon. The Reve's Puzzle. Conput. J . 29 (1986), 478. B. Mandelbrot. The Fracmi G e o m e ~ of Nature. W. K Freemih, San Francisco, 1982. S. B. Maurer and A Ralston. Dimete Afgwithmic Mathenidm. Addison-Wesley, Reading, MA, 1990. S. Minsker. The Towers of Antwapen Problem. Infcw. Proces. Lette 38 (1991), 107-1 11. L. Nyhoff and S. Lus- Dala Structures md Program Design rh PCISCQI. Second edition, Macmillan Publishing Co. 1992. K de Parville. La Tour d'Hanoi et la question du Toakin. La N a r e 12 (1884), 285-286. D. G. Poole. The Bottleneck Towers of Hanoi Problem. J , Recreah'onaI Math. 24 (1 W2), 203-207. D. G. Poole. The Towers and Triangies of Professor Claus (or, Pascal Knows Hanoi). M& Magmine 67 (1994). 323344. K. H. Rosen. Discrete Muthemuzics and Its Appficatiom. Third edition, McGraw- EWI, Inc. 1995. T. Roth The Tower of Brahma revisited. J RecreatioMI Muth 7 (1974). 1 16- 1 19. J. T. Sandefur. Discrete QymmicaI Systems. Theory d Applcah'o~ts. Mord Univ. Press, N,Y. 1990. R S. Scorer, P. M- Grundy and C. A B. Smith. Some binary games. Mah. Ga. 28 (1944), 96-103.
![Page 102: ON THE TOWER HANOI PUZZLE APPLIED'TO A TRENT- · Lupita y Rodoüio Barraam, mis hermaaas Diana e Ivette, y al resto de la familia for m amor ... Lupe por constniirme el mode10 de](https://reader036.fdocuments.us/reader036/viewer/2022063002/5f21eee83b42654f28071599/html5/thumbnails/102.jpg)
46. B. M. Stewart. Solution to Problem 3918. Amer. Marrh Monthly 48 (1941). 2 17- 219.
47- L Stewart. Les fbtds de Pascal. P m h Scfence 129 (1988), 100-104. 48. M S v d Divisibüity - with visiiüay- M d lnfeI@mcer 10 (1988), 5 6 4 . 49. T. R Walsh The Towas of m o i revisited: Mov@ the rings by counting the
m o w . ii@orm. Proces. Le#. 15 (1982). 64-67. 50. S. W o b Geometry of binomisl d c i e n t s - Amer. Mmh Mcnfhiy 91 (1984),
566-571. 5 1- D. Wood, The Towers of B ~ ~ ~ I X M L and Himoi revisitd J. RecreattolliOI Mah 14
(198 1). 17-24. 52. A J. van Zanten. An Optimal Algorithm for the Twin-Tower Problem. De@ Progr.
Rep. 15 (1991) 33-50.