Yog.FSharp
Getting Started Examples API Reference GitHub

Eulerian Module

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

Problem

Algorithm

Function

Complexity

Eulerian circuit check

Degree counting

hasEulerianCircuit

O(V + E)

Eulerian path check

Degree counting

hasEulerianPath

O(V + E)

Find circuit

Hierholzer's

findEulerianCircuit

O(E)

Find path

Hierholzer's

findEulerianPath

O(E)

Necessary and Sufficient Conditions

Undirected Graphs: - Circuit: All vertices have even degree, connected (ignoring isolates) - Path: Exactly 0 or 2 vertices have odd degree, connected

Directed Graphs: - Circuit: In-degree = Out-degree for all vertices, weakly connected - Path: At most one vertex has (out - in) = 1 (start), at most one has (in - out) = 1 (end), all others balanced

Use Cases

  • Route planning: Garbage collection, snow plowing, mail delivery
  • DNA sequencing: Constructing genomes from overlapping fragments
  • Circuit board drilling: Optimizing drill paths for PCB manufacturing

Functions and values

Function or value Description

findEulerianCircuit graph

Full Usage: findEulerianCircuit graph

Parameters:
Returns: NodeId list option

Finds an Eulerian circuit in the graph.

graph : Graph<'n, 'e>
Returns: NodeId list option

findEulerianPath graph

Full Usage: findEulerianPath graph

Parameters:
Returns: NodeId list option

Finds an Eulerian path in the graph.

graph : Graph<'n, 'e>
Returns: NodeId list option

hasEulerianCircuit graph

Full Usage: hasEulerianCircuit graph

Parameters:
Returns: bool

Checks if the graph has an Eulerian circuit.

graph : Graph<'n, 'e>
Returns: bool

hasEulerianPath graph

Full Usage: hasEulerianPath graph

Parameters:
Returns: bool

Checks if the graph has an Eulerian path.

graph : Graph<'n, 'e>
Returns: bool