Hamilton Paths and Circuits

A Hamilton path is a path in a graph that visits every vertex exactly once. A Hamilton circuit is a Hamilton path that returns to its starting vertex. Unlike Euler paths, there is no simple degree test for Hamilton paths and circuits, but theorems such as Dirac’s and Ore’s guarantee them in graphs with many edges.

Before this lesson: Graph Theory Basics and Euler Paths and Circuits

The idea

An Euler path uses every edge once. A Hamilton path visits every vertex once. Think of a salesperson who must stop in each city exactly once: the roads they skip do not matter, but no city can be missed or repeated.

The two questions sound alike, but they behave very differently. Euler’s question has a quick answer from the degrees. For Hamilton paths, no quick test is known, so we combine a few rules that force a circuit to exist, a few rules that rule one out, and careful searching.

Hamilton path and circuit definitions

  • A Hamilton path (or Hamiltonian path) visits every vertex of the graph exactly once.
  • A Hamilton circuit (Hamiltonian circuit or cycle) is a closed route that visits every vertex exactly once and returns to the start. It needs at least 3 vertices.
  • A graph that has a Hamilton circuit is called Hamiltonian.

A Hamilton path never repeats a vertex, so it never repeats an edge either. With n vertices, a Hamilton path uses n − 1 edges and a Hamilton circuit uses n edges. The circuit A, B, C, D, A is the same circuit as B, C, D, A, B and as A, D, C, B, A, because it uses the same edges.

Theorems that guarantee a Hamilton circuit

Let G be a simple graph with n ≥ 3 vertices.

  • Dirac’s theorem: if every vertex has degree at least n/2, then G has a Hamilton circuit.
  • Ore’s theorem: if \deg(u) + \deg(v) \ge n for every pair of vertices u and v that are not adjacent, then G has a Hamilton circuit.

Both theorems are one-way. If the condition holds, a circuit exists. If it fails, the graph may still be Hamiltonian: the cycle on 6 vertices has every degree equal to 2, which is less than 6/2 = 3, yet the cycle itself is a Hamilton circuit. Ore’s theorem is stronger than Dirac’s, because degrees of at least n/2 always add to at least n.

Ways to show there is no Hamilton circuit

  • A vertex of degree 1. A circuit enters and leaves every vertex, so every vertex needs degree at least 2.
  • Degree-2 vertices force edges. Both edges at a degree-2 vertex must be in the circuit. If the forced edges close a smaller loop or give some vertex three circuit edges, there is no Hamilton circuit.
  • A cut vertex or a bridge. If removing one vertex (a cut vertex) or one edge (a bridge) disconnects the graph, a circuit cannot cross that point and come back, so the graph is not Hamiltonian.
  • Unequal bipartite sides. In a bipartite graph, a circuit alternates between the two sides, so it needs the same number of vertices on each side. A Hamilton path needs the side sizes to differ by at most 1.

Counting Hamilton circuits in a complete graph

In the complete graph K_n, every vertex is joined to every other. Fix a starting vertex. The other n − 1 vertices can come in any order, giving (n − 1)! orders by the permutations count. Each circuit is counted twice, once in each direction, so

\text{number of Hamilton circuits in } K_n = \frac{(n-1)!}{2}

This number grows very fast. For 10 cities there are 9!/2 = 181,440 circuits, which is why the cheapest one is hard to find by listing them all.

Hamilton path and circuit examples

Example 1: Finding a Hamilton circuit

The “house” graph has a square with corners A, B, C, D (A and B on top) and a roof vertex E, with edges AB, BC, CD, DA, AE and EB. Find a Hamilton circuit.

\deg(E) = 2

E lies only on AE and EB, so both edges must be in the circuit.

A, E, B

Use the forced edges: go over the roof from A to B.

A, E, B, C

From B, the only unvisited neighbor is C.

A, E, B, C, D

From C, go to the last unvisited vertex, D.

A, E, B, C, D, A

DA is an edge, so return to the start.

AE, EB, BC, CD, DA

Check: 5 edges for 5 vertices, and every vertex appears once before the return.

The house graph with vertices A, B, C, D and roof vertex E. The Hamilton circuit A, E, B, C, D, A is drawn as thick solid blue edges numbered 1 to 5 in order; the unused edge AB is a thin dashed gray line.
The Hamilton circuit A, E, B, C, D, A skips edge AB, and that is allowed: a Hamilton circuit must visit every vertex, not use every edge.

Answer: A, E, B, C, D, A is a Hamilton circuit. Edge AB is not used, which is fine.

Example 2: Showing there is no Hamilton circuit

The “bowtie” graph has edges AB, BC, CA, CD, DE and EC: two triangles that share vertex C. Does it have a Hamilton circuit? Does it have a Hamilton path?

\deg(A) = 2

A lies only on AB and AC, so both edges are forced.

\deg(B) = 2

B lies only on AB and BC, so BC is forced too.

CA, AB, BC

These forced edges already form the closed loop C, A, B, C.

3 \lt 5

That loop visits only 3 of the 5 vertices, so no Hamilton circuit exists.

A, B, C, D, E

A path does not have to close: go around one triangle, through C, then the other.

AB, BC, CD, DE

Check: 4 edges for 5 vertices, each vertex once.

Answer: there is no Hamilton circuit, but A, B, C, D, E is a Hamilton path. The Euler circuit lesson showed that this same graph has an Euler circuit, so the two ideas really are independent.

Example 3: Using Dirac’s theorem

Show that the complete bipartite graph K_{3,3}, with sides {a₁, a₂, a₃} and {b₁, b₂, b₃}, has a Hamilton circuit, and find one.

n = 6

Count the vertices: 3 on each side.

\frac{n}{2} = \frac{6}{2} = 3

Find Dirac’s degree bound.

\deg(v) = 3

Each vertex is joined to all 3 vertices on the other side.

3 \ge 3

Every degree meets the bound, so Dirac’s theorem says a Hamilton circuit exists.

a_1, b_1, a_2, b_2, a_3, b_3, a_1

Alternate sides; every a is adjacent to every b.

Answer: K_{3,3} is Hamiltonian, and a₁, b₁, a₂, b₂, a₃, b₃, a₁ is a Hamilton circuit.

Example 4: Using Ore’s theorem when Dirac’s fails

Graph G has vertices 1 to 5. Vertices 1, 2, 3 and 4 are all joined to each other, and vertex 5 is joined to 1 and 2. Show that G has a Hamilton circuit.

\deg(1) = \deg(2) = 3 + 1 = 4

Each is joined to the other three of 1–4, plus to 5.

\deg(3) = \deg(4) = 3

Each is joined to the other three of 1–4.

\deg(5) = 2

Vertex 5 is joined to 1 and 2.

2 \lt \frac{5}{2}

Dirac’s theorem does not apply, because vertex 5 is below the bound.

\{3, 5\},\ \{4, 5\}

These are the only pairs of vertices that are not adjacent.

\deg(3) + \deg(5) = 3 + 2 = 5

Check the first pair against n = 5.

\deg(4) + \deg(5) = 3 + 2 = 5

Check the second pair.

5 \ge 5

Both sums reach n, so Ore’s theorem says a Hamilton circuit exists.

5, 1, 3, 4, 2, 5

Find one: leave 5 toward 1, cover 3 and 4, and come back through 2.

51, 13, 34, 42, 25

Check: all five are edges, and each vertex appears once.

Answer: G is Hamiltonian; one Hamilton circuit is 5, 1, 3, 4, 2, 5.

Example 5: The cheapest delivery route (word problem)

A driver leaves a depot D, delivers to stores P, Q and R, and returns to D. The road distances in miles are DP = 4, DQ = 7, DR = 5, PQ = 3, PR = 6 and QR = 2. Which route is shortest?

\frac{(4-1)!}{2} = \frac{6}{2} = 3

Every pair of places is joined, so this is K_4, with 3 different circuits.

4 + 3 + 2 + 5 = 14

Route D, P, Q, R, D: add DP, PQ, QR and RD.

4 + 6 + 2 + 7 = 19

Route D, P, R, Q, D: add DP, PR, RQ and QD.

7 + 3 + 6 + 5 = 21

Route D, Q, P, R, D: add DQ, QP, PR and RD.

14 \lt 19 \lt 21

Compare the three totals.

A complete graph on four places: depot D at top left, P at top right, Q at bottom right and R at bottom left. Edge lengths are DP 4, PQ 3, QR 2, RD 5 around the outside and DQ 7, PR 6 on the diagonals. The shortest route D, P, Q, R, D runs around the outside in thick solid blue; the diagonals are thin dashed gray.
The shortest route goes around the outside, 4 + 3 + 2 + 5 = 14 miles; both routes that use a diagonal are longer.

Answer: D, P, Q, R, D (or the same loop backward) is shortest, at 14 miles. Finding the cheapest Hamilton circuit in a weighted complete graph is called the traveling salesman problem.

Common mistakes

MistakeExample of the errorFix
Mixing up Hamilton and Euler“The bowtie has all even degrees, so it has a Hamilton circuit.”Even degrees give an Euler circuit (every edge). A Hamilton circuit is about visiting every vertex once.
Thinking every edge must be used“The house graph has no Hamilton circuit, because AB is left over.”A Hamilton circuit may skip edges; only vertices matter.
Using Dirac’s theorem backward“The 6-cycle fails Dirac’s bound, so it has no Hamilton circuit.”Dirac’s and Ore’s theorems only guarantee a circuit. Failing them proves nothing.
Checking Ore’s condition on adjacent pairsAdding the degrees of every pair in Example 4Ore’s condition is only needed for pairs that are not adjacent.
Counting the same circuit more than once“K_4 has 3! = 6 Hamilton circuits.”A circuit and its reverse are the same, and the start does not matter: (4 − 1)!/2 = 3.
Repeating a vertexD, P, Q, P, R, DEach vertex appears once; only the start repeats, at the very end of a circuit.

Related ideas

Why there is no simple test

Deciding whether a graph has a Hamilton circuit is an NP-complete problem. No one knows a method that is fast for every large graph, and finding one would settle the famous P versus NP question. So in practice, we use the sufficient conditions above, the rules for showing none exists, and organized searching (backtracking).

The nearest neighbor method

For large traveling salesman problems, a quick heuristic is the nearest neighbor method: from the current place, always go to the closest place not yet visited, then return home. In Example 5, starting at D it goes to P (4), then Q (3), then R (2), then back to D (5), which happens to find the best route. In general it is fast but not always the cheapest.

Hamilton paths in puzzles

A knight’s tour on a chessboard is a Hamilton path in the graph whose vertices are squares and whose edges are knight moves. Gray codes, which list binary strings so that neighbors differ in one bit, are Hamilton paths on a cube-shaped graph.

Practice problems

  1. Find a Hamilton circuit in K_4 with vertices A, B, C and D.
  2. How many different Hamilton circuits does K_5 have?
  3. Does the star K_{1,3} (a center joined to three outer vertices) have a Hamilton path?
  4. Every vertex of a simple graph with 8 vertices has degree 4. Must it have a Hamilton circuit?
  5. Does Dirac’s theorem apply to the cycle C_6? Is C_6 Hamiltonian?
  6. Does K_{2,3} have a Hamilton circuit? Does it have a Hamilton path?
  7. Graph G is two triangles ABC and DEF joined by the edge CD. Does G have a Hamilton circuit? A Hamilton path?
  8. A wheel has a hub H joined to every vertex of the 5-cycle 1, 2, 3, 4, 5, 1. Find a Hamilton circuit.
  9. A tour starts and ends at city A and visits B, C and D. The distances are AB = 8, AC = 12, AD = 9, BC = 6, BD = 11 and CD = 7. Find the shortest tour.
  10. The 3 × 3 grid graph has 9 vertices (the points of a tic-tac-toe board) and edges between horizontal and vertical neighbors. Does it have a Hamilton circuit? A Hamilton path?
Show answers

1.

A, B, C, D, A

In K_4 every pair is adjacent, so any order works.

AB, BC, CD, DA

Check: 4 edges, each vertex once.

Answer: A, B, C, D, A

2.

\frac{(5-1)!}{2} = \frac{4!}{2}

Use the count for K_n with n = 5.

\frac{24}{2} = 12

Evaluate 4! = 24, then divide.

Answer: 12

3.

\deg = 1,\ 1,\ 1

Each outer vertex has degree 1, so it must be an end of the path.

3 \gt 2

A path has only 2 ends, but there are 3 outer vertices.

Answer: no

4.

\frac{8}{2} = 4

Find Dirac’s degree bound.

4 \ge 4

Every degree meets the bound.

Answer: yes, by Dirac’s theorem

5.

\frac{6}{2} = 3

Find Dirac’s degree bound.

2 \lt 3

Every degree is 2, so Dirac’s theorem does not apply.

1, 2, 3, 4, 5, 6, 1

The cycle itself visits every vertex once.

Answer: Dirac’s theorem does not apply, but C_6 is Hamiltonian

6.

2 \ne 3

A circuit alternates sides, so it needs equal sides; these sides have 2 and 3 vertices.

b_1, a_1, b_2, a_2, b_3

A path can start and end on the larger side.

Answer: no Hamilton circuit; b₁, a₁, b₂, a₂, b₃ is a Hamilton path

7.

CD \text{ is a bridge}

Removing CD splits G into the two triangles.

\text{no circuit}

A circuit that crosses a bridge cannot get back.

A, B, C, D, E, F

Cover one triangle, cross CD, cover the other.

AB, BC, CD, DE, EF

Check: 5 edges for 6 vertices, each vertex once.

Answer: no Hamilton circuit; A, B, C, D, E, F is a Hamilton path

8.

1, 2, 3, 4, 5

Go along the rim from 1 to 5.

H, 1, 2, 3, 4, 5, H

Start and end at the hub, which is joined to 1 and to 5.

Answer: H, 1, 2, 3, 4, 5, H

9.

8 + 6 + 7 + 9 = 30

Tour A, B, C, D, A: add AB, BC, CD and DA.

8 + 11 + 7 + 12 = 38

Tour A, B, D, C, A: add AB, BD, DC and CA.

12 + 6 + 11 + 9 = 38

Tour A, C, B, D, A: add AC, CB, BD and DA.

30 \lt 38

These are all (4 − 1)!/2 = 3 tours; compare.

Answer: A, B, C, D, A (or its reverse), 30 units

10.

5 \text{ and } 4

Color the points like a checkerboard: 5 corner-and-center points, 4 edge-middle points. Every edge joins the two colors.

5 \ne 4

The graph is bipartite with unequal sides, so there is no Hamilton circuit.

5 - 4 = 1

The sides differ by 1, so a Hamilton path is still possible.

1, 2, 3, 6, 5, 4, 7, 8, 9

Number the points 1–9 by rows and snake back and forth.

Answer: no Hamilton circuit; the “snake” 1, 2, 3, 6, 5, 4, 7, 8, 9 is a Hamilton path

Hamilton paths and circuits FAQ

What is the difference between a Hamilton path and an Euler path?

A Hamilton path visits every vertex exactly once and may skip edges. An Euler path uses every edge exactly once and may revisit vertices.

How do you know if a graph has a Hamilton circuit?

There is no simple test that works for every graph. Dirac’s or Ore’s theorem can prove that a circuit exists, while a degree-1 vertex, a cut vertex, a bridge or unequal bipartite sides prove that none does; otherwise, search for one.

How many Hamilton circuits does a complete graph have?

The complete graph K_n with n ≥ 3 has (n − 1)!/2 different Hamilton circuits. For example, K_5 has 4!/2 = 12.

Is a Hamilton circuit the same as a Hamiltonian cycle?

Yes. Hamilton circuit, Hamiltonian circuit and Hamiltonian cycle all name a closed route that visits every vertex exactly once.

Summary

  • A Hamilton path visits every vertex exactly once; a Hamilton circuit also returns to its start.
  • Hamilton circuits may skip edges, and there is no simple degree test for them.
  • Dirac’s theorem (every degree at least n/2) and Ore’s theorem (nonadjacent degree sums at least n) guarantee a Hamilton circuit.
  • Degree-1 vertices, forced edges at degree-2 vertices, cut vertices, bridges and unequal bipartite sides can show that none exists.
  • K_n has (n − 1)!/2 Hamilton circuits; finding the cheapest one is the traveling salesman problem.

Previous lesson: Euler Paths and Circuits

Next lesson: Graph Coloring

Back to the Discrete Math Index