At Least Two Worlds
We begin with a list of
Bubble Sort repeatedly scans the list, inspecting neighboring pairs of elements. Consider such a pair,
Now pick any two elements,
Since Bubble Sort finishes with the entire list in ascending order,
Now return to a moment when Bubble Sort is inspecting neighboring elements
Furthermore, because
Putting this together, Bubble Sort swaps a given pair of elements exactly once if and only if they were in the wrong relative order in the original list. Each swap corrects that pair’s relative order without affecting the relative order of any other pair.
Let’s call the number of element pairs in the wrong relative order in the original list
Now consider
First, pick any two other elements,
If both of these pairs were originally in the correct order, they become incorrect, increasing
Therefore, every element between
Returning to the
But consider what happens when the empty space starts and finishes in the same position. Every move to the left must be balanced by a move to the right, and every move upward by a move downward. Therefore, returning the empty space to its starting position always requires an even number of moves.
Since each move flips
Now recall our two examples. The solved puzzle has
Thus, at least two separate worlds exist, unreachable from one another.
At Most Two Worlds
Here’s an inefficient algorithm that can solve the 15-puzzle from any starting configuration... well, almost.
First, move the empty space to the lower-right corner. Now consider the following arrangement:
The letters represent positions on the board, not the numbers printed on the tiles. Starting from the empty space, we can follow a circuit through
If we move the empty space around the circuit, each numbered tile shifts one place in the opposite direction. The tile at
Now consider just the 2×2 region in the lower-right corner:
Instead of following the entire circuit, move the empty space up, left, down, and right, returning it to its starting position. The maneuver rotates the three tiles without disturbing any others. Moving the empty space around the square in the opposite direction rotates those same three tiles in reverse.
Notice that
Suppose we want to rotate any three consecutive tiles in the circular ordering. First, rotate the entire circuit until those three tiles occupy positions
Because the two full-circuit rotations cancel for every other tile, we can rotate any three consecutive tiles in the circular ordering, in either direction, without changing the final positions of any other tiles. That is, if we label the tiles occupying three consecutive positions
Now we have everything we need to almost solve the puzzle.
First, rotate the entire circuit until tile 12 occupies position
Next, find tile 11, which belongs at position
Continue in the same way, placing the correct tiles at
If the required tile is at least two positions beyond its destination, rotate it with the two preceding tiles to move it back two positions. Repeat until it reaches its destination or the position immediately after it. In the latter case, rotate the tile at the destination, the required tile, and the following tile to move it back one final position. Since at least three unfinished positions remain, this final maneuver is always possible.
Eventually, we reach position
That leaves just
Every other tile is now in its correct position, and the empty space is in the lower-right corner. There are only two possible outcomes: either the puzzle is solved, or tiles 14 and 15 are swapped.
Since every legal move can be reversed, any two starting configurations that lead to the same outcome can be transformed into one another. And since our algorithm has only two possible outcomes, the 15-puzzle can have at most two separate worlds.
But what about other grid sizes?
For rectangular grids with an even number of squares, at least one dimension must be even. When the number of rows is even, we can construct a circuit using the pattern described below. If only the number of columns is even, the same pattern works with the roles of rows and columns exchanged; the empty space and the goal arrangement stay in their original positions.
Starting from the empty space in the lower-right corner, move up one position. Snake left and right through the rows above the bottom row, working upward and leaving the leftmost column untouched. Because the number of rows is even, the number of rows above the bottom row is odd; the alternating passes therefore finish in the second column of the top row. Move one position left into the upper-left corner. Then follow the leftmost column downward and cross the bottom row to return to the empty space.
This circuit visits every position once before returning to its starting point. Furthermore, the three positions in the lower-right 2×2 region are consecutive in the circular ordering that skips the empty space, just as in our 15-puzzle example.
When we exchange the roles of rows and columns, the same construction works in the other direction. For example, a grid with three rows and four columns can use this circuit:
Here,
We can therefore arrange the tiles one by one, leaving only two positions unresolved. Those final positions need not always correspond to the last two numbered tiles, but there are still only two possible outcomes.
For grids with an odd number of squares, such as the 3×3 grid of the 8-puzzle, we need a small adjustment. As we established earlier, returning the empty space to its starting position requires an even number of moves. A circuit that visits every position exactly once and returns to its starting point requires one move per position; therefore, a circuit must contain an even number of positions.
To compensate, we can leave one position outside the circuit. For the 8-puzzle, let’s omit the upper-right corner:
Here, the cross marks the excluded position. Starting from the empty space, we can follow
Before using this circuit to arrange the tiles, we need tile 3 in the excluded corner. If it is already there, we can proceed directly to the solving algorithm. Otherwise, rotate the circuit until tile 3 occupies position
The remaining maneuvers leave tile 3 untouched.
Look again at the lower-right 2×2 region:
Moving the empty space around this square rotates the tiles at
We can therefore combine full-circuit rotations with this smaller rotation to rotate any three consecutive tiles in the circular ordering, leaving all others in their original positions when the maneuver finishes.
Using the same algorithm, we first rotate the entire circuit until tile 6 occupies position
That leaves
Once again, there are only two possible outcomes: the solved puzzle, or the solved puzzle with its final two numbered tiles swapped.
Now consider the 5×5 grid of the 24-puzzle:
Notice the pattern. Starting from the empty space, the circuit moves up and then left. It continues upward through the two rightmost columns, crossing between them after each upward move except the move into the top row. Because the height is odd, it arrives immediately to the left of the excluded upper-right corner. From there, it snakes leftward through the remaining columns, alternating downward and upward, while leaving the bottom row untouched. After the two rightmost columns, an odd number of columns remains; the alternating passes therefore finish by descending the leftmost column. The circuit then crosses the bottom row to return to the starting position.
We can extend this pattern to larger odd-by-odd grids by adding pairs of rows or columns. Every position except the upper-right corner belongs to the circuit. The lower-right 2×2 region always contains the first two numbered positions and the last numbered position along the circuit; these are consecutive in the circular ordering that skips the empty space.
We can also place the correct tile into the excluded corner using the same procedure as before. If it is already there, leave it untouched. Otherwise, rotate the circuit until that tile occupies the position immediately to the left of the corner. Move the empty space up the rightmost column, then left, pushing the tile into place. Return the empty space to the lower-right by following the remainder of the circuit, without disturbing the completed corner.
We can now use our familiar rotations to arrange the remaining tiles one by one, leaving only the final two positions unresolved.
Thus, regardless of whether the rectangular grid contains an even or odd number of squares, every starting configuration can be transformed into one of just two possible outcomes. By the same reversibility argument used for the 15-puzzle, there can be at most two worlds.
Our algorithm starts and ends with the empty space in the lower-right corner; so, the initial and final values of
The route used to move the empty space to the lower-right corner does not matter. Reversing one route and following another gives a sequence that begins and ends with the empty space in that corner, so
Exactly Two Worlds
Bubble Sort revealed that there must be at least two worlds. Our inefficient solving algorithm demonstrated that there can be at most two. Together, they prove that every
The two worlds are equally large. To see this, pair every configuration with the one obtained by swapping tiles 1 and 2. Since the swap does not disturb the empty space but does flip
Therefore, each world contains exactly