Login
📚 Contemporary Mathematics
Chapters ▾
⇩ Download ▾

12.7 Hamilton Cycles

A 3D model of an icosahedron.
Figure 12.155 The symmetries of an icosahedron, with 30 edges, 20 faces, and 12 vertices, can be analyzed using graph theory.The symmetries of an icosahedron, with 30 edges, 20 faces, and 12 vertices, can be analyzed using graph theory. (credit: "Really big icosahedron" by Clayton Shonkwiler/Wikimedia, CC BY 2.0)

Learning Objectives

After completing this section, you should be able to:

  1. Describe and identify Hamilton cycles.
  2. Compute the number of Hamilton cycles in a complete graph.
  3. Apply and evaluate weighted graphs.

In Euler Circuits and Euler Trails, we looked for circuits and paths that visited each edge of a graph exactly once. In this section, we will look for circuits that visit each vertex exactly once. Like many concepts in graph theory, the idea of a circuit that visits each vertex once was inspired by games and puzzles. As early as the 9th century, Indian and Islamic intellectuals wondered whether it was possible for a knight to visit every space on a chess board of a given size, which is equivalent to visiting every vertex of a graph that represents the chess board.

In 1857, a mathematician named William Rowan Hamilton invented a puzzle in which players were asked to find a route along the edges of a dodecahedron (see Figure 12.156), which visited every vertex exactly once. Let’s explore how graph theory provides insight into these games as well as practical applications such as the Traveling Salesperson Problem.

A 3D illustration of a truncated icosahedron, a polyhedron with pentagonal and hexagonal faces, rendered in shades of gray and blue.
Figure 12.156 A Dodecahedron

Hamilton’s Puzzle

Before we look at the solution to Hamilton's puzzle, let’s review some vocabulary we used in Figure 12.157. It will be helpful to remember that directed cycle is a type of circuit that doesn’t repeat any edges or vertices.

Three concentric ovals represent directed cycles, circuits, and closed walks. The first (inner) oval labeled directed cycles (closed paths) reads, no repeated edges or vertices. The second oval labeled circuits (closed talks) reads, no repeated edges. The third oval is labeled closed walks.
Figure 12.157 Closed Walks, Circuits, and Directed Cycles

The goal of Hamilton's puzzle was to find a route along the edges of the dodecahedron, which visits each vertex exactly once. A dodecahedron is a three-dimensional space figure with faces that are all pentagons as we saw in Figure 12.156.

Since it is easier to visualize two dimensions rather than three, we will flatten out the dodecahedron and look at the edges and vertices on a flat surface. Graph A in Figure 12.158 shows a two-dimensional graph of the edges and vertices, and Graph B shows an untangled version of Graph A in which no edges are crossing. Graph B in Figure 12.158 is very similar to the design of the game board that Hamilton invented for his puzzle.

Two graphs are labeled graph A and graph B. Graph A highlights the edges of a dodecahedron. Graph B highlights the vertices of a dodecahedron.
Figure 12.158 Graph of Edges and Vertices of Dodecahedron

We can see that this is a planar graph because it can be “untangled.” In order to solve Hamilton’s puzzle, we need to find a circuit that visits every vertex once. A solution is shown in Figure 12.159.

Two figures. The first figure is a 2 D view of a dodecahedron. The edges are highlighted. The second figure is a 3 D view of a dodecahedron. The edges in the front face are highlighted.
Figure 12.159 A Solution to Hamilton’s Puzzle

A circuit that doesn’t repeat any vertices, like the one in Figure 12.159, is called a directed cycle. So, we can most accurately say that Hamilton’s puzzle asks us to find a directed cycle that visits every vertex in a graph exactly once. Because Hamilton created and solved this puzzle, these special circuits were named Hamilton cycles, or Hamilton circuits.

Hamilton Cycles vs. Euler Circuits

Let’s practice naming and identifying Hamilton cycles, as well as distinguishing them from Euler circuits. It is important to remember that Euler circuits visit all edges without repetition, while Hamilton cycles visit all vertices without repetition. Hamilton cycles are named by their vertices just like all circuits. An example is given in Figure 12.160.

Two graphs. The first graph, graph Z has four vertices: a, b, c, and d. The edges connect a b, b c, c d, d a, and a c. The second graph directed edges from a to b, b to c, c to d, and d to a. A dashed line connects a to c.
Figure 12.160 Hamilton Cycle in Graph Z

Notice that the Hamilton cycle abcd for Graph Z in Figure 12.160 is NOT an Euler circuit, because it does not visit edge ac. Some Hamilton cycles are also Euler circuits while some are not, and some Euler circuits are Hamilton cycles while some are not.

Notice that the graph is a cycle. A cycle will always be Eulerian because all vertices are degree 2. Moreover, any circuit in the graph will always be both an Euler circuit and a Hamilton cycle. It is not always as easy to determine if a graph has a Hamilton cycle as it is to see that it has an Euler circuit, but there is a large group of graphs that we know will always have Hamilton cycles, the complete graphs. Since all vertices in a complete graph are adjacent, we can always find a directed cycle that visits all the vertices. For example, look at the directed six-cycle, nopqrs, in the complete graph with six vertices in Figure 12.162.

A directed graph has six vertices: o, p, q, r, s, and n. All the vertices are interconnected. Directed arrows flow from o to p, p to q, q to r, r to s, s to n, and n to o.
Figure 12.162 Directed Cycle in Complete Graph

That is not the only directed six-cycle in the graph though. We could find another just be reversing the direction, and we could find even more by using different edges. So, how many Hamilton cycles are in a complete graph with n vertices? Before we tackle this problem, let’s look at a shorthand notation that we use in mathematics which will be helpful to us.

Factorials

In many areas of mathematics, we must calculate products like 7654321 or 1110987654321, products that involve multiplying all the counting numbers from a particular number down to 1. Imagine that the product happened to be all the numbers from 100 down to 1. That’s a lot of writing! Instead of writing all of that out, mathematicians came up with a shorthand notation. For example, instead of 7654321, we write 7!, which is read “7 factorial.” In other words, the product of all the counting numbers from n down to 1 is called n factorial and it is written n!

A common use for factorials is counting the number of ways to arrange objects. Suppose that there were three students, Aryana, Byron, and Carlos, who wanted to line up in a row. How many arrangements are possible? There are six possibilities: ABC, ACB, BAC, BCA, CAB, or CBA. Notice that there were three students being arranged, and the number of possible arrangements is three.

Counting Hamilton Cycles in Complete Graphs

Now, let’s get back to answering the question of how many Hamilton cycles are in a complete graph. In Table 12.8, we have drawn all the four cycles in a complete graph with four vertices. Remember, cycles can be named starting with any vertex in the cycle, but we will name them starting with vertex a.

Table 12.8
Complete GraphCycleCycleCycle
Cycle Name Clockwise (a, b, c, d) (a, b, d, c) (a, c, b, d)
Cycle Name Counterclockwise(a, d, c, b)(a, c, d, b)(a, d, b, c)

Table 12.8 shows that there are three unique four-cycles in a complete graph with four vertices. Notice that there were two ways to name each cycle, one reading the vertices in a clockwise direction and one reading the vertices in a counterclockwise direction. This is important to us because we are interested in Hamilton cycles, which are directed cycles. Although the cycles (a, b, c, d) and (a, d, c, b) are the same cycle, the directed cycles, abcda and adcba, which travel the same route in reverse order are considered different directed cycles, as shown in Table 12.9.

Table 12.9
Complete GraphCycleCycleCycle
Clockwise Hamilton Cycle abcda abdca acbda
Counter-clockwise Hamilton Cycle adcba acdba adbca

The six directed four-cycles in Table 12.9 are the only distinct Hamilton cycles in a complete graph with four vertices. Six is also the number of ways to arrange the three letters b, c, and d. (Do you see why?) The number of ways to arrange three letters is 3!=321=6. Similarly, the number of Hamilton cycles in a graph with five vertices is the number of ways to arrange four letters, which is 4!=4321=24. In general, to find the number of Hamilton cycles in a graph, we take one less than the number of vertices and find its factorial.

Weighted Graphs

Suppose that an officer in the U.S. Air Force who is stationed at Vandenberg Air Force base must drive to visit three other California Air Force bases before returning to Vandenberg. The officer needs to visit each base once. The vertices in the graph in Figure 12.164 represent the four U.S. Air Force bases, Vandenberg, Edwards, Los Angeles, and Beale. The edges are labeled to with the driving distance between each pair of cities.

A graph represents the four California air force bases. The graph has four vertices: E, B, V, and L. The edge, E B is labeld 410 miles. The edge, B V is labeled 396 miles. The edge, V L is labeled 159 miles. The edge, L E is labeled 106 miles. The edge, L B is labeled 439 miles. The edge, E V is labeled 207 miles.
Figure 12.164 Graph of Four California Air Force Bases

The graph in Figure 12.164 is called a weighted graph, because each edge has been assigned a value or weight. The weights can represent quantities such as time, distance, money, or any quantity associated with the adjacent vertices joined by the edges. The total weight of any walk, trail, or path is the sum of the weights of the edges it visits.

Notice that the officer’s trip can be represented as a Hamilton cycle, because each of the four vertices in the graph is visited exactly once.

Key Terms

  • Hamilton cycle, or Hamilton circuit
  • n factorial
  • weighted graph
  • total weight

Key Concepts

  • A Hamilton cycle is a directed cycle, or circuit, that visits each vertex exactly once.
  • Some Hamilton cycles are also Euler circuits, but some are not.
  • Hamilton cycles that follow the same undirected cycle in the same direction are considered the same cycle even if they begin at a different vertex.
  • The number of unique Hamilton cycles in a complete graph with n vertices is the same as the number of ways to arrange n1 distinct objects.
  • Weighted graphs have a value assigned to each edge, which can represent distance, time, money and other quantities.

Formulas

The number of ways to arrange n distinct objects is n!.

The number of distinct Hamilton cycles in a complete graph with n vertices is (n1)!.

Adapted from Contemporary Mathematics by OpenStax (openstax.org), licensed under CC BY-NC-SA 4.0. Changes were made. License: CC-BY-NC-SA-4.0.