A Hamiltonian path, also called a Hamilton path, is a graph path that visits each vertex of a graph exactly once (Knuth 2025, p. 1). The counts in this entry exclude paths of length 0, so a one-vertex graph has count 0. For a path visiting at least three vertices, an edge joining its endpoints closes it into a Hamiltonian cycle (or Hamilton cycle).
A graph that possesses a Hamiltonian path is called a traceable graph.
In general, the problem of determining whether a graph has a Hamiltonian path is NP-complete (Garey and Johnson 1983, pp. 199-200).
If a bipartite graph has bipartition classes
and
,
then any Hamiltonian path alternates between
and
, so
is necessary. In particular, a connected bipartite graph whose bipartition
classes differ in size by more than 1 is untraceable.
The converse does not hold in general; examples with bipartition
sizes differing by 0 that are untraceable include
the E graph and H graph, and
examples with sizes differing by 1 that are untraceable
include the fork graph and spoke
graph
.
More generally, if a graph on
vertices has a Hamiltonian
path, then every other edge of the path
gives a matching of size
. Thus traceability requires
, where
is the matching number
and
is the floor function. Equivalently, a graph
with
is untraceable.
Finding a single Hamiltonian path of a graph is implemented in the Wolfram
Language as FindHamiltonianPath[g].
A precomputed list of all Hamiltonian paths for many named graphs
can be obtained using GraphData[graph,
"HamiltonianPaths"], with both orientations of paths
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 over all nonisomorphic 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
distinct vertices and
can be found using an algorithm
for Hamiltonian cycles. Add a new vertex
adjacent only to
and
. The augmented graph has a Hamiltonian
cycle iff the original graph
has a Hamiltonian path from
to
. Deleting
from such a cycle gives the
desired path. Alternatively, for graphs
on at least three vertices, add the edge
if necessary and require a Hamiltonian
cycle that uses that edge. An arbitrary Hamiltonian
cycle may avoid
and does not certify a Hamiltonian path with those endpoints.
The Lovász conjecture states that without exception, every connected vertex-transitive graph is traceable.
The following table summarizes the numbers of (undirected) Hamiltonian paths on various classes of graphs. The index of each value list in the table starts at 1. An X indicates that the family in that row is not defined for the corresponding parameter value. The counts exclude paths of length 0 even when the cited OEIS sequence includes a one-vertex path, as in OEIS A120443. The counts for the crown graph are half the directed counts in OEIS A137886.
| graph | OEIS | sequence |
| Andrásfai graph | A307932 | 1, 5, 72, 3047, 265034, 42442251, ... |
| antiprism graph | A307933 | X, X, 120, 408, 1200, 3240, 8330, 20720, ... |
| barbell graph | A001044 | 1, 1, 4, 36, 576, 14400, ... |
| A307934 | 0, 1, 4, 96, 25376, 32132352, ... | |
| cocktail
party graph | A307935 | 0, 4, 120, 6912, 631680, ... |
| complete
graph | A001710 | 0, 1, 3, 12, 60, 360, ... |
| complete
bipartite graph | A001044 | 1, 4, 36, 576, 14400, ... |
| complete
tripartite graph | A307936 | 3, 120, 18792, 7547904, ... |
| crossed prism graph | A308136 | X, X, X, 72, X, 288, X, 960, X, 2880, ... |
| crown graph | A137886 | 0, 0, 6, 72, 1920, 69120, ... |
| cycle graph | A000027 | X, X, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, ... |
| folded cube graph | A307948 | X, 1, 12, 576, 1006080, 28102446858240, ... |
| gear graph | A002378 | X, X, 12, 20, 30, 42, 56, 72, 90, 110, ... |
| grid graph | A120443 | 0, 4, 20, 276, 4324, 229348, 13535280, ... |
| grid graph | A308586 | 0, 72, 2480304, ... |
| halved cube graph | A308130 | 0, 1, 12, 6912, 23710679040, ... |
| Hanoi graph | A308134 | 3, 18, 192, 2730, ... |
| hypercube
graph | A284673 | 1, 4, 72, 45696, 93749829120, ... |
| Keller
graph | 0, 1006080, ... | |
| A308129 | 0, 12, 392, 171592, 364618672, ... | |
| A308131 | 0, 0, 0, 0, 864, 3318960, 82787609160, ... | |
| ladder
graph | A003682 | 1, 4, 8, 14, 22, 32, 44, 58, 74, 92, ... |
| Möbius ladder | A020875 | X, X, 36, 72, 140, 228, 364, 528, 756, ... |
| Mycielski graph | A308132 | 0, 1, 5, 490, 31629560, ... |
| odd graph | A301559 | 0, 3, 120, 328345920, ... |
| path
graph | A057427 | 0, 1, 1, 1, 1, 1, 1, 1, ... |
| prism
graph | A308137 | X, X, 30, 72, 130, 228, 350, 528, ... |
| A308139 | 0, 12, 22928, 10221735256, ... | |
| A308141 | 0, 4, 756, 11197440, ... | |
| Sierpiński carpet graph | A308138 | 8, 137728, ... |
| Sierpiński gasket graph | A246957 | 3, 12, 552, 6978816, 429714433137180672, ... |
| star graph | A171386 | 0, 1, 1, 0, 0, 0, 0, 0, ... |
| sun graph | A002378 | X, X, 12, 20, 30, 42, 56, 72, 90, 110, ... |
| tetrahedral Johnson graph | X, X, X, X, X, 808668610560, ... | |
| torus grid graph | A268838 | X, X, 756, 45696, 2955700, 560028096, ... |
| transposition graph | A307949 | 0, 1, 36, 27267618816, ... |
| triangular graph | A308142 | X, 0, 3, 120, 47760, ... |
| triangular grid graph | A308144 | 3, 12, 114, 1968, 66312, 4381020, 578266212, ... |
| wheel graph | A046092 | X, X, X, 12, 24, 40, 60, 84, 112, 144, ... |
| A308146 | X, 1, 4, 96, 12256, 32132352, 392007078912, ... |
Closed forms for the undirected counts for some of these classes of graphs are summarized in the following
table. The formulas for the complete graph and
path graph apply for , and the formula for the ladder
graph applies for
,
with the exceptional count 1 for
. The barbell and complete-bipartite formulas apply for
, and the cocktail-party and
-crossed-prism formulas for
. The cycle, gear, Möbius-ladder, prism, and sun
formulas require
,
and the wheel formula requires
.
| graph | formula |
| barbell graph | |
| cocktail party graph | |
| complete graph | |
| complete
bipartite 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. The antiprism recurrence is conjectural for (OEIS A307933).
The crown and prism recurrences apply for
and
, respectively.
| graph | order | recurrence |
| antiprism graph | 9 | |
| crown graph | 3 | |
| prism graph | 6 |