iterative algorithms
Before searching for an iterative algorithm to reemphasize an important detail. Although we speak of various algorithms, the optimal solution (the less movement, as we have seen before, for n = 8 is 255) is unique. In other words, the series of moves that results from applying an algorithm (optimum) will either be always the same.
An Observation key to finding an iterative algorithm is that the smallest disk is moved after another, one might not. The first move must be done with disk 1. It is clear that after moving the disk 1 (at any time) must move a different disk (if you do not want to waste time moving the same disc multiple times.) This movement must be made between the two posts that do not contain the disk 1. Then we do not are only two choices: undo the last move, which makes no sense, or return to move the disc 1. Also, when you touch your turn to a disk other than 1, the movement will be fully determined and will intervene only two posts and two posts there is only one possible move. So only when there can be no doubt that moving the lower disk. We leave this question with respect to any of the following rules.
-The small disk must always move cyclically in the same direction, clockwise (from A to B, B to C and from C to A) or left (A to C, C to B and from B to A), as the number of disks is even or odd respectively.
-The small disk should always be placed either on a disk number, either as a single disk in the post of destination (C) if the record number is odd or the other (B) if pair.
Given the first rule is constructed an algorithm discovered by Peter Buneman and Leon Levy.
1.-If n is even, disk 1 moves to the right. If is odd, move to the left.
2.-If all the disks are in C, end. If not, move a disk other than 1 and returns to step 1.
Considering the second rule, the algorithm could be next.
1.-If possible, bring the hard disk 1 on a number. If not possible, take it to the post B if n is even or C if n is odd.
2.-If all the disks are in C, end. If not, move a disk other than 1 and returns to step 1.
To make this algorithm easier to implement, can be painted even and odd discs of two different colors. Even You can paint the base into three pieces, as shown in the figure (it is as if the pieces were based disks n +1, n +2 and n +3).
0 comments:
Post a Comment