Professional Documents
Culture Documents
BF 01933618
BF 01933618
AN ANALYSIS OF THE
GENERALIZED TOWERS OF HANOI PROBLEM
M. C. ER
Department of Computing Science, The University of Wollongong, P.O. Box 1144, Wollongong,
N.S.W. 2500 Australia
Abstract.
A state-space graph for representing the states and their transitions of n discs on three pegs is
formulated. It is then transformed to a shortest-path tree for representing the shortest paths in
transferring n discs in any configurations to a specified peg. The shortest-path tree clearly
characterizes the generalized Towers of Hanoi problem ; and its use leads to a very simple analysis
of the generalized problem. The best-case, the worst-case and the average-case complexities are
analyzed.
1. Introduction.
2. State-space graph.
AAA
J-- L
CCA
ACA
ABBAC~Cd :BAB
3. Shortest-path tree.
The goal of the generalised problem is to move all discs to a specified peg;
such a goal node is one of the three extreme vertices of the state-space graph. If
such a goal node is treated as a root and all non-shortest paths between the
goal node and other nodes are removed, the result is a tree - we call it the
shortest-path t r e e . It is a tree because the shortest paths between the goal node
and any nodes are unique. The uniqueness follows from the mirror-symmetry
432 M . C . ER
4. Analysis.
BAA CAA
ABC
7 7 7 7 7 7
/\
7
ACC
7
BBB eBB CAB AAB AAC BAC BCC CCC
Figure 2. A shortest-path tree for the generalized Towers of Hanoi problem with three discs.
Mbest(n) = 0. (1)
The number of such instances is only 1 ; and thus we have a probability of 1/3".
n(0) = 1
Let L(n) be the number of leaves of T(n) at the lowest level. From the way the
shortest-path tree is recursively constructed, we obtain
The closed-form solution is L(n)= 2". Thus, the number of the worst-
cases is 2"; and thus the probability of occurrence is 2"/3". Eq. (2) is equal to the
complexity of the standard problem ; and indeed the standard problem contains
only two instances of the worst-case configurations of discs. There are other
configurations of discs which can give rise to the worst-case complexity; and the
worst-case complexity of the generalized problem is not worse than the
complexity of the standard problem. This is a somewhat surprising result.
(4) Vo = O.
Solving the recurrence Eq. (3) with Eq. (4),we obtain the foUowing closed-form
solution
M . . . . . ge(n) = V./3"
or
5. Concluding remarks.
In this paper, the state-space graph is used to represent the states and the
transitions of moving n discs to other configurations. Many interesting
properties of the state-space graph are also discussed. The state-space graph is
then transformed to the shortest-path tree which represents the shortest paths of
transferring n discs in any configuration to a specified peg. The shortest-path
tree simplifies the analysis of the generalized Towers of Hanoi problem
tremendously. In particular, the best-case, the worst-case and the average-case
complexities of the generalized problem are analyzed. Of particular interest is
the average-case complexity of the generalized problem, which is shown to be
2/3 of the complexity of the standard problem. Also, the worst-case complexity
of the generalized problem is shown to be not worse than the complexity of the
standard problem.
Acknowledgements.
The author is indebted to the referee for his many valuable comments and
suggestions. The work was supported by the RGC under grant 05-143-105.
REFERENCES
1. P. Buneman and L. Levy, The Towers of Hanoi problem, Information Processing Letters 10
(1980) 243-244.
2. E. W. Dijkstra, A short introduction to the art of programming, EWD316 (1971).
3. M. C. Er, A representation approach to the Tower of Hanoi problem, Computer Journal 25 (1982)
442-447.
4. M. C. Er, The generalized Towers of Hanoi problem, Information Processing Letters (in press).
5. M. C. Er, An iterative solution to the generalized Towers of Hanoi problem, Technical Report,
Department of Computing Science, University of Wollongong (1982).
6. P. J. Hayes, A note on the Towers of Hanoi problem, Computer Journal 20 (1977) 282-285.