Skip to main content
Back to the DSA atlas
Graphs Algorithm Advanced

Eulerian Path

Traverse every edge exactly once by checking degree conditions and then building the walk with Hierholzer's algorithm.

graphspathsstackconnectivity

Interactive visualization

Use the controls to connect the idea to concrete operations before diving into the full write-up.

Step 1 / 5

Current stack

0

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:

  1. keep walking unused edges while possible
  2. push vertices on a stack
  3. 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

OperationTime
Build Eulerian path/circuitO(V+E)O(V + E)

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

ProblemDifficultyKey idea
Reconstruct Itinerary🔴 HardHierholzer on a directed multigraph with lexical tie-breaking
Teleporters Path🔴 HardDirected Eulerian path
Valid Arrangement of Pairs🔴 HardEulerian 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.

Related directions

These topics live nearby conceptually, even if they are not direct prerequisites.

More from Graphs

Stay in the same family when you want parallel variations of the same mental model.

Paths that include this topic

Follow one of these sequences if you want a guided next step instead of open-ended browsing.

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.