Graph Theory37 sections · 1633 units
Open in Course

Why Hierholzer Works

Intuition behind the algorithm.

Why does Hierholzer's algorithm work?

When you get stuck at vertex vv, you've used all edges incident to vv. Since degrees are even (or vv is an endpoint), you must be at the end of a valid path segment.

The stack stores your current position. By popping when stuck and pushing to the result, you build the path from end to start.

Invariant: At any point, unused edges still form a valid Eulerian subgraph. You can always find a path through them.

The reversed path at the end gives you the correct order from start to finish.