Discrete Mathematics and Combinatorics
Euler Paths and Circuits and How to Find Them
Learn the degree test that decides whether a network can be traced in one stroke, then build the route step by step.
Key takeaways
- A connected graph has an Euler circuit exactly when every vertex has even degree.
- It has an Euler path that is not a circuit exactly when two vertices are odd, and the path must start at one and end at the other.
- Hierholzer's method builds a circuit by finding small loops and splicing them together.
- With 2k odd vertices, k at least 1, you need k separate strokes to cover every edge once.
- The test is quick even for huge graphs, unlike the similar-sounding problem of visiting every vertex once.
An Euler path is a route through a graph that uses every edge exactly once. An Euler circuit is such a route that also ends where it began. For a connected graph, you can decide whether either exists just by counting the edges at each vertex: no odd vertices means a circuit, exactly two odd vertices means a path but no circuit, and more than two means neither.
A graph here is a set of points, called vertices, joined by edges. The number of edge ends at a vertex is its degree, and a vertex is odd or even according to that number.
The bridges that started it
The city of Königsberg had seven bridges linking two riverbanks and two islands. The question was whether a stroll could cross each bridge exactly once. In work dating from 1736, Leonhard Euler showed that it could not.
Treat each land mass as a vertex and each bridge as an edge. One island touches five bridges, and each of the other three land masses touches three. All four vertices are odd, so no walk of the required kind exists. The original argument is retold in Euler's Königsberg argument.
Why degrees settle the question
Picture walking along the route. Each time you pass through a vertex, you arrive by one edge and leave by another, using up two. A vertex that is neither the start nor the end therefore must have even degree.
In a circuit, the start also works out: the first departure pairs with the final arrival. So every vertex is even. In a path with different start and end, those two vertices each have one unpaired edge, so they are odd and all others are even.
This shows the conditions are necessary. The harder direction is that they are sufficient, once the graph is connected. Euler stated this, and a complete published proof is usually credited to Carl Hierholzer, in a paper that appeared in 1873.
| Number of odd vertices (connected graph) | Euler circuit? | Euler path? |
|---|---|---|
| 0 | Yes | Yes (any circuit counts) |
| 2 | No | Yes, from one odd vertex to the other |
| 4 or more | No | No |
An odd count of odd vertices cannot happen, by the handshaking lemma. Also, "connected" only needs to apply to the vertices that have edges. A stray isolated point does no harm.
Why the condition is enough
Suppose every degree is even. Start anywhere and walk along unused edges. Whenever you enter a vertex other than the start, you have used an odd number of its edges, so at least one remains. You can only get stuck back at the start, which means your walk is a closed loop.
If the loop misses some edges, remove the ones you used. Every vertex still has even degree among the leftovers. Because the graph is connected, some vertex on your loop touches an unused edge. Walk a new loop from there and insert it into the old one. Each round uses more edges, so eventually none remain.
That proof is also an algorithm.
A worked example
Take six vertices, A to F, with nine edges: AB, BC, CA, BD, DE, EB, CE, EF and FC. The degrees are A 2, B 4, C 4, D 2, E 4 and F 2. All are even, and the graph is connected.
1. Loop from A: A B C A (3 edges)
2. B still has unused edges: B D E B (3 edges)
3. Splice at B: A B D E B C A (6 edges)
4. C still has unused edges: C E F C (3 edges)
5. Splice at C: A B D E B C E F C A (9 edges) Read the final route and tick off each edge: AB, BD, DE, EB, BC, CE, EF, FC, CA. All nine appear once, and the route returns to A.
Now delete edge CA. Vertices A and C become odd, with degrees 1 and 3. Dropping the last step of the circuit gives the Euler path A B D E B C E F C, which runs from one odd vertex to the other.
Finding an Euler path
When exactly two vertices are odd, use a small trick. Add a temporary edge between them, even if one already exists. Now every vertex is even. Find a circuit, then cut it at the temporary edge. What remains is a path between the two original odd vertices.
A familiar pencil puzzle shows the test in action. Draw a square with both diagonals and a triangular roof on top. The two top corners have degree 4, the roof tip has degree 2 and the two bottom corners have degree 3. You can draw the house without lifting the pencil, but only if you start at one bottom corner and finish at the other.
Fleury's method and its warning
An older procedure, Fleury's algorithm, traces the route in one pass. Start at an odd vertex if there is one. At each step, choose any unused edge, with one rule: do not take a bridge of the remaining graph unless you have no other choice. A bridge is an edge whose removal would split what is left into separate pieces.
The rule keeps you from stranding edges behind you. It is easy to follow by eye on a small drawing. On large graphs it is slower than Hierholzer's method, because you must repeatedly check which edges are bridges.
More than two odd vertices
If a connected graph has 2k odd vertices with k ≥ 1, you can cover all edges with exactly k trails, and no fewer. A trail is a route that never repeats an edge. Each trail can remove at most two odd vertices from the problem, which gives the lower bound. Adding k temporary edges to pair them up, finding a circuit and cutting it shows that k trails are enough.
Königsberg, with four odd vertices, needs two separate walks.
A related practical task is the route inspection problem, often called the Chinese postman problem after the mathematician Guan Meigu (Mei-Ko Kwan), who studied it around 1960. A postal worker, street sweeper or snow plow must cover every street and return to base. If some junctions are odd, certain streets must be traveled twice. The task is to choose pairings of the odd junctions, connected by shortest routes, that make the repeated distance as small as possible. Shortest path methods supply those distances.
For example, if only two junctions are odd, the answer is simple: walk every street once, plus one extra copy of a shortest route between those two junctions.
One-way streets and other uses
In a directed graph, each edge can be followed only in its direction. A circuit using every edge exists exactly when each vertex has equal numbers of incoming and outgoing edges and all the vertices with edges can reach one another.
This version builds de Bruijn sequences. The circular string 00010111 contains each of the eight three-bit blocks exactly once as you read around it: 000, 001, 010, 101, 011, 111, 110 and 100. You find it by letting two-bit blocks be vertices and three-bit blocks be edges, then following an Euler circuit. Related ideas have been used to reassemble DNA sequences from short overlapping fragments.
Test yourself on complete graphs
The complete graph on n vertices joins every pair, so each vertex has degree n − 1. That tells you at once which ones can be traced.
- If n is odd, every degree is even, so there is an Euler circuit. With n = 5 you can draw a pentagon and the star inside it in one unbroken stroke, 10 edges in all.
- If n = 2, there is a single edge, which is itself an Euler path.
- If n is even and at least 4, all n vertices are odd. You need n/2 separate strokes. For n = 4 that means two.
The same reasoning applies to a set of dominoes. Think of the numbers 0 to 6 as vertices and each domino with two different numbers as an edge joining them. Every number meets six such edges, so a circuit exists. All 21 of those dominoes can be laid in a closed chain with matching ends, and the 7 doubles can be slipped in wherever their number appears.
Remove the numbers above 5 and the picture changes: each vertex then has degree 5, there are six odd vertices and no single chain can use every piece.
Not the same as visiting every vertex
An Euler route covers every edge once. A route that visits every vertex once is called Hamiltonian, and it is a very different matter. There is a fast, complete test for the former. No efficient general test is known for the latter, as Hamiltonian cycles explains.
Common mistakes to avoid:
- Counting vertices instead of degrees. The number of vertices has no effect on the test.
- Forgetting connectivity. Two separate triangles have all even degrees but no circuit covering both.
- Starting an Euler path at an even vertex when two odd vertices exist. You will get stuck with edges left over.
- Reading crossing lines in a drawing as vertices when none was intended, which changes the degrees.
If you are new to the vocabulary, the introduction to graph theory builds it from everyday networks.