Skip to main content

Hierholzer's Algorithm

Hierholzer's Algorithm is a graph method for finding an Eulerian path or Eulerian circuit by following edges and splicing closed walks together. In combinatorics, it shows up when a graph’s degree conditions guarantee an edge-by-edge traversal.

Last updated July 2026

What is Hierholzer's Algorithm?

Hierholzer's Algorithm is the standard way to construct an Eulerian path or Eulerian circuit in combinatorics. Instead of guessing a route, you keep walking along unused edges until you get stuck, then you splice that walk into the rest of the route.

That splicing idea is what makes the algorithm feel different from a simple graph traversal. A depth-first search is usually about visiting vertices, but Hierholzer's Algorithm is about using every edge exactly once. If the graph has the right degree pattern, you can build a valid trail without trying every possible path.

For an Eulerian circuit, you start at any vertex and keep taking unused edges until you return to where you began. If the graph is only semi-Eulerian, meaning it has exactly two odd-degree vertices, you start at one odd vertex and end at the other. The algorithm still works because the leftover edges can be folded into the partial route as you go.

A common way to think about it is with a stack or with nested cycles. You follow one cycle or trail, record it, then find another unused edge from a vertex on that route and insert the new cycle into the old one. The final answer is not built in one straight shot. It is assembled from smaller closed walks that all share vertices.

A tiny example makes the process clearer. Suppose a connected graph has vertices with degrees that allow an Eulerian circuit. You might trace a loop through several edges, discover a vertex on that loop still has unused edges, trace another loop from that vertex, and then merge the two loops. By the end, every edge appears exactly once and the walk starts and ends at the same vertex.

The main mistake is confusing vertex visitation with edge visitation. Hierholzer's Algorithm does not try to visit every vertex once, and it does not work on graphs that fail the Eulerian degree conditions. If the graph is disconnected, or if more than two vertices have odd degree, there is no Eulerian trail for the algorithm to find.

Why Hierholzer's Algorithm matters in COMBINATORICS

Hierholzer's Algorithm gives you a direct construction method instead of a trial-and-error search. That matters in combinatorics because Eulerian path questions are not just about saying whether a trail exists, they are often about producing the actual trail.

It also connects the degree conditions to a working procedure. You are not just memorizing that a circuit needs every vertex to have even degree, or that a path needs exactly two odd-degree vertices. You see how those conditions let the graph be broken into cycles and stitched back together without leaving unused edges behind.

This comes up in graph theory problems that ask for a route through a network, especially when the edges matter more than the vertices. A classic setup is a street map, mailing route, or bridge problem where you want to cover every connection once. Once you recognize an Eulerian graph, Hierholzer's Algorithm turns the existence result into an actual route.

It also helps separate Eulerian problems from Hamiltonian ones. Eulerian questions are about edges, so this algorithm works cleanly. Hamiltonian questions are about visiting vertices once, and there is no equally simple construction rule like this one. That contrast shows up a lot in combinatorics because the two problem types look similar at first glance but behave very differently.

Keep studying COMBINATORICS Unit 11

How Hierholzer's Algorithm connects across the course

Eulerian Circuit

Hierholzer's Algorithm is one of the main ways to build an Eulerian circuit once you know the graph has one. The circuit is the final closed walk that uses every edge exactly once, and the algorithm shows you how to assemble it from smaller cycles instead of guessing the full route.

Eulerian Path

If a graph has exactly two odd-degree vertices, Hierholzer's Algorithm can produce an Eulerian path instead of a circuit. The only difference is where you start and finish. You begin at one odd vertex and end at the other, while still using every edge exactly once.

Necessary conditions for Eulerian paths

Before you run the algorithm, you check whether the graph can actually have an Eulerian trail. Hierholzer's method depends on the degree conditions and connectedness, so this concept tells you when the algorithm is even worth applying.

Graph Traversal

Hierholzer's Algorithm is a special kind of traversal, but it is much stricter than ordinary graph walking. Many traversal methods visit vertices or explore structure broadly, while this one is focused on covering each edge exactly once and then stitching the pieces together.

Is Hierholzer's Algorithm on the COMBINATORICS exam?

A problem set or quiz item usually gives you a graph and asks whether an Eulerian path or circuit exists, then asks you to construct one. The move is to check the odd-degree vertices first, decide whether the graph is Eulerian, semi-Eulerian, or neither, and then trace the trail using unused edges only. If the graph works, Hierholzer's Algorithm gives you the actual sequence of vertices, not just a yes or no answer.

If a question asks for a proof or explanation, mention the degree conditions and the idea of splicing cycles together. If it asks for a route on a network diagram, you can show the walk step by step and mark edges as used so you do not repeat any. The usual mistake is repeating an edge or trying to force a Hamiltonian-style answer when the task is really about edges.

Hierholzer's Algorithm vs Depth-first search

Depth-first search and Hierholzer's Algorithm can both use a stack, so they look similar at first. The difference is the goal: DFS is a general search method that explores vertices, while Hierholzer's Algorithm is specifically designed to find an Eulerian path or circuit by using every edge exactly once.

Key things to remember about Hierholzer's Algorithm

  • Hierholzer's Algorithm constructs an Eulerian path or circuit by following unused edges and splicing the resulting walks together.

  • The graph has to satisfy the Eulerian degree conditions first, so the algorithm is not a fix for a graph that cannot have an Eulerian trail.

  • For an Eulerian circuit, you can start at any vertex, but for an Eulerian path you start at one odd-degree vertex and end at the other.

  • The method is edge-focused, not vertex-focused, which is why it is different from Hamiltonian problems and ordinary graph search.

  • A good exam response usually shows both the degree check and the actual trail, not just the final list of vertices.

Frequently asked questions about Hierholzer's Algorithm

What is Hierholzer's Algorithm in Combinatorics?

Hierholzer's Algorithm is a procedure for finding an Eulerian path or Eulerian circuit in a graph. It works by tracing unused edges until you get stuck, then combining those trails into one complete walk that uses every edge exactly once.

How does Hierholzer's Algorithm work?

You start from a valid vertex, follow unused edges, and keep building a trail until you cannot continue. Then you return to a vertex on your current route that still has unused edges, trace another cycle or trail, and splice it into the original path.

What is the difference between Hierholzer's Algorithm and DFS?

DFS is a general search technique, while Hierholzer's Algorithm is specialized for Eulerian trails. DFS is usually about exploring vertices and graph structure, but Hierholzer's Algorithm is about using every edge exactly once and constructing the final route.

When can you use Hierholzer's Algorithm?

You can use it on a connected graph that has an Eulerian circuit or an Eulerian path. That means all vertices have even degree for a circuit, or exactly two vertices have odd degree for a path.