A knight’s journey

Polina Shchepinova hitches a ride round various boards

post

Chess is one of the oldest games that remains popular today. It is fairly easy to learn, yet incredibly complex strategically. As well as spending time learning to play it well, mathematicians have spent considerable effort trying to uncover its hidden structures.

A particular piece that has been of interest to mathematicians for centuries is the knight. From any square a knight may move two squares in a horizontal or vertical direction, followed by a square perpendicular to that, familiarly referred to as an ‘L-shape’. For example, these are the possible squares that a knight could move to from one of the centre squares:

A chess board with a white knight in position D4 with blue circles indicating the squares where it can move.
The knight is perhaps less intuitive than the other pieces, often making it easy for players to miss knight tactics during the game and giving the piece some interesting quirks. For example, notice that each time the knight makes a move it swaps colours: it can’t jump from a white square to another white one, and same with black. The manoeuvrability of the knight is also very interesting and leads to a question: can the knight move all the way around the board, visiting every square exactly once? This is what is called a knight’s tour.

The maiden voyage

With a chessboard at hand and some time, you may indeed find such a path for the knight. With enough patience, you may even find multiple such paths, perhaps with different starting squares. We will in fact show that the starting square does not matter — we can find a knight’s tour starting from any of the 64 squares!

Attempting to find a knight’s tour from each square by hand is far too tedious. Instead, let me first rephrase the goal slightly. Rather than presenting a knight’s tour for each possible starting square, we will find what is called a closed knight’s tour. This is a sequence of moves for the knight, visiting each square on the board exactly once and ending at the starting square. (An open knight’s tour is one that doesn’t end at the starting square. These are easier to find and perhaps less interesting to discuss, so we won’t be doing that here.)

As closed knight’s tours form a loop, we can treat any square as their starting square — so once we’ve found a closed tour, we can generate a tour starting at any square by shifting the sequence of moves.

To find our tour, we’re going to follow an elegant but not-so-famous method found by Peter Roget. This method reframes how to view the board and makes the path easily recreatable from memory. First, we split the chessboard into four quadrants, obtaining four 4 by 4 squares. We now colour each quadrant like this:

A four by four grid made up of orange, green, yellow and blue squares, arranged so that no two colour squares are in the same row or column.

Notice that the four colours — blue, green, orange and yellow — split the board into four mini knight’s tours. After repeating the colouring on all four quadrants, our board looks like this:

An eight by eight grid made up of orange, green, yellow and blue squares, arranged so that only two of each colour of square are in the same row or column and same colour squares do not share a border.

The key idea is to notice that each colour forms a closed tour for the knight. For example, here’s a closed knight’s tour of the blue squares:
An eight by eight grid made up of orange, green, yellow and blue squares, arranged so that only two of each colour of square are in the same row or column and same colour squares do not share a border. The blue squares are labelled 1 through 16 and have arrows connecting to the next blue square.
Now from our last traversed blue square (number 16), notice that we can hop onto a yellow square in the top right quadrant, and now traverse all the yellow squares (moves 17–32). We continue by then visiting all the orange squares (33–48) then the green squares (49–64). We obtain the following closed tour for the knight:
An eight by eight grid made up of orange, green, yellow and blue squares, arranged so that only two of each colour of square are in the same row or column and same colour squares do not share a border. Each square is labelled with a number from 1 to 64 in the order that the knight chess piece visits each square.

In his original work Roget went further still. He used this colouring trick not to simply find a closed knight’s tour on an 8 by 8 board, but developed a powerful algorithm that produced a (not necessarily closed) knight’s tour from any given starting and ending square, provided they are of different colours in the standard colouring of the board. So for example, I could choose the top left hand corner as the starting square and the top right hand corner as the ending square, and the algorithm would give me a sequence of knight moves with those end points, and of course visiting every square on the board exactly once to form a knight’s tour!

An eight by eight grid made up of orange, green, yellow and blue squares, arranged so that only two of each colour of square are in the same row or column and same colour squares do not share a border. Each square is labelled with a number from 1 to 64 in the order that the knight chess piece visits each square. This image gives a different arrangement of the numbers.

A knight’s tour starting in the top left corner
and ending top right corner

If the explicit algorithm is of interest to you, see Roget’s original article, with the
rather lengthy title “Description of a method of moving the knight over every square of the chessboard without going twice over any one; commencing at any given square and ending at any other given square of a different colour” — (Philosophical Magazine, 1840).

The uncrossable realms

So far, we have been looking at a standard 8 by 8 chessboard. Now we take it a step further: does a closed knight’s tour exist on other shaped boards? Or to flip the question: on which sized boards is there no closed knight’s tour?

Consider a rectangular $n$ by $m$ board with $m \leq n$ (to avoid double counting different cases). It turns out that the exhaustive list of boards on which a knight’s tour is not possible is covered by the following cases:

  • $m$ is 1, 2 or 4;
  • $m$ and $n$ are both odd;
  • $m$ is 3, and $n$ is 4, 6 or 8.

We will go through each of these, in increasing order of difficulty.

First of all let’s look at when $m$ is 1 or 2. Here the board is simply too small for the knight to get around. For $m = 1$ this is obvious. For $m = 2$, consider a corner of the board: from here the knight may only move to one square, so we cannot possibly obtain a loop.

A one by nine chessboard with the knight on square B2

On a 1 by 𝑛 board, a knight cannot move.

A two by nine chessboard with the knight on square A2

On a 2 by 𝑛 board, a knight in a corner has only
one possible move

Now let’s look at the case when $m$ and $n$ are both odd. Each time the knight makes a move, it switches the colour of the square it was on (from a white square a knight may only move to black squares, and vice versa). This means that a closed knight’s tour traverses as many black squares as white squares and it must end on the colour that it doesn’t start on (in order for it to be able to move to its original square and be closed). If $m$ and $n$ are both odd, that means we have an odd total number of squares on the board, and therefore there is no possible way for there to be an equal number of black and white squares, and so we cannot have a closed knight’s tour.

Next, we look at a board with $m=4$ (or $n=4$). This uses a slightly more involved parity argument, discovered by Louis Pósa. Consider a 4 by $n$ board, and colour the top and bottom rows green, and the two other rows blue. For $n=9$, this would look like this:

A 4 by nine grid with the top and bottom rows coloured green and the middle two rows are blue.

First, notice that there are the same number of blue and green squares ($2n$ of each).

From a green square the knight can only move onto blue squares. If a knight’s tour contained two blue squares in a row, then it would have to at some point contain two green squares in a row to keep the totals equal — but that’s impossible, so in a closed tour, the knight must alternate between blue and green squares. We also know that the knight alternates between white and black squares (using the standard board colouring), therefore all green squares must be white, and all blue squares black. They’re not, so our colouring demonstrates there cannot be a closed tour on this board.

The case where $m=3$ and $n=6$ requires a different approach. We reframe our 3 by 6 board as a graph — a set of vertices (points) with some edges (connections) between them. Each of the 18 squares will be a vertex, and two vertices will be connected if the squares are a knight’s move apart:
A three by six grid with a black point in the centre of each grid square. Each point is joined by a black line to another point in a square that is a legal move for a knight in chess.

In this representation, a knight’s tour is formed from all the vertices (squares), and some selected edges between them (possible knight’s moves) forming a loop around the graph. In the tour, each vertex will have two edges connected to it — one for the knight entering, and the other for it leaving. With this in mind, let’s consider the vertex in the middle row and second column. Notice that it has only two incident edges as the knight only has two possible moves from this square. These edges must be included in our tour:
The graph that is drawn in the previous image but without the grid squares. One point is coloured orange and is connected to two other points with orange lines. The rest is black.

Similarly, consider the vertex in the middle row and final column. This also only has two incident edges, which must be included:

The graph that is drawn in the previous image but without the grid squares. Two points are coloured orange and they are connected to two other points with orange lines. The rest is black. This creates a horizontal diamond shape out of orange lines.

And now we are done! Why? By looking at the graph, we’ve seen that any knight trying to complete a tour is forced to follow a cycle between these four vertices:

A repeat of the previous but most of the graph is now gray. The graph that is drawn in the previous image but without the grid squares. One point is coloured orange and is connected to two other points with orange lines. The rest is gray.

This means there’s no possible way for the knight to visit all 18 squares, since it cannot make any other moves to or from these coloured vertices.

The 3 by 8 case is slightly more involved, and we won’t see it here. The idea is similar though — we consider the board as a graph, and by eliminating some vertices, deduce that a knight’s tour is impossible.

The verdict

It turns out that the cases we covered above exhaust all of the rectangular boards on which a closed knight’s tour is not possible: a tour is possible on an $n$ by $m$ board (with $m\leq n$) unless one or more of the following is true:

    • $m$ is 1, 2 or 4;
    • $m$ and $n$ are both odd;
    • $m$ is 3, and $n$ is 4, 6 or 8.

We’ve shown that each of these is impossible, but we’ve not shown that a knight’s tour is indeed possible on all other boards. The reasoning for this isn’t too hard, but is slightly tedious — it turns out there are nine small boards on which knight’s tours are possible, and you can argue that by extending these you can cover all possible rectangular boards.

Although I haven’t explicitly mentioned it, what we have been doing is rooted in graph theory. A knight’s tour is a specific case of a concept called a Hamiltonian cycle — a path around a graph that visits each vertex exactly once.

8 black dots arranged in an octagon shape. Each point is connected to the two points on either side with a black line. There is also an orange arrow pointing in an anti-clockwise direction between each set of two points.

A Hamiltonian cycle on the cyclic
graph on 8 vertices is easy to find

There is a condition for general graphs which guarantees that we can find a Hamiltonian cycle on it:

If a graph has $n$ vertices and each vertex has at least $n/2$ edges incident to it, then the graph has a Hamiltonian cycle.

This only goes one way though: there are many graphs that have Hamiltonian cycles but do not satisfy the condition. For example, the cyclic graph on 8 vertices has a Hamiltonian cycle but only has 2 edges incident to each vertex. Another example is the knight’s tour graphs that we’ve been looking at: regardless of the size of the board, the knight only has two possible moves from any of the corner squares. Yet there are many knight’s tour graphs on which a Hamiltonian cycle exists.

The field of graph theory was first introduced by Euler in 1736 when he proposed a solution to the famous seven bridges of Königsberg problem. This, similar to our knight’s tour adventure, was a recreational mathematical problem. Hamiltonian cycles, which arose from these playful explorations, are now crucial in transportation routes, electronic circuits, and even genome mapping. In this almost 300-year-long saga, imagination and playfulness have taken us far beyond the board.

Polina is an undergraduate maths student at the University of Warwick. She loves all sorts of puzzles, with some of her favourites being variant sudokus, cryptic crosswords, and any sort of chess-related puzzles.

More from Chalkdust