yog/properties/eulerian

Eulerian path and circuit algorithms using Hierholzer’s algorithm.

An Eulerian path visits every edge exactly once. An Eulerian circuit visits every edge exactly once and returns to the start. These problems originated from the famous Seven Bridges of Königsberg solved by Leonhard Euler in 1736, founding graph theory.

Algorithms

ProblemAlgorithmFunctionComplexity
Eulerian circuit checkDegree countinghas_eulerian_circuit/1O(V + E)
Eulerian path checkDegree countinghas_eulerian_path/1O(V + E)
Find circuitHierholzer’sfind_eulerian_circuit/1O(E)
Find pathHierholzer’sfind_eulerian_path/1O(E)

Key Concepts

Necessary and Sufficient Conditions

Undirected Graphs:

Directed Graphs:

Hierholzer’s Algorithm

  1. Start from any vertex (or odd-degree vertex for path)
  2. Follow unused edges until returning to start (forming a cycle)
  3. If unused edges remain, find vertex on current path with unused edges
  4. Form another cycle from that vertex and splice into main path
  5. Repeat until all edges used

Relationship to Other Problems

Use Cases

History

In 1736, Leonhard Euler proved that the Seven Bridges of Königsberg problem had no solution, establishing the conditions for Eulerian paths and founding graph theory as a mathematical discipline.

References

Values

pub fn find_eulerian_circuit(
  graph: model.Graph(n, e),
) -> option.Option(List(Int))

Finds an Eulerian circuit in the graph using Hierholzer’s algorithm.

Returns the path as a list of node IDs forming a circuit.

Time Complexity: O(E)

pub fn find_eulerian_path(
  graph: model.Graph(n, e),
) -> option.Option(List(Int))

Finds an Eulerian path in the graph using Hierholzer’s algorithm.

Returns the path as a list of node IDs.

Time Complexity: O(E)

pub fn has_eulerian_circuit(graph: model.Graph(n, e)) -> Bool

Checks if the graph has an Eulerian circuit.

Conditions

  • Undirected: All vertices even degree + connected.
  • Directed: All vertices balanced (in == out) + connected.

Time Complexity: O(V + E)

pub fn has_eulerian_path(graph: model.Graph(n, e)) -> Bool

Checks if the graph has an Eulerian path.

Conditions

  • Undirected: 0 or 2 odd-degree vertices + connected.
  • Directed: At most one (out - in = 1), at most one (in - out = 1), others balanced.

Time Complexity: O(V + E)

Search Document