You are on page 1of 6

Hamiltonian Circuits

The Traveling Salesman Problem

In the last section, we considered optimizing a walking route for a postal carrier. How is
this different than the requirements of a package delivery driver? While the postal
carrier needed to walk down every street (edge) to deliver the mail, the package
delivery driver instead needs to visit every one of a set of delivery locations. Instead of
looking for a circuit that covers every edge once, the package deliverer is interested in a
circuit that visits every vertex once.

HAMILTONIAN CIRCUITS AND PATHS

A Hamiltonian circuit is a circuit that visits every vertex once with no repeats. Being a circuit,
it must start and end at the same vertex. A Hamiltonian path also visits every vertex once
with no repeats, but does not have to start and end at the same vertex.

Hamiltonian circuits are named for William Rowan Hamilton who studied them in the
1800’s.

EXAMPLE

One Hamiltonian circuit is shown on the graph below. There are several other Hamiltonian
circuits possible on this graph. Notice that the circuit only has to visit every vertex once; it does
not need to use every edge.
This circuit could be notated by the sequence of vertices visited, starting and ending at the
same vertex: ABFGCDHMLKJEA. Notice that the same circuit could be written in reverse order,
or starting and ending at a different vertex.

Unlike with Euler circuits, there is no nice theorem that allows us to instantly determine
whether or not a Hamiltonian circuit exists for all graphs.[1]
EXAMPLE

Does a Hamiltonian path or circuit exist on the graph below?

We can see that once we travel to vertex E there is no way to leave without returning to C, so
there is no possibility of a Hamiltonian circuit. If we start at vertex E we can find several
Hamiltonian paths, such as ECDAB and ECABD

This problem is called the Traveling salesman problem (TSP) because the question
can be framed like this: Suppose a salesman needs to give sales pitches in four cities.
He looks up the airfares between each city, and puts the costs in a graph. In what order
should he travel to visit each city once then return home with the lowest cost?

To answer this question of how to find the lowest cost Hamiltonian circuit, we will
consider some possible approaches. The first option that might come to mind is to just
try all different possible circuits.

question can be framed like this: Suppose a salesman needs to give sales pitches in
four cities. He looks up the airfares between each city, and puts the costs in a graph. In
what order should he travel to visit each city once then return home with the lowest
cost?
To answer this question of how to find the lowest cost Hamiltonian circuit, we will
consider some possible approaches. The first option that might come to mind is to just
try all different possible circuits.

BRUTE FORCE ALGORITHM (A.K.A. EXHAUSTIVE SEARCH)


1. List all possible Hamiltonian circuits
2. Find the length of each circuit by adding the edge weights
3. Select the circuit with minimal total weight.

EXAMPLE

Apply the Brute force algorithm to find the minimum cost Hamiltonian circuit on the graph below.

To apply the Brute force algorithm, we list all possible Hamiltonian circuits and calculate their
weight:

Circuit Weight

ABCDA 4+13+8+1 = 26

ABDCA 4+9+8+2 = 23

ACBDA 2+13+9+1 = 25

Note: These are the unique circuits on this graph. All other possible circuits are the reverse of
the listed ones or start at a different vertex, but result in the same weights.

From this we can see that the second circuit, ABDCA, is the optimal circuit.

https://courses.lumenlearning.com/math4liberalarts/chapter/introduction-euler-paths/
A Hamiltonian path, also called a Hamilton path, is a graph path between two vertices of a graph that visits each
vertex exactly once. If a Hamiltonian path exists whose endpoints are adjacent, then the resulting graph cycle is
called a Hamiltonian cycle (or Hamiltonian cycle).

A graph that possesses a Hamiltonian path is called a traceable graph.

In general, the problem of finding a Hamiltonian path is NP-complete (Garey and Johnson 1983, pp. 199-200), so the
only known way to determine whether a given general graph has a Hamiltonian path is to undertake an exhaustive
search

Any bipartite graph with a vertex parity unbalance has no Hamiltonian paths.

Finding a single Hamiltonian path of a graph is implemented in the Wolfram


Language as FindHamiltonianPath[g]. All Hamiltonian paths of a given graph can be found (inefficiently) using
the command HamiltonianPath[g, All] in the Wolfram Language package Combinatorica` . A
precomputed list of all Hamiltonian paths for many named graphs can be obtained
using GraphData[graph, "HamiltonianPaths"], where and both orientations of paths are included (so that
1, 2, 3 is considered distinct from 3, 2, 1 ). A precomputed count of the corresponding number of Hamiltonian
paths is given by GraphData[graph, "HamiltonianPathCount"].

The total numbers of directed Hamiltonian paths for all simple graphs of orders , 2, ... are 0, 2, 8, 50, 416,
5616, 117308, 4862736, ... (OEIS A193352).

Rubin (1974) describes an efficient search procedure that can find some or all Hamilton paths and circuits in a graph
using deductions that greatly reduce backtracking and guesswork. A probabilistic algorithm due to Angluin and
Valiant (1979), described by Wilf (1994), can also be useful to find Hamiltonian cycles and paths. A Hamiltonian path
between two vertices and can be found if an algorithm for Hamiltonian cycles is available. This can be done by
checking if the original graph contains the edge and adding it if not to obtain . Since a Hamiltonian path
with adjacent endpoints is a Hamiltonian cycle and since and are now adjacent, finding a Hamiltonian cycle and
splitting at the edge gives a Hamiltonian path from to in . Similarly, if no Hamiltonian cycle exists in , then
there is no Hamiltonian path from to in .

The following table summarizes the numbers of (undirected) Hamiltonian paths on various classes of graphs.

graph Sloane sequence

Andrásfai graph A137884 1, 5, 72, 3047, 265034, 42442251, ...

antiprism graph A124352 X, X, 120, 408, 1200, 3240, 8330, 20720, ...

barbell graph A048617 X, X, 4, 36, 576, 14400, ...

-black bishop graph A234632 X, X, X, 96, 25376, 32132352, ...

cocktail party graph A007060 4, 120, 6912, 631680, ...

complete graph A124355 0, 1, 3, 12, 60, 360, ...

complete bipartite graph A048617 1, 4, 36, 576, 14400, ...

complete tripartite graph A234633 3, 120, 18792, 7547904, ...

crossed prism graph A137885 X, X, X, 72, X, 288, X, 960, X, 2880, ...

crown graph A137886 X, X, 6, 72, 1920, 69120, ...


cycle graph A005843 X, X, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, ...

folded cube graph A137887 1, 12, 576, 1006080, 28102446858240, ...

gear graph A046092 X, X, 12, 20, 30, 42, 56, 72, 90, 110, ...

grid graph A096969 0, 4, 20, 276, 4324, 229348, 13535280, ...

grid graph A193346 0, 72, 2480304, ...

halved cube graph A137888 0, 1, 12, 6912, 23710679040, ...

Hanoi graph A137889 3, 18, 192, 2730, ...

hypercube graph A091299 1, 4, 72, 45696, 93749829120, ...

Keller graph A000000 0, 1006080, ...

-king graph A158651 X, 12, 392, 171592, 364618672, ...

-knight graph A000000 X, 0, 0, 0, 864, ...

ladder graph A137882 1, 4, 8, 14, 22, 32, 44, 58, 74, 92, ...

Möbius ladder A137883 X, X, 36, 72, 140, 228, 364, 528, 756, ...

Mycielski graph A137890 0, 1, 5, 490, 31629560, ...

odd graph A233826 0, 3, 120, 328345920, ...

path graph A000000 0, 1, 1, 1, 1, 1, 1, 1, ...

prism graph A124350 X, X, 30, 72, 130, 228, 350, 528, ...

-queen graph A158664 0, 12, 22928, 10221735256, ...

-rook graph A096970 1/2, 4, 756, 11197440, ...

Sierpiński sieve graph A234635 3, 12, 552, 6978816, 429714433137180672, ...

Sierpiński carpet graph A000000 0, 8, ...

star graph A000000 0, 1, 1, 0, 0, 0, 0, 0, ...

sun graph A046092 X, X, 12, 20, 30, 42, 56, 72, 90, 110, ...

tetrahedral graph A000000 X, X, X, X, X, 808668610560, ...

torus grid graph A000000 X, X, 756, 45696, 2955700, 560028096, ...

transposition graph A276518 0, 1, 36, 27267618816, ...

triangular graph A137892 0, 3, 120, 47760, ...

triangular grid graph A112675 3, 12, 114, 1968, 66312, 4381020, 57826621, ...

wheel graph A033996 X, X, X, 12, 24, 40, 60, 84, 112, 144, ...

-white bishop graph A234637 X, X, X, 96, 12256, 32132352, 392007078912, ...

Closed forms for some of these classes of graphs are summarized in the following table.
graph formula

barbell graph

cocktail party graph

complete graph

complete bipartite graph

-crossed prism graph

cycle graph

gear graph

ladder graph

Möbius ladder

path graph 1

prism graph

sun graph

wheel graph

Recurrence relations for the number of directed Hamiltonian paths for some graph families are summarized below.

graph order recurrence

antiprism graph 9

crown graph 3

prism graph 6

http://mathworld.wolfram.com/HamiltonianPath.html

You might also like