Jul 7, 1998 - of Hanoi games where the gameboard contains more than three pegs. ... The game best known as Towers of Hanoi is played by a single player.
Exponential Lower Bounds for the Towers of Hanoi with More Than Three Pegs Mario Szegedy
ATT Research July 7, 1998 Abstract In this we paper we consider the version of the classical Towers of Hanoi games where the gameboard contains more than three pegs. 1=k ?2 k For k pegs we give a 2 lower bound on the number of steps necessary for transferring n disks from one peg to another. Apart from the value of the constants C this bound is tight. C n
k
1
Introduction
The game best known as Towers of Hanoi is played by a single player using three pegs and n disks with the following set of rules: Originally the disks are arranged on the rst peg, largest at the bottom and each disk sitting on a larger disk. The goal of the game is to transfer the n disks to another peg while observing the following conditions: 1. In each step the topmost disk on a peg is removed and placed on the top of the disks on another peg. 2. A disk cannot be placed on a disk smaller than itself. The objective is to minimize the number of steps. The game has become a popular example for recursive algorithms (see e.g. [1] ). 1
The unique solution which requires 2 ? 1 steps is well understood and has been proven to be be optimal. Lovers of the game developed various versions of it [2], [3], [6]. A generalization in which more than three pegs are allowed ([2], [3]) has been puzzling the mathematicians for decades. A number of diernt algorithms have been invented that solve the problem within exactly the same number of disk moves ([2],[5] ), but their optimality is unproven. More precisely, all known algorithms adhere to a certain scheme with parameters which have been shown to be optimal for these algorithms (see e.g. [4]), but there is no guarantee that other kind of algorithms cannot do the same task within a smaller number of moves. We denote the number of pegs by k and the number of disks by n. De ne h = k ? 2 and n = . Set s such that n ? < n n :. The known algorithms require n
(h+s)!
h;s
h;s
1
? X 2 (n s
1
t
h!s!
h;s
? ) + 2 (n ? n ? )
h
s
1;t
h;s
(1)
1
t=0
disk moves when transfering the pile of disks from the rst peg to the second peg. Equivalently, we can interpret Equation (1) so that the addition of a new disk in the best known algorithms for the k peg version increases the number of steps to be performed by 2 if we already have n ? 1 disks, where s is de ned by n ? n ? 1 n . (The formula that appear in [2] can be shown to be equivalent to the above.) The order of magnitude of the formula of the k peg case is 2 k 1=k?2 where B = (1 + o(1))(k ? 2)! ? : 1=k ?2 k Our main result is an uncoditional 2 lower bound for the number of necessary moves to solve the k pegs version of the Towers of Hanoi game, which is optimal up to a constant factor in the exponent. s
h;s
1
h;s
B n
1=k
2
k
(1+o(1))C n
2
The Lower Bound
Our lower bound will hold in a more general setup, namely when our only requirement is that between the initial and the nal con guration each disk moves at least once. This generalization will allow us to use an induction. Getting the precise bound on the original problem might require a dierent kind of argument. 2
De nition 2.1 We call an arrangement of the disks con guration if
it obeys the \smallest disk on top of the larger" rule. For a con guration D of the disks let g (D) be the minimal number of the steps required to get every disk moved at least once. (We remark here this is a nite number for every con guration.) Let us denote min g (D) by g(n; k); where the minimum is taken over all possible con gurations D of n rings on k pegs.
Theorem 2.2 For k 3 g(n; k) 2
?
1=k 2
(1+o(1))Ck n
:
Here the constants C depend on k in the following way: ? : C = 21 ( k(k12? 1) ) Consequence 2.3 The k peg version of the Towers of Hanoi problem 1=k ?2 k requires at least 2 ? steps. k
1=k
2
k
(1
o(1))C n
Proof of the Theorem 2.2: We proceed by induction on k: The case k = 3: We can suppose that n 2. Consider an arbitrary initial arrangement of n disks. Suppose S is a sequence of the steps in which every disk moves at least once. Let j denote the rst step that moves the largest disk. Let S be the initial segment of the steps preceding j , and S the terminal segment of steps following j . In the last con guration of S and in the rst con guration of S the disks other than the largest disk are piled up in a single tower. On the other hand in either S or in S the second largest disk (which is at the bottom of the pile) should move at least once. The segment in which this happens contains a sequence of steps that is a solution to the three peg, n ? 2 disk Towers of Hanoi problem, so is at least 2 ? long taking into account the step of the second largest disk as well (see e.g. [6] for this estimation). To estimate the length of S add one to this quantity for the step j . We obtain: g (n; 3) 2 ? + 1 (and in fact here equality holds). The case k 4: First we prove a lemma which serves as the main lemma in our argument: 1
2
1
1
2
2
n
n
Lemma 2.4 Suppose k 4 and 0 < m < n=2k: Then: g(n; k) 2 min(g(n ? 2km; k); g(m; k ? 1)): 3
2
2
Proof of Lemma 2.4: We say that a sequence S of steps moves a set H of disks if for every h 2 H there exists a step in S made by h. Let us call S (small disks) the set of the smallest n ? 2km disks. Consider an arbitrary con guration D of the disks around k
pegs. There is a peg around which we have at least 2m disks from the largest 2km disks. Let us call X (extra large disks) the set of the largest m disks in this peg. Let us call L (large disks) the set of the next largest m disks in this peg . Note that X and L depend on D while S does not. Clearly S , L and X are disjoint, j X j=j L j= m, j S j= n ? 2km. Moreover every disk in X is larger than any disk in L and they are all larger than any disk in S . Consider a sequence of steps that moves all the disks starting from the initial con guration D. De ne S as the initial segment of steps taken before the rst step by the topmost disk of X and S as the segment beginning with this step and all the steps after. Obviously S moves L and S moves X . Moreover if S does not move S then the peg on which an idle member of S is sitting is completely useless for the disks in L since they are all larger than any of the disks in S . This allows us in this case to estimate the number of steps made by the elements of L by g(m; k ? 1): The same argument shows that S either moves S or only k ? 1 pegs were used when making the steps with the disks in X . Since according to the above argument both S and S contain at least min(g (n ? 2km; k); g (m; k ? 1)) steps the proof of the lemma follows. Let us denote log g (n; k) by (n; k): Corollary 2.5 For k 4 and 0 < m < n=2k (n; k) 1 + min((n ? 2km; k); (m; k ? 1)) holds. Lemma 2.6 (n; k) is a monotone increasing function of n for any xed k 3. Lemma 2.6 follows from the fact that extra disks just make the task harder. Lemma 2.7 Suppose k 4 and (n ; k ? 1) i for i = 1; ::; s: Then 1
2
1
2
1
2
1
2
X n ; k) s: i
(2k
s
i
i=1
4
2
Proof of Lemma 2.7: We proceed by induction on s. The s = 1 case is straightforward. For s 2 : (2k
X n ; k) = (2kn s
i
s
+ 2k
? X n ; k) s
1
i
i=1
i=1
1 + min((2k
? X n ; k); (n ; k ? 1)) s: s
1
i
s
i=1
The rst inequality comes from the corollary of Lemma 2.4, the second comes from the induction hypothesis on s ? 1 and the assumption of the lemma on (n ; k ? 1): s
Lemma 2.8 Suppose the Theorem holds for k ? 1: De ne n as the smallest element of the set fn j (n; k ? 1) ig. Then: i
X n (1 + o(1)) s
i
i=1
s? : (k ? 2)C ?? k
2
k
3
k
1
Proof of Lemma 2.8: Since according to our assumption the theorem holds for k ? 1 we have the (1+ o(1))C ? n ? lower bound on (n; k ? 1): Combining this with the monotonicity of (n; k ? 1) in n we get the asymptotic upper bound on the integral of the inverse required by the lemma. k
1
1=k
3
Now we are ready to prove the Theorem for k assuming that it is P true for k ? 1: Let us denote n by N . From Lemma 2.8 we have N (1 + o(1)) ? k?k2?3 . On the other hand Lemma 2.7 says that k ?1 (2kN ; k) s: for every s: These two inequalities provide us with an asymptotic upper bound on the inverse of (n; k), which can be easily turned into the following asymptotic lower bound on (n; k) using the monotonicity in n: k ?3 (k; n) (1 + o(1))C ? k?2 ( k 2?k 2 ) ? n ? : k ?3 Calculation shows that C = C ? k?2 ( ? ) ? : s
i
i=1
s
2ks
s
(k
2)C
s
1=k
k
k
k
2
k
2
1
1
k
2
1=k
2
2k
Acknowledgement: The author wishes to thank L. Csirmaz for suggesting the more-than-three-pegs problem and for his useful comments and A. M. Hinz for making corrections in the manuscript. 5
References [1] A.V. Aho, J.E. Hopcroft, J.D. Ullman, Data Structures and Algorithms, Addison-Wesley, 1983 [2] S. Biswas and M.S. Krishnamoorthy, The generalized Towers of Hanoi, Unpublished manuscript, 1978 [3] Br.A. Brousseau, Tower of Hanoi with More Pegs, Journal of Recreational Mathematics, 8:3, pp. 169-176, 1976 [4] J.S. Frame, A Solution to AMM Problem 3918 (1939), American Mathematical Monthly, 48, pp.216-217, 1941 [5] A. M. Hinz, An iterative algorithm for the tower of Hanoi with four pegs, Computing 42, pp. 133-140 (1989) [6] S. Minsker, The towers of Hanoi rainbow problem: coloring the rings, to appear in J. Algorithms [7] D. Wood, Towers of Brahma and Hanoi Revisited, Journal of Recreational Mathematics, 14:1, pp.17-24, 1981-82
6