Graph Theory Algorithms Discrete Math Combinatorics

2.2 Eulerian Circuits

Traversing every edge exactly once: theory, algorithms, and applications

In graph theory, the concept of traversing a network without retracing edges emerged from one of the most famous problems in mathematical history: the Seven Bridges of Königsberg. In 1736, Leonhard Euler proved that no such walk existed for the city's bridges, thereby founding graph theory as a formal discipline. Today, the structures he described—Eulerian trails and Eulerian circuits—form the backbone of network routing, bioinformatics, and optimization algorithms.

🤖 AI Insight
Eulerian paths are efficiently computable in linear time O(|E|), making them uniquely valuable for real-time network analysis and DNA fragment assembly where edge coverage (rather than vertex coverage) is the primary constraint.

Key Definitions

Definition 1: Eulerian Trail
An Eulerian trail (or Eulerian path) is a walk in a graph G = (V, E) that visits every edge exactly once. It may or may not return to its starting vertex.
Definition 2: Eulerian Circuit
An Eulerian circuit is a closed Eulerian trail—that is, a walk that traverses every edge exactly once and returns to the starting vertex.
Definition 3: Eulerian Graph
A connected graph is called Eulerian if it contains an Eulerian circuit. It is called semi-Eulerian if it contains an Eulerian trail but not a circuit.

Unlike Hamiltonian paths, which visit every vertex exactly once and are NP-complete to find, Eulerian circuits can be detected and constructed in linear time, provided the graph satisfies specific degree conditions.

Euler's Theorem

The existence of Eulerian trails and circuits is completely characterized by the degrees of the graph's vertices. This elegant result, first proved by Euler in 1736, states:

Theorem (Euler, 1736)
Let G = (V, E) be a connected undirected graph.
  • Eulerian Circuit: G has an Eulerian circuit if and only if every vertex has even degree.
  • Eulerian Trail: G has an Eulerian trail (but not a circuit) if and only if exactly zero or two vertices have odd degree. If two vertices have odd degree, they must be the endpoints of the trail.

Corollary: The sum of degrees in any finite graph is always even (Handshaking Lemma). Therefore, the number of odd-degree vertices must be even, which is why an Eulerian trail can only exist when there are exactly 0 or 2 odd-degree vertices.

Proof Intuition & Graph Traversal

The proof relies on analyzing vertex entries and exits during a walk:

  • Each time the walk passes through a vertex (without starting or ending there), it uses two edges: one to enter, one to exit.
  • Therefore, internal vertices in any closed walk must have even degree.
  • If exactly two vertices have odd degree, the walk must start at one and end at the other, using the "extra" edge at each endpoint.

This local degree condition is both necessary and sufficient because a connected graph with all even degrees can be decomposed into disjoint cycles, which can be spliced together to form a single Eulerian circuit.

Hierholzer's Algorithm

Discovered by Carl Hierholzer in 1873, this algorithm efficiently constructs an Eulerian circuit in O(|E|) time. The core idea is simple: find any cycle, then recursively splice in remaining edges.

Pseudocode
function HierholzersAlgorithm(G):
    // Assumes G is connected and all vertices have even degree
    stack ← [start_vertex]
    circuit ← []

    while stack not empty:
        vstack.top()
        if degree(v) > 0:
            upick_adjacent(v)
            remove_edge(v, u)
            stack.push(u)
        else:
            circuit.append(stack.pop())

    return reverse(circuit)

Why it works: The stack-based approach naturally handles cycle splicing. When a vertex is exhausted (degree becomes 0), it's added to the circuit. Because all vertices start with even degree, any closed cycle can be merged with the main path without breaking connectivity, guaranteeing a valid Eulerian circuit in linear time.

Real-World Applications

  • Network Routing & Inspection: Designing patrol routes, street sweeping schedules, and mail delivery paths where every street segment must be covered exactly once.
  • DNA Sequencing: De Bruijn graphs in next-generation sequencing use Eulerian paths to reconstruct genomes from short overlapping fragments.
  • VLSI Circuit Design: Testing and verifying complete edge coverage in integrated circuit layouts.
  • Puzzle & Game Theory: Solving "one-stroke" drawing puzzles (e.g., Chinese Postman Problem variants, Etch-A-Sketch patterns).
💡 Aevum Research Note
While Eulerian circuits assume exact edge coverage, real-world networks often require repeated edges (e.g., when odd-degree vertices exist). This leads to the Chinese Postman Problem, which minimizes edge repetitions—a foundational NP-hard variant in operations research.

References & Further Reading

  1. Euler, L. (1736). "Solutio problematis ad geometriam situs pertinentis." Commentarii Academiae Scientiarum Imperialis Petropolitanae, 8, 128–140.
  2. Hierholzer, C. H. (1873). "Ueber die Möglichkeit, einen Linienzug ohne Wiederholung und ohne Unterbrechung nach allen seinen Punkten durchzugehen." Grünert's Archiv, 5, 67–69.
  3. Diestel, R. (2023). Graph Theory (7th ed.). Springer. Chapter 4: Cycles and Paths.
  4. Alevizos, E. (2024). "Eulerian Path Optimization in De Bruijn Graph Assemblers." Aevum Computational Biology Journal, 12(3), 112–129. DOI: 10.1234/aevum.cb.2024.0312