Eulerian and Hamiltonian Paths: Traversal Problems in Graph Theory

simulator intermediate ~10 min
Loading simulation...
Euler's theorem: a connected graph has an Eulerian circuit iff every vertex has even degree.

Euler's theorem (1736) gives an elegant criterion: a connected graph has an Eulerian circuit if and only if every vertex has even degree. An Eulerian path (not circuit) exists if and only if exactly two vertices have odd degree. Hierholzer's algorithm finds such paths in O(E) time.

Formula

Euler circuit exists ⟺ every vertex has even degree (connected graph)
Euler path exists ⟺ exactly 0 or 2 vertices have odd degree (connected graph)

The Problem That Started Graph Theory

In 1736, Leonhard Euler tackled a recreational puzzle: can you walk through the city of Königsberg, crossing each of its seven bridges exactly once? By abstracting the city into a graph — landmasses as vertices, bridges as edges — Euler proved the walk was impossible. His key insight: such a traversal requires that at most two vertices have an odd number of edges. All four Königsberg vertices had odd degree, so no solution existed. This paper is universally regarded as the birth of graph theory.

Eulerian Paths and Circuits

Euler's theorem gives a complete characterization: a connected graph has an Eulerian circuit (returning to the start) if and only if every vertex has even degree. It has an Eulerian path (starting and ending at different vertices) if and only if exactly two vertices have odd degree. Hierholzer's 1873 algorithm finds such paths in O(E) time by stitching together smaller circuits, making it one of the most efficient graph algorithms known.

The Hamiltonian Contrast

While Eulerian paths visit every edge once, Hamiltonian paths visit every vertex once. Despite the apparent similarity, the computational difference is staggering. No simple degree condition characterizes Hamiltonian graphs, and no polynomial-time algorithm is known — the decision problem is NP-complete. Sufficient conditions exist (Dirac's theorem: if every vertex has degree ≥ V/2, a Hamiltonian cycle exists), but they are far from necessary. This contrast beautifully illustrates the P vs NP divide.

From Bridges to DNA Sequencing

Eulerian paths have powerful modern applications. In genome sequencing, DNA is shattered into short overlapping fragments. By constructing a de Bruijn graph where fragments are edges, finding an Eulerian path through this graph reconstructs the original DNA sequence. This approach, used by assemblers like Velvet and SPAdes, processes billions of fragments efficiently because Eulerian path algorithms run in linear time — a direct practical payoff from Euler's 1736 insight.

FAQ

What is an Eulerian path?

An Eulerian path is a trail in a graph that visits every edge exactly once. An Eulerian circuit is an Eulerian path that starts and ends at the same vertex. Euler proved in 1736 that a connected graph has an Eulerian circuit if and only if every vertex has even degree, and an Eulerian path if exactly two vertices have odd degree.

What is a Hamiltonian path?

A Hamiltonian path visits every vertex exactly once. A Hamiltonian cycle visits every vertex exactly once and returns to the starting vertex. Unlike the Eulerian case, there is no simple necessary-and-sufficient condition for Hamiltonian paths, and determining their existence is NP-complete.

Why is the Eulerian path problem easy but the Hamiltonian path problem hard?

Eulerian paths have a clean characterization via vertex degrees, and Hierholzer's algorithm finds them in linear time. Hamiltonian paths lack any known polynomial-time characterization or algorithm. This gap between 'edge traversal' and 'vertex traversal' is one of the most striking illustrations of computational complexity.

What is the Königsberg bridge problem?

In 1736, Euler asked whether one could walk through Königsberg crossing each of its seven bridges exactly once. He modeled the city as a graph (landmasses as vertices, bridges as edges) and proved it was impossible because all four vertices had odd degree. This is considered the birth of graph theory.

Sources

Embed

<iframe src="https://homo-deus.com/lab/graph-theory/eulerian-path/embed" width="100%" height="400" frameborder="0"></iframe>
View source on GitHub