I will not prove (as Stephen did), but I will try to explain intuitively that 2 ^ n-1 - min: In each state there are only three possible movements for the disks. Let it represent the current state in the form of ordered seq (1, 1, .., 1), so that the first number indicates where the larger disk is, and the last number indicates where the smallest disk is. (1, 1, ..., 1) means that all disks are included in position 1. Also from (1, 1, .. 1) there are only two downstream states: (1, 1, ... 2) and ( 1, 1, ... 3). From (1, 1, ... 2) there are three descending states:
- Return to (1, 1, .. 1)
- goto (1, 1, ..., 3)
- goto (1, 1, ... 3, 2)
If you continue, you will get a graph for which nodes are possible states and edges (transitions) are โdisk movementsโ.
You will get the image as shown below (if you continue, it will look like a triangle, and at the vertices will be (1, 1, ... 1), (2, 2, .. 2), (3, 3, .. . 3)). The number of steps is actually the path in the graph.
If you walk along the edge of a triangle, the number of steps is 2 ^ n-1. All other paths are the same length or longer.
If you use a strategy: move all the disks except the largest one to accommodate 3, then move the large places to place 2 and finally move all the shapes from 3 to 2, the formula can be developed as follows:
f (n) =
f (n -1) // move all but the largest from 1 to 3
+ 1 // move for the most part from 1 to 2
+ f (n -1) // move everything from 3 to 2
->
f (n) = 1+ 2 * f (n-1)
solving this recurrence equation gives you the number of steps required by this strategy (which is the minimum number of steps)