• 沒有找到結果。

Iterative Algorithm of Parallel Moves

CHAPTER 6 ITERATIVE ALGORITHM OF PARALLEL MOVES

6.2 Iterative Algorithm of Parallel Moves

Now we describe our iterative algorithm to implement the towers of Hanoi problem with parallel moves. First we define disk groups.

[Definition 7] Disk group

If n

∈ odd, let disks 1-3 be as group-1, disk 4-5 as group-2, disk 6-7 as

group-3, … so there will be (n-1)/2 groups. Otherwise, n

∈ even, let disks 1-2 be

as group-1, disk 3-4 as group-2, disk 5-6 as group-3, … , so there will be n/2 groups.

And then, define all group moves as follows.

[Definition 8] Group-1 move for disks 1-3: 5 parallel moves

Consider source peg is A, (1) destination peg is B or C, (2) the first move of disk 1 to peg B or C, and (3) the last move of disk 1 from non-destination two pegs, so there are total 8 types of group-1 move for disks 1-3 with 5 parallel moves.

(a) (b)

(c) (d)

(e) (f)

(g) (h)

Figure 6.2a Total 8 types of group-1 move for disks 1-3 with 5 parallel moves.

[Definition 9] Group-1 move for disks 1-2 : 3 parallel moves

Consider source peg is A, (1) destination peg is B or C, (2) the first move of disk 1 to peg B or C, and (3) the last move of disk 1 from non-destination 2 pegs, so there are total 8 types of group-1 move for disks 1-2 with 3 parallel moves.

(a) (b)

(c) (d)

(e) (f)

(g) (h)

Figure 6.2b Total 8 types of group-1 move for disks 1-2 with 3 parallel moves.

[Definition 10] Other group move for disks i-(i+1) : 3 parallel moves

Consider source peg is A, (1) destination peg is B or C, so there are two types of other group moves with 3 parallel moves.

(a) (b)

Figure 6.2c Two types of other group moves with 3 parallel moves.

Now we present our optimal parallel iterative algorithm as follows.

[Algorithm 2]

Parallel_Hanoi(n, A, B) //move n disks from peg A to peg B//

{

IF

n/2group ∈ odd, then assign the cyclic order A? B? C? A;

// n ∈ odd, there are (n-1)/2 groups; n ∈even, there are n/2 groups//

ELSE assign to them the cyclic order A? C? B? A;

(1) Move* the smallest group to the next peg in the cyclic order;

(2) IF all groups are on the same peg, then EXIT();

ELSE move** the second-smallest top group onto the peg

not containing the smallest group and goto (1);

}

* : First selecting group-1 move among 8 types : the first move of disk 1 to the peg not containing the above second-smallest top group, and the last move of disk 1 from the peg not containing the next second-smallest top group. And then, we can combine the first move of disk 1 with the last move of the above second-smallest top group move, and the last move of disk 1 with the first move of the next second-smallest top group move.

**: Combine the first move with the last move of the above smallest group move, and the last move with the first move of the next smallest group move.

[Theorem 6.1] The above iterative parallel algorithm is optimal.

Proof: Consider Algorithm 1 with n disks, there are total 2n – 1 disk moves;

2n-1 for the smallest disk, and 2n-1 – 1 for the second-smallest disk. Now consider Algorithm 2 with n disks allowing parallel moves.

If n

∈ odd, there are (n-1)/2 groups with 2

(n-1)/2 – 1 group moves; where 2(n-1)/2 -1 for the group-1, and 2(n-1)/2-1 – 1 for the other group. Without combination, there are total 5•2(n-1)/2 -1 + 3•(2(n-1)/2-1 – 1) = 4•2(n-1)/2 – 3 parallel disk moves.

Applying combination moves: * and **, because there are total 2(n-1)/2 – 1 group moves, the numbers of parallel disk move are

[4•2 (n-1)/2 – 3] – [2(n-1)/2 – 1 – 1] = 3•2(n-1)/2 - 1.

If n

∈ even, we similarly derive the number, without combination there are

total 3•2n/2-1 + 3• 2( n/2-1 – 1)= 3•2n/2 – 3 parallel disk moves. Applying combination moves, all the numbers of parallel disk move are

[3•2n/2 – 3] – [2n/2 – 1 – 1] = 2•2n/2 - 1.

The above result is the same as the optimal disk move number derived by Wu &

Chen[57], so our algorithm is the optimal iterative parallel.

Chapter 7

Conclusion

7.1 Result of Our Research

In this paper, we study recursive and iterative algorithms on “The tower of Hanoi problem” with three pegs. Six surveys are introduce : four recursive algorithm, (1) traditional TTOHP, (2) cyclic moves TTOHP, (3) parallel moves TTOHP, (4) cyclic parallel moves TTOHP, and two iterative algorithm (5) iterative algorithm on traditional TTOHP (6) iterative algorithm on cyclic TTOHP. In chapter 6 we introduce our observation: design a simple and effective iterative algorithm to implement TTOHP with parallel moves.

We propose the algorithm is base on the theorem of Walsh’s thesis : the iterative

WU&CHEN in the parallel moves of TTOHP, we design the simple algorithm, and have proved its solution is same with the solution of recursive algorithm.

In the finally we list some data for TTOHP to compare.

TTOHP SOLUTION

standard cyclic parallel cyclic parallel algorithm

c(n) a(n) c(n) a(n)

Formula

Disk number

2

n

-1 2a

n-1

+1 2a

n-1

+c

n-1

+2 2a

n-1

-3 2a

n-1

+c

n-1

-6

1 1 1 2 1 1 2

2 3 5 7 3 4 5

3 7 15 21 5 7 8

4 15 43 59 7 13 17

5 31 119 163 11 31 41

6 63 327 447 15 79 107

7 127 895 1223 23 211 287

8 255 2447 3343 31 571 779

9 511 6687 9135 47 1555 2123

10 1023 18271 24959 63 4243 5795

11 2047 49919 68191 95 11587 15827

12 4095 136383 186303 127 31651 43235

13 8191 372607 508991 191 86467 118115 14 16383 1017983 1390591 255 236227 322691 15 32767 2781183 3799167 383 645379 881603 16 65535 7598335 10379519 511 1763203 2408579

Figure 7.1 Some optimal solution for TTOHP and its variants

7.2 Studying Topic in the Future

The multi-peg (k≧4) TTOHP is another generalized version of this classical problem, and is still open. Newman-Wolfe [49] obtained some lower and upper bounds on the number of moves for different ranges of the number of pegs. They had given a recursive formulation for computing the number of moves. But interestingly, it is not known whether the number of moves given in Boardman’s formulation is optimal and no evidence to contrary is available either. In the finally, we provide this topic for the future research on TTOHP .

Reference

[1] J. P. Allouche, “Note on the Cyclic Towers of Hanoi”, TCS 123 (1), pp.3-7, 1994.

[2] M. D. Atkinson, “The cyclic towers of Hanoi”, Information Processing Letters 13, pp.118-119, 1981.

[3] P. Buneman & L. Levy, “The towers of Hanoi problem”, Information Processing Letters 10, pp.243-244, 1980.

[4] W. C. Chang & G. J. Chang, “Study on Tower of Hanoi”, Master Thesis, Submitted to Department of Applied Mathematics, National Chiao Tung University Engineering, 1998.

[5] F. B. Chedidand Toshiya Mogi, “A simple iterative algorithm for The Tower of Hanoi Problem”, IEEE Trans. Ed. 39, no. 2, pp. 274-275, 1996.

[6] E. W. Dijkstra, “A short introduction to the art of programming”, EWD 316, 1971.

[7] B. Eggers, “The towers of Hanoi: Yet another nonrecursive solution”, SIG-PLAN Notices 20, no. 9 (September), pp.32-42, 1985.

[8] M. C. Er, “A general algorithm for finding a shortest path between two n-configurations”, Inform. Sci. 42, pp.137-141, 1987.

[9] M. C. Er, “A generalization of the cyclic towers of Hanoi: An iterative solution”, Internat. J. Comput. Math. 15, pp.129-140, 1984.

[10] M. C. Er, “A loop less approach for constructing a fastest algorithm for the Towers of Hanoi problem”, Internat. J. Comput. Math. 20, pp.49-54, 1986.

[11] M. C. Er, “A loop less and optimal algorithm for the cyclic towers of Hanoi problem”, Inform. Sci. 42, pp.283-287, 1987.

[12] M. C. Er, “A minimal space algorithm for solving the towers of Hanoi problem”, J. Inform. Optim. Sci 9, pp.183-191, 1988.

[13] M. C. Er, “A representation approach to the tower of Hanoi problem”, Comput.

J. 25, no. 4, pp.442-447, 1982.

[14] M. C. Er, “An algorithmic solution to the multi- tower of Hanoi problem”, J.

Inform. Optim. Sci. 8, no. 1, pp.91-100, 1987.

[15] M. C. Er, “An analysis of the Generalized Tower of Hanoi Problem”, Bit 23 (4),

[16] M. C. Er, “An iterative algorithm for the cycle towers of Hanoi problem”, Internat. J. Comput. Inform. Sci. 13, no. 2, pp.123-129, 1984.

[17] M. C. Er, “An iterative solution to the Generalized Tower of Hanoi Problem”, Bit 23 (4), pp.295-302, 1983.

[18] M. C. Er, “An optimal algorithm for Revel’s puzzle”, Inform. Sci 45, pp.39-49, 1988.

[19] M. C. Er, “Counter examples to adjudicating a tower of Hanoi contest”, Internat. J. Comput. Math. 21, pp.123-131, 1987.

[20] M. C. Er, “Performance evaluations of recursive and iterative algorithms for the towers of Hanoi problem”, Computing 37, PP.93-102, 1986.

[21] M. C. Er, “The colour towers of Hanoi- An iterative solution”, J. Inform. Optim Sci. 5, no. 2, pp.95-104, 1984.

[22] M. C. Er, “The complexity of the generalized cyclic towers of Hanoi problem”, J. Algorithms 6, pp.351-358, 1985.

[23] M. C. Er, “The Cyclic Tower of Hanoi: A representation Approach”, The Computer Journal 27 (2), pp.171-175, 1984.

[24] M. C. Er, “The cyclic towers of Hanoi and pseudo ternary code”, J. Inform.

Optim. Sci. 7, no. 3, pp.271-277, 1986.

[25] M. C. Er, “The Generalized colour Tower of Hanoi Problem: An iterative algorithm”, The Computer Journal 27 (3), pp.278-282, 1984.

[26] M. C. Er, “The generalized towers of Hanoi problem”, J. Inform. Optim. Sci 5, no. 1, pp.89-94, 1984.

[27] M. C. Er, “The tower of Hanoi problem-a further reply”, Comput. J. 28, no.5, pp.543-544, 1985.

[28] M. C. Er, “The towers of Hanoi and binary numerals”, J. Inform. Optim. Sci. 6, no. 2, pp.147-152, 1985.

[29] M. C. Er, “Towers of Hanoi with black and white disks”, J. Inform. Optim. Sci.

6, no. 1, pp.87-94, 1985.

[30] D. Gault & M. Clint: “A Fast Algorithm for the Towers of Hanoi”, The Computer Journal 30 (4), pp.376-378, 1987.

[31] T. Gedeon, The “Cyclic Tower of Hanoi: An Iterative Solution Produced by Transformation”, The Computer Journal 39 (4), pp.353-356, 1996.

[32] T. D. Gedeon, “The Reve`s puzzle : An iterative solution produced by transformation”, The Computer Journal 35 (2), pp.186-187, 1992.

[33] P. J. Hays, “A note on The Tower of Hanoi problem”, Computer Journal 20, pp.

282-285, 1977.

[34] A. M. Hinz, “An iterative algorithm for the Tower of Hanoi with four pegs ”, Computing 42, pp.133-140, 1989.

[35] X. –M Lu & T. S. Dillon, “Nonrecursive solutio n to parallel multipeg Towers of Hanoi: A decomposition approach”, Math. Comput. Modelling 24, no. 3, pp.29-35, 1996.

[36] W. Lunnon, “The Reve’s Puzzle”, Comput. J. 29, p.478, 1986.

[37] A. A. K. Majumdar, “A note on the iterative algorithm for the Reve’s puzzle”, The Computer Journal. 37(5)pp.463-464, 1994.

[38]

A. A. K. Majumdar & M. Kaykobad, “An iterative algorithm for the

5-peg tower of Hanoi problem”, J. Bangladesh Acad. Sci. 20, no. 2, pp.119-128, 1996.

[39] A. A. K. Majumdar, “A note on the generalized multi-peg tower of Hanoi problem”, Prpc. Pakistan Acad. Sci. 33, no. 1-2, pp.129-130, 1996.

[40] A. A. K. Majumdar, “A note on the iterative algorithm for the four peg tower of Hanoi problem”, Bangladesh Acad. Sci. 18, no2, pp.241-250, 1994

[41] A. A. K. Majumdar, “Frame's conjecture and the tower of Hanoi problem with four pegs”, Indian J. Math. 36, no. 3, pp. 215-227, 1994

[42] A. A. K. Majumdar, “Generalized multi-peg tower of Hanoi problem”, J.

Austral. Math. Soc. Ser. B 38, Q.O. 2, pp 201-208, 1996.

[43] A. A. K. Majumdar, “The divide-and-conquer approach to the generalized p-peg tower of Hanoi problem”, Optimization 34, pp.373-378, 1995.

[44] A. A. K. Majumdar, A note on the cyclic towers of Hanoi, Proc. Pakistan A ad.

Sci. 33, no. 1-2, pp.131-132, 1996.

[45] A. A. K. Majumdar, “The generalized four-peg tower of Hanoi problem”, Optimization, vol 29, pp.349-360, 1994.

[46] A. A. K. Majumdar, “The generalized p-peg tower of Hanoi problem”, Optimization, vol 32, pp 175-183, 1995.

[47] S. Margarita, “The towers of Hanoi: a new approach”, AI Expert 8,no. 3 (March), pp.22-27, 1993.

[48] S. Minsker, “The Towers of Antwerpen problem”, Information Processing Letters 38, pp.107-111, 1991.

[49] R. Newman-Wolfe, “Observations on multipeg Tower of Hanoi”, TR187, University of Rochester, 1986.

[50] A. Pettorossi, “Tower of Hanoi Problem: Deriving Iterative Solutions by Program Transformations”, Bit 25, pp.327-334, 1985.

[51] J. S. Rohl, “Tower of Hanoi: The Derivation of Some Iterative Versions ”, The

相關文件