Knight's tour
A knight's tour is a sequence of moves of a knight on a chessboard such that the knight visits every square exactly once. If the knight ends on a square that is one knight's move from the beginning square (so that it could tour the board again immediately, following the same path), the tour is "closed", or "re-entrant"; otherwise, it is "open".<ref>Template:Cite thesis</ref><ref>Template:Cite book</ref>
The knight's tour problem is the mathematical problem of finding a knight's tour. Creating a program to find a knight's tour is a common problem given to computer science students.<ref>Template:Cite book</ref> Variations of the knight's tour problem involve chessboards of different sizes than the usual Template:Nowrap, as well as irregular (non-rectangular) boards.
TheoryEdit
The knight's tour problem is an instance of the more general Hamiltonian path problem in graph theory. The problem of finding a closed knight's tour is similarly an instance of the Hamiltonian cycle problem. Unlike the general Hamiltonian path problem, the knight's tour problem can be solved in linear time.<ref name=Conrad1994>Template:Cite journal</ref>
HistoryEdit
The earliest known reference to the knight's tour problem dates back to the 9th century AD. In Rudrata's {{#invoke:Lang|lang}}<ref> Template:Cite book </ref> (5.15), a Sanskrit work on Poetics, the pattern of a knight's tour on a half-board has been presented as an elaborate poetic figure ({{#invoke:Lang|lang}}) called the {{#invoke:Lang|lang}} or 'arrangement in the steps of a horse'. The same verse in four lines of eight syllables each can be read from left to right or by following the path of the knight on tour. Since the Indic writing systems used for Sanskrit are syllabic, each syllable can be thought of as representing a square on a chessboard. Rudrata's example is as follows:
से | ना | ली | ली | ली | ना | ना | ली |
ली | ना | ना | ना | ना | ली | ली | ली |
न | ली | ना | ली | ले | ना | ली | ना |
ली | ली | ली | ना | ना | ना | ना | ली |
transliterated:
se | nā | lī | lī | lī | nā | nā | lī |
lī | nā | nā | nā | nā | lī | lī | lī |
na | lī | nā | lī | le | nā | lī | nā |
lī | lī | lī | nā | nā | nā | nā | lī |
For example, the first line can be read from left to right or by moving from the first square to the second line, third syllable (2.3) and then to 1.5 to 2.7 to 4.8 to 3.6 to 4.4 to 3.2.
The Sri Vaishnava poet and philosopher Vedanta Desika, during the 14th century, in his 1,008-verse magnum opus praising the deity Ranganatha's divine sandals of Srirangam, Paduka Sahasram (in chapter 30: Chitra Paddhati) has composed two consecutive Sanskrit verses containing 32 letters each (in Anushtubh meter) where the second verse can be derived from the first verse by performing a Knight's tour on a Template:Nowrap board, starting from the top-left corner.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref> The transliterated 19th verse is as follows:
sThi
(1) |
rA
(30) |
ga
(9) |
sAm
(20) |
sa
(3) |
dhA
(24) |
rA
(11) |
dhyA
(26) |
vi
(16) |
ha
(19) |
thA
(2) |
ka
(29) |
tha
(10) |
thA
(27) |
ma
(4) |
thA
(23) |
sa
(31) |
thpA
(8) |
dhu
(17) |
kE
(14) |
sa
(21) |
rA
(6) |
sA
(25) |
mA
(12) |
ran
(18) |
ga
(15) |
rA
(32) |
ja
(7) |
pa
(28) |
dha
(13) |
nna
(22) |
ya
(5) |
The 20th verse that can be obtained by performing Knight's tour on the above verse is as follows:
sThi thA sa ma ya rA ja thpA
ga tha rA mA dha kE ga vi |
dhu ran ha sAm sa nna thA dhA
sA dhyA thA pa ka rA sa rA ||
It is believed that Desika composed all 1,008 verses (including the special Chaturanga Turanga Padabandham mentioned above) in a single night as a challenge.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref>
A tour reported in the fifth book of Bhagavantabaskaraby by Bhat Nilakantha, a cyclopedic work in Sanskrit on ritual, law and politics, written either about 1600 or about 1700 describes three knight's tours. The tours are not only reentrant but also symmetrical, and the verses are based on the same tour, starting from different squares.<ref>A History of Chess by Murray</ref> Nilakantha's work is an extraordinary achievement being a fully symmetric closed tour, predating the work of Euler (1759) by at least 60 years.
After Nilakantha, one of the first mathematicians to investigate the knight's tour was Leonhard Euler. The first procedure for completing the knight's tour was Warnsdorf's rule, first described in 1823 by H. C. von Warnsdorf.
In the 20th century, the Oulipo group of writers used it, among many others. The most notable example is the Template:Nowrap knight's tour which sets the order of the chapters in Georges Perec's novel Life a User's Manual.
The sixth game of the World Chess Championship 2010 between Viswanathan Anand and Veselin Topalov saw Anand making 13 consecutive knight moves (albeit using both knights); online commentators jested that Anand was trying to solve the knight's tour problem during the game.
ExistenceEdit
Schwenk<ref>Template:Cite journal</ref> proved that for any Template:Nowrap board with m ≤ n, a closed knight's tour is always possible unless one or more of these three conditions are met:
- m and n are both odd
- m = 1, 2, or 4
- m = 3 and n = 4, 6, or 8.
Cull et al. and Conrad et al. proved that on any rectangular board whose smaller dimension is at least 5, there is a (possibly open) knight's tour.<ref name=Conrad1994/><ref name=Cull1978/> For any Template:Nowrap board with m ≤ n, a (possibly open) knight's tour is always possible unless one or more of these three conditions are met:
- m = 1 or 2
- m = 3 and n = 3, 5, or 6<ref>{{#invoke:citation/CS1|citation
|CitationClass=web }}</ref>
- m = 4 and n = 4.<ref>{{#invoke:citation/CS1|citation
|CitationClass=web }}</ref>
Number of toursEdit
On an Template:Nowrap board, there are exactly 26,534,728,821,064 directed closed tours (i.e. two tours along the same path that travel in opposite directions are counted separately, as are rotations and reflections).<ref name=lw96>Template:Cite journal See attached comment by Brendan McKay, Feb 18, 1997, for the corrected count.</ref><ref>Template:Cite journal</ref><ref>Template:Cite book</ref> The number of undirected closed tours is half this number, since every tour can be traced in reverse. There are 9,862 undirected closed tours on a Template:Nowrap board.<ref>{{#invoke:Template wrapper|{{#if:|list|wrap}}|_template=cite web |_exclude=urlname, _debug, id |url = https://mathworld.wolfram.com/{{#if:KnightGraph%7CKnightGraph.html}} |title = Knight Graph |author = Weisstein, Eric W. |website = MathWorld |access-date = |ref = Template:SfnRef }}</ref>
n | Number of directed tours (open and closed) on an n × n board (sequence A165134 in the OEIS) |
---|---|
1 | 1 |
2 | 0 |
3 | 0 |
4 | 0 |
5 | 1,728 |
6 | 6,637,920 |
7 | 165,575,218,320 |
8 | 19,591,828,170,979,904 |
Finding tours with computersEdit
There are several ways to find a knight's tour on a given board with a computer. Some of these methods are algorithms, while others are heuristics.
Brute-force algorithmsEdit
A brute-force search for a knight's tour is impractical on all but the smallest boards.<ref name=Simon01a>Template:Citation</ref> On an Template:Nowrap board, for instance, there are Template:Val knight's tours,<ref name=lw96/> and a much greater number of sequences of knight moves of the same length. It is well beyond the capacity of modern computers (or networks of computers) to perform operations on such a large set. However, the size of this number is not indicative of the difficulty of the problem, which can be solved "by using human insight and ingenuity ... without much difficulty."<ref name=Simon01a/>
Divide-and-conquer algorithmsEdit
By dividing the board into smaller pieces, constructing tours on each piece, and patching the pieces together, one can construct tours on most rectangular boards in linear time – that is, in a time proportional to the number of squares on the board.<ref name=Cull1978>Template:Cite journal</ref><ref>Template:Cite journal</ref>
Warnsdorf's ruleEdit
Warnsdorf's rule is a heuristic for finding a single knight's tour. The knight is moved so that it always proceeds to the square from which the knight will have the fewest onward moves. When calculating the number of onward moves for each candidate square, we do not count moves that revisit any square already visited. It is possible to have two or more choices for which the number of onward moves is equal; there are various methods for breaking such ties, including one devised by Pohl<ref name="pohl"/> and another by Squirrel and Cull.<ref>{{#invoke:citation/CS1|citation |CitationClass=web }}</ref>
This rule may also more generally be applied to any graph. In graph-theoretic terms, each move is made to the adjacent vertex with the least degree.<ref name="Van Horn et. al">Template:Cite conference</ref> Although the Hamiltonian path problem is NP-hard in general, on many graphs that occur in practice this heuristic is able to successfully locate a solution in linear time.<ref name="pohl">Template:Cite journal</ref> The knight's tour is such a special case.<ref name="alwan-waters">Template:Cite conference</ref>
The heuristic was first described in "Des Rösselsprungs einfachste und allgemeinste Lösung" by H. C. von Warnsdorf in 1823.<ref name="alwan-waters"/>
A computer program that finds a knight's tour for any starting position using Warnsdorf's rule was written by Gordon Horsington and published in 1984 in the book Century/Acorn User Book of Computer Puzzles.<ref>Template:Cite book</ref>
Neural network solutionsEdit
The knight's tour problem also lends itself to being solved by a neural network implementation.<ref>Y. Takefuji, K. C. Lee. "Neural network computing for knight's tour problems." Neurocomputing, 4(5):249–254, 1992.</ref> The network is set up such that every legal knight's move is represented by a neuron, and each neuron is initialized randomly to be either "active" or "inactive" (output of 1 or 0), with 1 implying that the neuron is part of the solution. Each neuron also has a state function (described below) which is initialized to 0.
When the network is allowed to run, each neuron can change its state and output based on the states and outputs of its neighbors (those exactly one knight's move away) according to the following transition rules:
- <math display="block">
U_{t+1} (N_{i,j}) = U_t(N_{i,j}) + 2 - \sum_{N \in G(N_{i,j})} V_t(N) </math>
- <math display="block">
V_{t+1} (N_{i,j}) = \left\{ \begin{array}{ll} 1 & \mbox{if}\,\, U_{t+1}(N_{i,j}) > 3\\ 0 & \mbox{if}\,\, U_{t+1}(N_{i,j}) < 0\\ V_t(N_{i,j}) & \mbox{otherwise}, \end{array} \right. </math>
where <math>t</math> represents discrete intervals of time, <math>U(N_{i,j})</math> is the state of the neuron connecting square <math>i</math> to square <math>j</math>, <math>V(N_{i,j})</math> is the output of the neuron from <math>i</math> to <math>j</math>, and <math>G(N_{i,j})</math> is the set of neighbors of the neuron.
Although divergent cases are possible, the network should eventually converge, which occurs when no neuron changes its state from time <math>t</math> to <math>t+1</math>. When the network converges, either the network encodes a knight's tour or a series of two or more independent circuits within the same board.
See alsoEdit
- Abu Bakr bin Yahya al-Suli
- Eight queens puzzle
- George Koltanowski
- Longest uncrossed knight's path
- Self-avoiding walk