Hamiltonian Path

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 >1 has no Hamiltonian paths.

Finding a single Hamiltonian path of a graph g 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 n=1, 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 i and j can be found if an algorithm for Hamiltonian cycles is available. This can be done by checking if the original graph G contains the edge (i,j) and adding it if not to obtain G^'. Since a Hamiltonian path with adjacent endpoints is a Hamiltonian cycle and since i and j are now adjacent, finding a Hamiltonian cycle and splitting at the edge gives a Hamiltonian path from i to j in G. Similarly, if no Hamiltonian cycle exists in G^', then there is no Hamiltonian path from i to j in G.

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

graphformula
barbell graph[(n-1)!]^2
cocktail party graph K_(n×2)(2n)!_1F_1(-n;-2n;-2)
complete graph K_nn!
complete bipartite graph K_(n,n)(n!)^2
2n-crossed prism graph6·2^(n-1)n(n+1)
cycle graph C_nn
gear graphn(n+1)
ladder graph P_2 square P_nn^2-n+2
Möbius ladder M_n1/2(-1)^nn[-1+(-1)^n(5+2n^2)]
path graph P_n1
prism graph Y_n1/2n[3+(-1)^n+2n^2]
sun graphn(n+1)
wheel graph W_n2(n-1)(n-2)

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

graphorderrecurrence
antiprism graph9a_n=a_(n-9)+a_(n-8)-3a_(n-7)-5a_(n-6)+5a_(n-5)+7a_(n-4)-4a_(n-3)-6a_(n-2)+5a_(n-1)
crown graph3a_n=n(n-1)^2a_(n-2)+(n-2)n(n-1)a_(n-3)+n(n-1)a_(n-1)
prism graph Y_n6a_n=-a_(n-6)+2a_(n-5)+a_(n-4)-4a_(n-3)+a_(n-2)+2a_(n-1)

Wolfram Web Resources

Mathematica »

The #1 tool for creating Demonstrations and anything technical.

Wolfram|Alpha »

Explore anything with the first computational knowledge engine.

Wolfram Demonstrations Project »

Explore thousands of free applications across science, mathematics, engineering, technology, business, art, finance, social sciences, and more.

Computerbasedmath.org »

Join the initiative for modernizing math education.

Online Integral Calculator »

Solve integrals with Wolfram|Alpha.

Step-by-step Solutions »

Walk through homework problems step-by-step from beginning to end. Hints help you try the next step on your own.

Wolfram Problem Generator »

Unlimited random practice problems and answers with built-in Step-by-step solutions. Practice online or make a printable study sheet.

Wolfram Education Portal »

Collection of teaching and learning tools built by Wolfram education experts: dynamic textbook, lesson plans, widgets, interactive Demonstrations, and more.

Wolfram Language »

Knowledge-based programming for everyone.