Touring Problems – a Mathematical Approach
Total Page:16
File Type:pdf, Size:1020Kb
TOURING PROBLEMS – A MATHEMATICAL APPROACH VIPUL NAIK Abstract. The article surveys “touring”, a problem of “fun” math, and employs serious techniques to attack it. The text is suitable for high school students interested in Olympiad mathematics, as well as undergraduate students studying combinatorics and discrete math- ematics. It can be used to introduce the concept of a graph. A sequel to this article, on a similar analysis for “tiling” problems, shall also appear soon. 1. Prebeginnings 1.1. The knight’s tour. Chess pieces, with their variously defined moves, are a rich source of puzzles in recreational mathematics. Chess puzzles include the following types : • Nonattacking pieces puzzle : Given a piece with some moves defined, place as many copies of this piece as possible so that no two can kill each other. The proto- typical example of this is the eight queens problem – placing eight queens on the chessboard so that no two can kill each other. • Board domination puzzle : Given a piece with some moves defined, place as few copies of the piece as possible so that every square is either covered by some copy or is under direct attack by a copy of the piece. • Touring puzzle : Given a piece with some moves defined, construct a tour of the entire chessboard with that piece. The only nontrivial case of this for a standard chess piece is the knight’s tour. Each of these problems revolves around a piece, with certain moves defined for that piece. Instead of standard chess pieces, we may sometimes be interested in defining chess pieces with somewhat different moves. Such pieces are termed fairy chess pieces . In this article, we focus on the problem of the knight’s tour, and its formulation in a manner that helps us consider general variations – such as replacing the knight by some fairy chess piece, or changing the shape and size of the board. Interestingly, we will find that the formalism that we develop on the way is useful even for understanding the other classes of chess puzzles. 1.2. Tour finding, maze hunting and sudoku solving. When a rat wants to find its way through a maze, it must, at every stage, make some choices as to which path to take (whenever there is more than one choice). If the rat makes the wrong choice, it will soon reach a dead end, and will go back to the last choice it made, and try the other one. When it finally reaches the starting point with no more paths to try out, it throws up its paws and concludes that there is “no way”. We do something similar while solving sudoku puzzles. By and large, our attempt is to use scanning techniques to locate positions that can be filled up. That is, we scan the rows and columns for entries we are sure of, using the fact that every row, every column and every 3 × 3 cell has all the numbers from 1 to 9. For eliminating positions for numbers and 1 numbers for positions, we use techniques of contingency spotting – that is, contingencies that force numbers to be within certain squares, and cross hatching – that combine multiple contingencies to draw conclusions. Repeated application of these helps us fill in positions we are sure of. However, there may be situations where we are not able to be sure of anything further to fill in. In such cases, we do a what if – we try out filling a number in some place and see if it works out. If this what if does not lead to a solution, then we will soon come up with a contradiction and shall be forced to remove all the entries filled in after the last what if. We can then try one of the other possibilities at that stage. In much the same way, when trying to construct a knight’s tour of the chessboard, we are, at every stage, confronted with some options and pick one option over the others. However, the option that we pick might lead to a dead end, in which case we need to backtrack and choose some other option. In our attempts to construct knight’s tours of the chessboard, we shall study more formally these kinds of strategies, under the title depth first search. As we can already see from the above three examples, we need to improve on the depth first search by minimizing backtracking because that indicates time wasted without any reward. We will come up with techniques for doing this in the knight’s tour situation that help us construct the tour. 1.3. Travelling salesmen. The travelling salesman problem is an important problem both in theoretical and in practical computer science. Problem 1 (Travelling Salesman Problem). A salesman has to visit n cities. There is a network of roads between the cities and the shortest distance between any pair of cities is known to the travelling salesman. How can he visit each of the cities so as to minimize the total distance he travels? (The distance between the cities is much larger compared to distances within each city) In a map, the cities may be represented as vertices and the roads may be represented as edges joining them, with each edge having a length. The length of the road may not be exactly equal to the crow’s distance between the cities. The travelling salesman’s task is to visit each city while minimizing the total road length he travels. This problem bears many similarities to the knight’s tour problem, in terms of both formulation and solution strategies. The travelling salesman problem is an example of an optimization problem and is outside the scope of this article. Nonetheless, the terminology developed here (for the purpose of analyzing the knight’s tour) is used in analyzing problems like this one. 2. The touring problem – general formulation 2.1. The motivating problem. The famous knight’s tour problem asks whether a knight can tour an entire 8 × 8 chessboard visiting each square exactly once. Here, a knight can move in any of 8 ways, provided that the final destination is within the board. In each of these ways, one coordinate of the knight’s position changes by 2 units (positively or negatively), and the other coordinate changes by 1 unit (positively or negatively). If the two directions are labelled up/down and left/right the eight moves are : • Up two steps, right one step 2 • Up two steps, left one step • Right two steps, up one step • Right two steps, down one step • Down two steps, left one step • Down two steps, right one step • Left two steps, up one step • Left two steps, down one step. From the above listing of moves, it is clear that the knight’s move is symmetric, in the sense that if a knight can move from a square A to a square B in one move, it can also move from B to A in one step. There are many variations of this problem : • Whether a tour is possible with a given initial position. • Whether a tour is possible with a given initial and a given final position. • Whether there is a closed tour or re-entrant tour , that is, a tour where the last square is a knight’s move away from the first. If there is a closed tour beginning at some square, there is a closed tour beginning at any square. Essentially, the knight needs to cover as many squares of the chessboard such that after each square, the next square it goes to is a knight’s move away. We would like a structure that captures this relationship between squares (of being separated only by a knight’s move). Such a structure exists in mathematics – a graph.1 The purpose of this abstraction is to help us develop more generic tools that can be applied to variants of the knight’s tour problem. For instance, we may change the : • Shape of the board (we might even choose not to keep it rectangular) • Moves allowed on the piece (we might even choose them not to be symmetric) • Conditions imposed on the tour – we might put some additional conditions or relax some constraints. 2.2. Necessary background and problem formulation. A graph comprises a set of vertices or nodes and a set of edges or arcs or lines, where each edge joins two nodes. We use the following terms : • The two nodes that an edge joins are termed its endpoints. Given two vertices, if there is an edge joining them, they are termed adjacent. • A vertex and an edge are incident provided that the vertex is one of the endpoints of the edge. Typically graphs are represented by pictures in the plane with the vertices represented as thick dots, and the edges represented as line segments or arcs joining the endpoints. Most graphs cannot be drawn in the plane such that no two edges cross each other, though such a depiction would be visually ideal. 2 In our case, the vertices of the graphs are the squares of the chessboard, and there is an edge joining two vertices (that is, the two vertices are adjacent) if they are separated by a knight’s move. This graph completely captures the behaviour of the chessboard in the 1The term “graph” is used in a completely different sense when we talk of the graph of a relation or a function. 2Graphs which can be drawn without edges crossing each other are termed planar graphs. A graph is planar if and only if it does not contain a K5 or a K3,3 3 context of the knight’s move.