MathOverflow is a question and answer site for professional mathematicians. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Consider a 'game' played on a subset $S$ of an $n^2$ square grid as follows. There are 3 types of pieces, each occupying a square of $S$, 1 green, some red and the rest are blue, a move consists of shuffling the green piece with any of its 4 adjacent pieces (if they are within $S$). $S$ consists of squares, squares not in $S$ are static, $S$ can be any subset of squares of the $n^2$ square.

If two board configurations are reachable from eachother, is it possible to obtain an upper bound on the number of moves needed, given only the board size $n$, is it polynomial in $n$?

share|cite|improve this question
So the green piece has the role of an empty space into which one can slide another piece. Nice question. – Johan Wästlund May 7 '12 at 19:16
It should be polynomial, probably in n^3 moves, most definitely n^6. (I suppress the O().) To move any tile to a given place in the top row (except) for the last 2) should take at most n^2 moves. Although tricky, filling the top row and left column with the desired tiles should take n^3 moves. Now induct down to small n where you did your exhaustive analysis already. Gerhard "Ask Me About System Design" Paseman, 2012.05.07 – Gerhard Paseman May 7 '12 at 19:50
@Gerhard The problem is that we often have to back track to fill the next column, thus changing the previous filled column. We cant normally enumerate the squares and fix one at a time, without disturbing the previously fixed ones. I think this strategy works when S is the n^2 square though. – Xnyyrznaa May 7 '12 at 19:56
The above assumes there is enough space at any time to do "cycle" moves. If S is constrained so that one cannot move a cycle of blocks freely, then we need to know more about the region of traversal. As long as S and appropriate subregions always contain a loop, the above analysis should apply, and give you an O(n^4) bound. Gerhard "Ask Me About System Design" Paseman, 2012.05.07 – Gerhard Paseman May 7 '12 at 20:19
Actually, if S is sufficiently "snaky", you may need n^6. Think insertion sort. Gerhard "A Twisted Imagination Sometimes Helps" Paseman, 2012.05.07 – Gerhard Paseman May 7 '12 at 20:35

Not a solution, just three observations that might trigger other ideas.

  1. The pieces filling $S$ continue to fill $S$ at all times. In other words, the shape of $S$ is fixed, and lattice cells exterior to $S$ are irrelevant as they can never be used.

  2. In order to move a particular tile from one square $a$ to another square $b$, there must be a simple cycle in $S$ on which they both lie. For example, in the first illustration below (where $X$ plays the role of the empty/green square, and $0$ and $1$ are red and blue tiles), the 1 in the lower-left corner cannot reach the upper-right corner because a connecting cycle pinches in the middle and so is not simple.

  3. In some sense the $2 \times n$ example illustrated feels like the worst case for moving one tile from end to end of $S$, and that requires $2 n (n-1)$ moves, if I've counted correctly.

      Sliding Blocks

Update1. Zack Wolske's sequence of moves is more efficient and shows the $2 \times n$ example only needs a linear number of moves. Gerhard Paseman's width-1 ring, however, clearly needs a quadratic number of moves.

Update2. I think the key parameter is, not the OP's $n$, but rather $m=|S|$, the number of cells in $S$. We have examples that require $\Omega(m^2)$ tile moves. Can anyone think of an pair of configurations that requires more than a quadratic number of moves in $m$?

share|cite|improve this answer
In 3, you only need $n-1 + 5(n-2) + 3 = 6n-8$ moves to go corner to corner as pictured. The first $n-1$ slides the bottom row so that the blank is behind the $1$, and it takes $5$ moves to go from X10 to 0X1 in the bottom row by pushing the 0s around the top row. After $n-2$ of those, the blue 1 is below its goal, and the final $3$ moves it up. – Zack Wolske May 8 '12 at 2:19
Yes. However it is possible that S is a square ring of squares of width 1 with an extra square in one corner, so that the general case of moving a square from one square to another square involves roughly the square of the number of squares in S. Gerhard "Likes E's of Suppressing O's" Paseman, 2012.05.07 – Gerhard Paseman May 8 '12 at 3:33
We should have MO Awards periodically, and you Joseph should get the Best Diagrams Awards everytime. – Mariano Suárez-Alvarez May 8 '12 at 6:16
@Zach: Yes, your moves are more efficient: Nice! – Joseph O'Rourke May 8 '12 at 11:25
@Gerhard: Your width-1 ring is a clear example of needing about $n^2/2$ moves to reposition a tile from one corner to the other. Nice example! – Joseph O'Rourke May 8 '12 at 11:29

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.