Download presentation

Presentation is loading. Please wait.

Published byAmya Rokes Modified over 3 years ago

1
On Optimal Solutions for the Bottleneck Tower of Hanoi Problem Yefim Dinitz Shay Solomon Dept. of Comp. Sci., Ben-Gurion University ISRAEL

2
Contents of the lecture 1. Background on the Tower of Hanoi. 2. The Bottleneck Tower of Hanoi (BTH) problem. 3. The family of all optimal solutions to BTH. 4. Investigation of the configuration graph of BTH: its diameter and average distance.

3
1. Background The first version of the puzzle was marketed by Edouard Lucas in 1883, under the name "Tower of Hanoi: - Given are 3 pegs, denoted by A,B and C, and n disks of distinct sizes placed on peg A in decreasing order, largest at the bottom to the smallest at the top. - The goal of the puzzle is to transfer all disks to peg C, placed in the same order, by the minimum possible number of moves. - The rules are to move a single disk from (the top of) one peg to (the top of) another one at each step, following the "divine rule": to never have a larger disk above a smaller one.

4
1 2 … n-1 n A B C Example for general n Move number

5
1 2 … n-1 A B C The optimal transfer for general n n Move number C n-1

6
1 2 … n-1 A B C n Move number C n-1 + 1 The optimal transfer for general n

7
1 2 … n-1 n A B C Move number 2 C n-1 + 1 The optimal transfer for general n

8
The recurrence formula is c n = 2c n-1 + 1, c 1 = 1. Hence, c n = 2^n -1. This classical Tower of Hanoi problem with three pegs is a basic problem, taught as a basic example of a recursion program.

9
There is a great proliferation of new ToH puzzles posed over the last twenty years. There is a bibliography made by Paul Stockmeyer, which covers over 350 papers on the subject.

10
In 1981, D. Wood posed the following generalization of ToH, which we call the Bottleneck Tower of Hanoi Problem, BTH n= BTH n,k, depending on an integer parameter k, k>0. 2. The Bottleneck ToH problem

11
The k-relaxed Placement Rule: Besides the usual placement of smaller disks above bigger ones, a bigger disk j may be placed above a smaller disk i, if their size difference j - i < k. i+k …. i

12
A placement of the n disks [1..n] on a single peg is called a tower of n disks. The decreasing bottom-top placement of the n disks [1..n] on a peg is called the perfect tower. 1 2 3 … n-2 n-1 n Definitions

13
Description of BTH n : There are 3 pegs: A,B, and C. The goal is to transfer the perfect tower on peg A to the perfect tower on peg C. The placement rule is k-relaxed. (Note that if k=1, we arrive at the classical problem.)

14
12376541237654 Example: k=4, n=7 Legal We note that there are many legal towers for a given k. As k grows, there are more legal towers. (The two extreme) examples: k=1, one legal tower (perfect tower). kn, n! possible towers.

15
D.Poole [1992] suggested the sequence of moves α n (described in the next slide), which solves BTH n. He showed its optimality within just one simple strategy. Beneditkis, Berend, and Safro [1998] proved its optimality for the case k=2. We proved optimality of α n for the general case [ISAAC2006]. Remark: another proof of optimality of α n for BTH n, by different techniques, was suggested independently by Xiaomin Chen et al. (unpublished).

16
α n (A,C) (not explicitly) 1.(*) Move disks [1..(n-1)] from A, by the minimum possible number of moves, to any (legal) state on B. 2. Move disk n from A to C. 3.(*) Move disks [1..(n-1)] from B to the perfect tower on C, by the minimum possible number of moves.

17
1 2 3 4 …. n-1 n A C B

18
[1..n-1] n A C B

19
A C B n

20
n A C B 1 2 3 4 …. n-1

21
Somehow tower-move(*): To move a tower of m disks on one peg, to a tower of m disks on another peg, in any order. D. Poole and BBS used, for the somehow problem, the following optimal sequence of moves, β m :

22
β m (source,target): (for the explanation, assume that the initial configuration is perfect) If m k, move all disks from source to target one by one. Otherwise: 1. Recursively perform β m-k (source,auxiliary). 2. Move k disks [(m-k+1)..m] one by one from source to target. 3. Recursively perform β m-k (auxiliary,target).

23
12345671234567 K=4, m=7 source auxiliary target

24
45674567 321321

25
321321 76547654

26
12376541237654

27
1 2 3 4 5 6 7 8 9 10 11 K=4, m=11 source auxiliary target

28
8 9 10 11 12376541237654 source auxiliary target

29
11 10 9 8 12376541237654 source auxiliary target

30
1 2 3 4 5 6 7 11 10 9 8 source auxiliary target

31
(**) We remark that, if we start with the perfect tower on A, and perform β m (A,B) followed by β m (B,C), the result is the perfect tower on C.

32
α n (A,C), reformulated 1. perform β n-1 (A,B). 2. Move disk n from A to C. 3. perform β n-1 (B,C). By earlier remark (**), α n solves BTH n.

33
1 2 3 4 …. n-1 n A C B

34
n A C B 1 2 3 …. n-k-1 n-1 …. n-k+1 n-k

35
A C B 1 2 3 …. n-k-1 n-1 …. n-k+1 n-k n

36
n A C B 1 2 3 4 …. n-1

37
Notation and numerical results b m = The number of moves in β m a n = The number of moves in α n b m = 2b m-k + k ; b 1 = 1,…, b k = k. b m = r ( 2^q) + k (2^q -1), where m = qk +r. a n = 2b n-1 + 1 ; a 1 = 1. a n = r (2^(q+1)) + k (2^(q+1) -2) + 1, where n-1=qk + r.

38
3. Family of all optimal solutions to BTH n We prove that, in any optimal solution to BTH n, disk n makes only one move, from peg A to C. Before that move, all disks 1,…,n-1 have been moved from peg A to peg B. After that move, all disks 1,..,n-1 will move from peg B to peg C.

39
Is α n the unique optimal solution? In the case k=1, the answer is yes (and is well known): there exists a unique solution for the classical problem. For the case k 2, the answer is No! Let us see a different sequence of moves, of the same length as that of α n :

40
1 2 3 4 5 6 7 8 9 10 Example n=10, k=3 A B C

41
4 5 6 7 8 9 10 321321 A B C

42
7 8 9 10 654654 321321 A B C

43
123654123654 7 8 9 10 A B C

44
987987 123654123654 10 A B C

45
987987 654654 3 2 1 10 Until this point, the move- sequence is the same as α n A B C

46
3698736987 5454 2 1 10 A B C

47
25369872536987 4 1 10 A B C

48
142536987142536987 10 A B C

49
142536987142536987 10 A B C

50
987987 3 2 1 10 654654 A B C

51
987987 10 123654123654 A B C

52
7 8 9 10 123654123654 A B C

53
7 8 9 10 654654 321321 A B C

54
4 5 6 7 8 9 10 321321 A B C

55
1 2 3 4 5 6 7 8 9 10 A B C

56
Tower-Move tower-move – A sequence of moves that transfers a tower on one peg to a tower on another peg. For example: - α n is a shortest perfect-to-perfect tower-move of n disks. - β m is a shortest somehow tower-move of m disks.

57
General structure of an optimal tower-move It should be similar to the structure of the (recursive) classic Tower of Hanoi solution, but the transfer unit is a block of k disks (as in the example). Main Proposition 1: The only possible change, in an optimal solution, may be to interleave the two upper blocks. Main Observation 2: The ways of interleaving, each time, are independent.

58
How many optimal solutions exist? Any optimal solution (i.e., a shortest p.t.p. tower move of [1..n]) contains 2^((n-1)/k-1) tower- moves of the union of the two upper blocks. For any such even-numbered tower-move, except for the last tower-move, its final configuration can be chosen arbitrarily from a certain set (**) of C(k+r,k)-C(k+r,k+1) configurations. These are the only choices, for an optimal solution.

59
An auxiliary problem equivalent to (**): Let n t+p. What is the number of integer solutions that satisfy the two following conditions: xi =n, i=[0..t], xi0. xi j+p, 0j n-p, i=[0..j]. How many such configurations exist?

60
The number of different solutions to (**) is: C(n+t,t) – C(n+t,t+p+1)

61
The number of all optimal solutions to BTH n is: k 2: (C(k+r,k)-C(k+r,k+1))^[ 2^((n-1)/k-2) -1], where r= (n-1) mod k. k=1: A unique optimal solution

62
4.1 Diameter of the configuration graph Questions : 1. Find a pair of disk arrangements over A,B and C, requiring the longest sequence of moves in order to get from one to the other. 2. Find the length of that sequence (later referred as diameter). Let us translate these questions to the language of graphs:

63
For BTH n, the corresponding configuration graph, G=(V,E) is the (undirected) graph s.t.: V is the set of all legal arrangements of the n disks over A, B and C. E = {e=(u,v)| u,v in V, s.t. u and v are reachable one from the other by a single move}.

64
The configuration graph for the case n=2,k=2 (2,1),(),() (2),(1),() (2),(),(1) (),(1,2),() (),(1),(2) (),(),(2,1) (1),(),(2) (),(),(1,2) (1,2),(),() (),(2),(1) (),(2,1),() (1),(2),()

65
The diameter is 4 (2,1),(),() (2),(1),() (2),(),(1) (),(1,2),() (),(1),(2) (),(),(2,1) (1),(),(2) (),(),(1,2) (1,2),(),() (),(2),(1) (),(2,1),() (1),(2),()

66
We found the answer for the second question, i.e. the diameter, D(n,k), up to a constant factor. D(n,k) = Θ((k^2)2^(n/k)) This is k times the shortest length of a perfect-to-perfect tower-move. Reminder: a n = Θ(k 2^(n/k))

67
Tighter bounds for D(n,k): Let n k D(n,k) = Θ(nlogn). Let k n 2k D(n,k) = Θ(nlogn + (n-k)^2). For n>2k: D(n,k) = Θ((k^2)2^(n/k)).

68
We believe (based on similar open questions raised by D. Knuth) that both afore- mentioned questions: 1. Finding a pair of disk arrangements requiring a longest sequence of moves. 2. Finding the length of that sequence (i.e, the previously mentioned diameter) exactly. should be difficult even for the (degenerate) case nk.

69
4.2 Average distance We find the average number of moves required to get from one configuration to another, taken over all pairs of configurations, up to a constant factor. In other words, we bound the average distance between nodes in the configuration graph of BTHn.

70
We prove that the average, Avg(n,k), is asymptotically the same as the afore- mentioned diameter. For n 3k: Avg(n,k) = Θ (D(n,k)) = Θ ((k^2)2^(n/k)) This is k times the shortest length of a p.t.p. tower-move.

71
Avg(n,k) for some values of n vs. k: Let n k: Avg(n,k) = Θ(D(n,k)) = Θ(nlogn). For n>3k: Avg(n,k) = Θ(D(n,k)) = Θ((k^2)2^(n/k)).

72
In our paper at ISAAC06, we considered optimal algorithms for ToH problems with generalized placement rules. We appreciate your attention.

73
The w ay of proof (for diameter) Upper bound: We show an explicit way to transfer any tower of n disks in O((k^2)2^(n/k)) moves.

74
Lower bound Observation. When any disk out of the k biggest disks [(n-k+1)..n] moves, all n-2k disks in [1..(n- 2k)] should be on the spare peg. We show two configurations of the k biggest disks, such that any tower-move between them requires Ω(k) changes of the spare peg. As a consequence, for those configurations and the case n>2k, Ω(k) tower-moves of the n-2k smallest disks are required. As we know, each one of those tower-moves requires Ω(k2^((n-2k)/k)) moves.

Similar presentations

Presentation is loading. Please wait....

OK

Recursion Lecture 18: Nov 18.

Recursion Lecture 18: Nov 18.

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google

Ppt on ergonomics computer workstations Ppt on channel estimation Ppt on exim bank of india Ppt on forward rate agreement quotes Ppt on review of related literature meaning Ppt on birds and animals Ppt on span of control Ppt on traditional methods of water harvesting Ppt on sobel edge detection Ppt on road signs in india