Mathwords logoMathwords

Hamiltonian Cycle — Definition, Formula & Examples

A Hamiltonian cycle is a path through a graph that starts at one vertex, visits every other vertex exactly once, and returns to the starting vertex. A graph that contains such a cycle is called Hamiltonian.

Given a graph G=(V,E)G = (V, E) with V=n|V| = n, a Hamiltonian cycle is a cycle v1,v2,,vn,v1v_1, v_2, \ldots, v_n, v_1 such that every vertex in VV appears exactly once in the sequence v1,v2,,vnv_1, v_2, \ldots, v_n and each consecutive pair (vi,vi+1)(v_i, v_{i+1}) as well as (vn,v1)(v_n, v_1) is an edge in EE.

How It Works

To check whether a graph has a Hamiltonian cycle, you look for a way to traverse all vertices exactly once and return to your starting point using only existing edges. There is no known efficient (polynomial-time) algorithm for this in general — determining whether a Hamiltonian cycle exists is a classic NP-complete problem. For small graphs, you can attempt a systematic search or backtracking. Sufficient conditions exist: Dirac's theorem states that if every vertex in a simple graph on n3n \geq 3 vertices has degree at least n2\frac{n}{2}, then the graph is Hamiltonian.

Worked Example

Problem: Determine whether the complete graph K4K_4 (four vertices, each connected to every other) has a Hamiltonian cycle.
Label the vertices: Call the four vertices AA, BB, CC, and DD. Every pair of distinct vertices shares an edge.
Construct a cycle visiting each vertex once: Start at AA, go to BB, then CC, then DD, and return to AA. The path is ABCDAA \to B \to C \to D \to A.
Verify: Each vertex appears exactly once before returning to AA, and every consecutive pair is an edge in K4K_4. This is a valid Hamiltonian cycle.
Answer: Yes, K4K_4 has a Hamiltonian cycle, for example ABCDAA \to B \to C \to D \to A.

Why It Matters

The Hamiltonian cycle problem is a foundational example in computational complexity, used to prove NP-completeness of other problems. It also underpins the Traveling Salesman Problem, which has direct applications in logistics, circuit board drilling, and DNA sequencing.

Common Mistakes

Mistake: Confusing a Hamiltonian cycle with an Eulerian circuit.
Correction: A Hamiltonian cycle visits every vertex exactly once; an Eulerian circuit traverses every edge exactly once. They impose fundamentally different requirements on the graph.