Eulerian Path
Traverse every edge exactly once by checking degree conditions and then building the walk with Hierholzer's algorithm.
Interactive visualization
Use the controls to connect the idea to concrete operations before diving into the full write-up.
Step 1 / 5
Current stack
Built path (reverse order)
Hierholzer builds the walk backward
Start Hierholzer from any valid start vertex.
Family
Graphs
Nodes, edges, traversal, connectivity, and shortest paths.
Builds on
2 topics
Read these first if you want the surrounding context.
Unlocks
0 next topics
Use these follow-ups when you want to apply the current idea in a richer setting.
Learning paths
2
This topic appears in curated progressions so you can keep moving without guessing the next step.
Problem
An Eulerian path visits every edge exactly once. If it starts and ends at the same vertex, it is an Eulerian circuit.
This is a graph-structure problem, not a shortest-path problem.
Core idea
First verify the graph has the right degree pattern.
For undirected graphs:
- circuit: every non-isolated vertex has even degree
- path: exactly two vertices have odd degree
Then build the walk with Hierholzer’s algorithm:
- keep walking unused edges while possible
- push vertices on a stack
- when stuck, pop into the answer
The path is constructed in reverse order.
Why it works
Whenever you reach a dead end, that piece must belong at the end of the unfinished Eulerian walk. Backtracking stitches local cycles and trails together automatically.
Complexity
| Operation | Time |
|---|---|
| Build Eulerian path/circuit |
Key takeaways
- Eulerian paths care about edge usage, not vertex reachability or shortest distance
- Degree conditions tell you whether a solution can exist before you even build it
- Hierholzer’s algorithm is a stack-based constructive proof
- This topic completes an important graph-structure branch beyond traversal and shortest paths
Practice problems
| Problem | Difficulty | Key idea |
|---|---|---|
| Reconstruct Itinerary | 🔴 Hard | Hierholzer on a directed multigraph with lexical tie-breaking |
| Teleporters Path | 🔴 Hard | Directed Eulerian path |
| Valid Arrangement of Pairs | 🔴 Hard | Eulerian trail framing |
Relation to other topics
- DFS helps verify the relevant connected component structure
- Stack is the implementation backbone of Hierholzer’s algorithm
- Bridges & Articulation Points study critical structure, while Eulerian paths study exact edge coverage structure
Build on these first
These topics supply the mental model or underlying structure that this page assumes.
DFS — Depth-First Search
Dive as deep as possible before backtracking. DFS is essential for detecting cycles, topological sorting, and exploring all paths in a graph.
Graph Fundamentals
Learn the core language of nodes, edges, paths, and cycles. Graphs are the broad container that trees, BFS, DFS, Dijkstra, and MST all live inside.
Related directions
These topics live nearby conceptually, even if they are not direct prerequisites.
Bridges and Articulation Points
Use DFS timestamps and low-link values to find the edges and vertices whose removal disconnects an undirected graph.
Stack & Monotonic Stack
LIFO data structure for expression evaluation, backtracking state, and the powerful monotonic stack pattern for next-greater-element problems.
More from Graphs
Stay in the same family when you want parallel variations of the same mental model.
BFS — Breadth-First Search
Explore a graph level by level using a queue. BFS finds the shortest path in unweighted graphs and is fundamental to many graph algorithms.
DFS — Depth-First Search
Dive as deep as possible before backtracking. DFS is essential for detecting cycles, topological sorting, and exploring all paths in a graph.
Graph Fundamentals
Learn the core language of nodes, edges, paths, and cycles. Graphs are the broad container that trees, BFS, DFS, Dijkstra, and MST all live inside.
0-1 BFS
Find shortest paths in graphs whose edge weights are only 0 or 1 using a deque instead of a heap.
Paths that include this topic
Follow one of these sequences if you want a guided next step instead of open-ended browsing.
Graph toolkit
Start with graph shape, then layer traversal, connectivity structure, and both single-source and all-pairs path algorithms.
Graph structure
Go beyond traversal into SCCs, critical edges, degree structure, and other non-shortest-path graph properties.
From the blog
Pair the atlas with recent writing from the rest of the site when you want a broader engineering perspective alongside the topic graph.