Image: Joachim Bering (1613), reprint of 1855, public domain, via Wikimedia Commons
Euler's solution of the Königsberg bridge problem, the theorem that tells when a closed walk over every edge exists, and Hierholzer's construction of one. Then the question that looks almost the same and is far harder: when does a cycle through every vertex exist? The unit proves Dirac's theorem, shows that the Petersen graph has no Hamilton cycle, and introduces the travelling salesman problem.
Sample unit: the complete text
Two questions in this unit look almost alike and could hardly be more different. The first asks for a walk that uses every edge of a graph exactly once, and it was settled in 1735 by one short argument that fits on half a page. The second asks for a cycle that visits every vertex exactly once, and after almost two centuries of work nobody has a criterion that decides it, nor an efficient method that finds such a cycle in a large graph. The unit proves the theorem behind the first question, shows how to build the walk it promises, and then explores what is known about the second: a few conditions that rule a cycle out, a few that guarantee one, and the problem of the travelling salesman that grows out of it.
1 The bridges of Königsberg
In the eighteenth century Königsberg was a trading town of Prussia on the river Pregel, today Kaliningrad in Russia. The river splits in the town and encloses an island called the Kneiphof. Seven bridges joined the island, the two banks, and the piece of land between the two branches of the river east of the island. The title picture of this unit shows the town in a bird’s-eye view of 1613, and Figure 1 shows the same river as Leonhard Euler (1707-1783) drew it in his paper of 1736. The citizens asked whether a walk through the town could cross each of the seven bridges exactly once, and nobody had found one.
Figure 1. The river Pregel and the seven bridges of Königsberg, as drawn by Euler in his paper of 1736. The pieces of land are lettered \(A\) to \(D\) and the bridges \(a\) to \(g\); the handwritten names are those of the bridges. Credit: Leonhard Euler, Commentarii academiae scientiarum Petropolitanae 8 (1741), Figure 1, public domain, via Wikimedia Commons.
Euler’s first step was to throw away almost everything. The streets, the houses, the width of the river, and the length of each bridge play no role in the question. What matters is only which piece of land each bridge joins to which, so the whole town shrinks to four pieces of land and seven connections between them (Figure 2). The four pieces of land are the vertices and the seven bridges are the edges. There is one difficulty with the definition of Unit 1: two bridges join the island \(A\) to the north bank \(C\), and two more join \(A\) to the south bank \(B\), so some pairs of vertices are joined by two edges. A graph in the sense of Unit 1 does not allow that, and we need a slightly wider notion.
Figure 2. The Königsberg multigraph. The four pieces of land are the vertices and the seven bridges are the edges, with the letters of Figure 1. The degree of each vertex counts the bridges that touch that piece of land.
A multigraph is a graph in which two vertices may be joined by several edges, called parallel edges, and an edge may join a vertex to itself, which is called a loop. The degree of a vertex still counts the edge ends at it, so each parallel edge counts once and a loop counts twice. The handshake lemma of Unit 1 holds for multigraphs with the same proof, since every edge still has two ends. Walks and trails are defined as in Unit 2, except that a walk must now also say which of several parallel edges it uses. The words that this unit needs are collected in the box below.
In this language the question of the citizens asks whether the multigraph of Figure 2 has an Euler trail. The walk may start and end anywhere, so an Euler tour would also do, but it is not required to be closed.
Now comes Euler’s argument. Think of a walker who follows a trail and consider any vertex \(v\) that is not the start or the end of the trail. Each time the walker passes through \(v\), one edge is used to arrive and a different edge is used to leave, so every visit uses up two of the edges at \(v\). If the trail uses every edge, the edges at \(v\) are paired off by the visits, and \(\deg(v)\) must be even. The start vertex and the end vertex behave differently. At the start one edge is used to leave without arriving, and at the end one edge is used to arrive without leaving, so these two vertices have odd degree if they are different, and even degree if the trail is closed and the two coincide. This proves the first half of the theorem of the next section: an Euler trail is possible only if the number of odd vertices is 0 or 2. Königsberg has four odd vertices, so no walk crosses each bridge exactly once, and the citizens were right to give up.
2 Euler’s theorem on tours
The degree argument rules an Euler trail out whenever more than two vertices have odd degree. The theorem of this section says that this is the only obstacle, provided the multigraph is connected. Connectedness is the second thing that a walker cannot get around, because no trail can reach an edge that lies in another component. Vertices without any edge play no part in the question and are ignored throughout, so “connected” here means that all the edges are in one component.
The direction “only if” of both parts is the degree argument of Section 1. The direction “if” needs a construction, and the one in the proof below was published by Carl Hierholzer (1840-1871) in 1873, two years after his death, from an account that a colleague wrote down after conversations with him. Its idea is called splicing: build one closed trail, and whenever it has left edges unused, build a second closed trail out of them and insert it into the first.
Figure 3. Hierholzer’s construction on a multigraph with 14 edges in which every degree is even. The first closed trail from vertex 1 is \(1\,2\,3\,1\) (thick). The second trail starts at 2, where the first one left edges unused, and the third uses the two parallel edges between 7 and 8. The small numbers give the position of each edge in the spliced tour.
2.1 Fleury’s rule
Splicing builds the tour in pieces. A walker who wants to trace the tour in one go, without ever going back to insert a detour, needs a rule for choosing the next edge, and such a rule was given by Fleury in 1883. The rule speaks about an edge whose removal would disconnect the part of the multigraph that is still unused. Graph theorists call such an edge a bridge, and Unit 4 uses that word; in this unit the bridges of Königsberg are real bridges, so we say cut edge instead.
The rule works for the following reason. As long as the unused edges form a connected multigraph together with the current vertex, a non-cut edge keeps them connected after it is used, so the walker can still reach every unused edge. A cut edge is taken only when the current vertex has nothing else left, and then the walker can abandon that vertex without loss. The full argument is a page of case checking and is left out here. In practice the rule is slow, because testing whether an edge is a cut edge means checking connectedness at every step, and Hierholzer’s construction is what a computer runs. For a drawing on paper, Fleury’s rule is the natural one.
Figure 4. The house figure: a square with its two diagonals and a roof, 5 vertices and 8 edges, with the two odd vertices \(A\) and \(B\). The numbers give the order of the edges in the trail \(A\,B\,D\,A\,C\,D\,E\,C\,B\) found with Fleury’s rule.
Puzzles of this kind exist in great number, and the theorem settles every one of them at a glance: count the odd vertices, and if there are 0 or 2 the figure can be drawn in one stroke, otherwise it cannot. A practical cousin of the question is the Chinese postman problem, posed in 1960 by the Chinese mathematician Mei-Ko Kwan, later president of Shandong Normal University, whose name is also written Meigu Guan, and translated into English in 1962. A postman must walk along every street of a district and return to the depot, and the streets have lengths. If every street corner has even degree, an Euler tour is the shortest possible round, since it walks each street exactly once. If some corners have odd degree, the postman must walk some streets twice, and the problem becomes to choose the repeated streets so that the extra length is as small as possible. The odd corners are then paired off by the repeated streets, and the choice of the cheapest pairing is a matching problem whose solution is beyond this masterclass.
3 Hamilton cycles
Now change one word. Instead of a walk through every edge once, ask for a walk through every vertex once. A Hamilton path of a graph is a path that contains every vertex, and a Hamilton cycle is a cycle that contains every vertex. A graph with a Hamilton cycle is called Hamiltonian. Since a path and a cycle never repeat a vertex, the walker visits each vertex exactly once and may leave most of the edges unused; parallel edges and loops are of no help here, so this section deals with simple graphs.
The name comes from William Rowan Hamilton (1805-1865), who in 1856 studied such cycles on the graph of the dodecahedron, the Platonic solid with 20 corners, 30 edges, and 12 pentagonal faces. In a paper printed by the Royal Society in 1856, Thomas Kirkman (1806-1895) had asked which polyhedra have a cycle through all their corners, so the question is Kirkman’s as much as Hamilton’s, and Unit 6 explains why the corners and edges of a polyhedron form a planar graph. Figure 5 shows the dodecahedron graph with its three rings of vertices, flattened as if one face were stretched to become the outer boundary.
Figure 5. The dodecahedron graph: 20 vertices of degree 3 and 30 edges, drawn as an outer pentagon, a ring of ten, and an inner pentagon. The thick cycle \(1, 6, 15, 20, 16, 7, 8, 9, 17, 18, 19, 13, 14, 5, 4, 12, 11, 10, 3, 2\) is a Hamilton cycle; the graph has 30 of them (own computation).
3.1 What rules a Hamilton cycle out
For Euler tours there is a test that takes seconds. For Hamilton cycles there is none, and this is not for lack of trying. No condition is known that is both necessary and sufficient and can be checked quickly, and no method is known that finds a Hamilton cycle in a graph with a few thousand vertices in reasonable time unless the graph is special. In 1972 Richard Karp of the University of California, Berkeley, showed that the problem of deciding whether a given graph has a Hamilton cycle is NP-complete, which means, in words, that a fast method for it would give a fast method for every one of a large family of famous hard problems at once. The precise meaning of this statement is beyond the unit; Unit 8 says more about the two families of problems called P and NP and why most mathematicians expect no fast method to exist. What can be done at the level of this unit is to collect conditions that forbid a Hamilton cycle and conditions that guarantee one.
Three simple conditions forbid one. A Hamiltonian graph is connected, since the cycle joins every pair of vertices. A Hamiltonian graph has no cut vertex, a vertex whose removal disconnects the graph, because removing one vertex from a Hamilton cycle leaves a Hamilton path of the rest, which is connected. The third condition concerns the bipartite graphs of Unit 2 and needs a line of argument.
The reason is that every edge of a bipartite graph runs between the sides, so a cycle alternates between \(X\) and \(Y\) and uses the same number of vertices from each side. A Hamilton cycle uses all vertices, so \(|X| = |Y|\). A path alternates too, and the numbers it takes from the two sides differ by at most 1. For example, the complete bipartite graph \(K_{3,4}\) has a Hamilton path, which starts and ends on the larger side, but no Hamilton cycle, and \(K_{3,5}\) has neither.
3.2 The Petersen graph
The Petersen graph of Unit 1 passes all three tests. It is connected, it has no cut vertex (removing any vertex leaves a connected graph, as the reader can check in Figure 6), and it is not bipartite, since the outer pentagon is an odd cycle. It even has a Hamilton path, since the thick path \(1, 2, 3, 4, 5, 10, 7, 9, 6, 8\) in Figure 6(a) follows four edges of the outer pentagon, takes the spoke from 5 to 10, and then runs through the inner pentagram, and each of its nine steps is an edge. And yet it has no Hamilton cycle, which makes it the standard example of how little the simple tests settle.
Figure 6. (a) The Petersen graph with the Hamilton path \(1, 2, 3, 4, 5, 10, 7, 9, 6, 8\) drawn thick. (b) The shape a Hamilton cycle would have: a 10-cycle \(v_0, \ldots, v_9\) whose five chords each join vertices at distance at least 4 along the cycle; two of the chords are drawn (dashed). The chord \(v_0 v_4\) forces the chord \(v_5 v_9\), and the four vertices \(v_0, v_4, v_5, v_9\) then span a 4-cycle (shaded), which the Petersen graph does not contain.
4 Dirac’s theorem and Ore’s theorem
Conditions that guarantee a Hamilton cycle go in the other direction, and the most useful ones ask for many edges. A graph with every possible edge, the complete graph \(K_n\), is Hamiltonian for \(n \ge 3\), since any ordering of its vertices is a Hamilton cycle. How many edges can be taken away before this fails? The answer in terms of the minimum degree \(\delta(G)\) of Unit 1 was found by Gabriel Andrew Dirac (1925-1984) in 1952.
The condition \(n \ge 3\) is needed, because a single edge satisfies the degree condition with \(n = 2\) and has no cycle. The bound \(n/2\) cannot be lowered, and two families of graphs show this. The complete bipartite graph \(K_{k, k+1}\) has \(n = 2k + 1\) vertices and minimum degree \(k\), which is just below \(n/2 = k + 1/2\), and it has no Hamilton cycle by the bipartite obstruction; for example, \(K_{3,4}\) has 7 vertices, minimum degree 3, and no Hamilton cycle. In the same way, two copies of \(K_{k+1}\) glued together at one vertex have \(n = 2k + 1\) vertices and minimum degree \(k\), and the shared vertex is a cut vertex. The theorem is a guarantee in one direction only. A graph that fails the degree condition may still have a Hamilton cycle; the cycle \(C_n\) itself has every degree equal to 2 and is Hamiltonian for every \(n \ge 3\), so a minimum degree below \(n/2\) tells nothing either way. The proof uses the two methods that Unit 1 introduced as the extremal principle and the pigeonhole principle, applied to a longest path.
The proof is constructive once a longest path is in hand, because an index that lies in both \(S\) and \(T\) can be found by inspection, and the Hamilton cycle appears with it. Figure 7 shows the argument on a small graph.
Figure 7. A graph on 8 vertices with 17 edges in which every vertex has degree at least 4, with a longest path drawn thick. Its ends 1 and 7 are not adjacent, but 1 is adjacent to the third vertex of the path and 7 to the second, and the two dashed chords cross. Following the path forward from 3, jumping back from 7 to 2, and returning to 1 gives the Hamilton cycle \(1, 3, 4, 5, 6, 8, 7, 2, 1\).
Dirac’s condition asks a lot of every single vertex. Øystein Ore (1899-1968) noticed in 1960 that the proof only ever adds the degrees of two non-adjacent vertices. It does so in the connectedness argument and in the bound \(|S| + |T| \ge n\) for the two ends of the longest path, and nowhere else, so the proof shows more than Dirac had stated.
The proof above goes through word for word, since the ends \(v_1\) and \(v_k\) of the longest path are non-adjacent whenever the path does not close by itself, and a path that closes by itself is already the cycle the proof wants. Ore’s condition is also the starting point of a trick found by John Adrian Bondy and Václav Chvátal in 1976. As long as the graph has two non-adjacent vertices whose degrees add up to at least \(n\), join them by an edge, and repeat until no such pair is left. The graph obtained in this way is called the closure, and it has a Hamilton cycle if and only if the original graph has one. A graph whose closure is complete is therefore Hamiltonian, even when Ore’s condition fails for the graph itself.
5 Gray codes and the hypercube
Some graphs are too regular to leave the question open, and the hypercube is one of them. The hypercube \(Q_n\) of Unit 1 has the binary words of length \(n\) as vertices, with two words adjacent when they differ in exactly one position, so \(Q_3\) is the ordinary cube with its 8 corners and 12 edges. A Hamilton cycle of \(Q_n\) is an ordering of all \(2^n\) words in which neighbouring words differ in one bit, and the last word differs from the first in one bit. Such an ordering is called a Gray code, after Frank Gray (1887-1969), an engineer at Bell Laboratories who used it in a patent application of 1947, granted in 1953, for converting a continuously varying signal into binary numbers. His reason was practical. If a rotating disc carries the words in this order, a sensor that reads the disc near the boundary between two words can misread at most one bit, and the error is one step instead of a jump across the whole range.
The construction is proved by induction on \(n\). For \(n = 2\) the order \(00, 01, 11, 10\) is a cycle, since \(10\) and \(00\) differ in one bit. Suppose the words of length \(n - 1\) have been listed as a Hamilton cycle of \(Q_{n-1}\). In the forward list with a leading 0, neighbouring words still differ in one bit, and the same holds in the backward list with a leading 1. At the join, the last word of the forward list and the first of the backward list are the same word of length \(n - 1\) with different leading bits, so they differ in one bit, and the same is true of the first word of the forward list and the last word of the backward list, which closes the cycle. Every word of length \(n\) appears exactly once, since each word of length \(n - 1\) appears once with each leading bit.
Figure 8. The cube \(Q_3\) with its vertices labelled by binary words and the reflected Gray code \(000, 001, 011, 010, 110, 111, 101, 100\) drawn thick. Each step changes one bit, and the last word returns to the first.
To illustrate the construction, start from the cycle \(00, 01, 11, 10\) of \(Q_2\). Writing it forward with a leading 0 and backward with a leading 1 gives
\[
000,\ 001,\ 011,\ 010,\ 110,\ 111,\ 101,\ 100 ,
\]
and this is the thick cycle in Figure 8: each of the eight steps changes exactly one bit, including the last step from \(100\) back to \(000\), and every corner of the cube is visited once. The same recipe applied once more gives a cycle through the 16 vertices of \(Q_4\), and so on for every length.
6 The travelling salesman problem
Give the edges lengths and the question changes once more. A salesman must visit \(n\) cities, each once, and return home, and the distances between every two cities are known. Which order of the cities makes the round trip shortest? This is the travelling salesman problem. In the language of this unit, the cities and their distances form a complete graph \(K_n\) with a length on every edge, and the problem asks for a Hamilton cycle of smallest total length. The problem was studied in Vienna in the 1930s, among others by Karl Menger (1902-1985).
Every ordering of the cities is a round trip, but many orderings describe the same trip. Fix the home city as the start; the remaining \(n - 1\) cities can be arranged in \((n - 1)! = (n - 1)(n - 2) \cdots 2 \cdot 1\) orders, and each trip is counted twice in this way, once in each direction, so the number of different round trips is
\begin{equation}
\frac{(n-1)!}{2} . \label{eq:tours}
\end{equation}
For five cities this is \(4!/2 = 12\), for eight cities \(7!/2 = 2520\), for ten cities \(181{,}440\), and for twenty cities about \(6 \times 10^{16}\). A computer that checks a billion trips per second would need about two years for the twenty-city list, so trying every trip stops being an option somewhere around twenty cities even for a computer.
City
Paris
Prague
Vienna
Warsaw
Berlin
877
281
524
517
Paris
883
1033
1367
Prague
251
517
Vienna
556
Table 1. Great-circle distances in kilometres between five cities, computed from the coordinates of the city centres on a sphere with the Earth’s mean radius and rounded to whole kilometres.
Round Trip from Berlin
Length (km)
Paris, Prague, Vienna, Warsaw
3084
Paris, Vienna, Prague, Warsaw
3195
Paris, Vienna, Warsaw, Prague
3264
Prague, Paris, Vienna, Warsaw
3270
Paris, Warsaw, Vienna, Prague
3332
Paris, Prague, Warsaw, Vienna
3357
Prague, Vienna, Paris, Warsaw
3449
Vienna, Paris, Prague, Warsaw
3474
Paris, Warsaw, Prague, Vienna
3536
Vienna, Prague, Paris, Warsaw
3542
Prague, Paris, Warsaw, Vienna
3611
Prague, Warsaw, Paris, Vienna
3722
Table 2. The 12 round trips through the five cities of Table 1, each starting and ending in Berlin, sorted by length. The shortest trip is the first.
The travelling salesman problem is at least as hard as the Hamilton cycle problem, and the reason is a short translation of one problem into the other. Given any graph \(G\) on \(n\) vertices, let the vertices be the cities, give every edge of \(G\) the length 1, and give every pair of vertices that is not an edge of \(G\) the length 2. A round trip of length exactly \(n\) uses only edges of length 1, so it is a Hamilton cycle of \(G\), and a Hamilton cycle of \(G\) is a round trip of length \(n\). A method that found the shortest round trip quickly would therefore decide quickly whether \(G\) has a Hamilton cycle, which is the NP-complete problem of Section 3. In practice the problem is attacked with clever bounds rather than with the list of all trips: in 1954 George Dantzig (1914-2005), Ray Fulkerson (1924-1976), and Selmer Johnson (1916-1996) found the shortest round trip through 49 cities of the United States, one in each of the 48 states of the time and Washington, and in 2006 the program Concorde of William Cook (University of Waterloo) and six collaborators found and certified the shortest round trip through 85,900 points, the largest instance solved to this day with a proof that no shorter trip exists. For distances that obey the triangle inequality, as real distances do, approximate methods that find trips guaranteed to be at most 50 per cent longer than the shortest one have existed since 1976, and the further reading of this unit tells where that guarantee stands today.
This is one of 16 units
Participants also get the quiz, the further reading, and the final exam.