Guest User
Using app without sign in

Practice book
Graph Theory Through Problems300 Exercises with Hints, Worked Algorithms and Complete Solutions
By Mohammed Islam Hadjoudj
Learn graph theory by solving problems: 300 exercises, from routine checks to challenging proofs, each with a complete solution.
Also by the authorGraph Algorithms for Coding Interviews100 solved interview problems with visual explanations and Python solutions.View on AmazonSelect an algorithm and generate steps to begin visualization
Every edge once, never burning a bridge too early
Euler trail or circuit, edge by edge, never crossing a bridge of the remaining graph unless forced
Select an algorithm and generate steps to begin visualization
Fleury's algorithm finds an Euler trail: a walk that uses every edge of a graph exactly once, like drawing a figure without lifting the pen. If the walk returns to its start, it is an Euler circuit. Published by M. Fleury in 1883, it is the classic textbook method, simple enough to follow by hand on paper.
A connected graph has an Euler trail exactly when zero or two of its vertices have odd degree. The walk starts at one of the two odd vertices, or anywhere if all degrees are even. At each step it crosses an edge from the current vertex and deletes it, with one rule: never cross a bridge of the remaining graph, an edge whose removal would cut it in two, unless it is the only edge left at that vertex. Crossing a bridge too early would leave the edges on this side unreachable. Since every step needs a bridge test, the algorithm takes O(E²) time; Hierholzer's algorithm finds the same trails in O(E).
Euler trails plan routes that must cover every street or link once, such as mail and snow-plough rounds, guide drawing machines and plotters, assemble DNA fragments with de Bruijn graphs, and test every transition of a network or circuit. Fleury's algorithm is mostly taught for its clear rule, and it pairs naturally with Hierholzer's algorithm, which this site also visualizes.
Fleury's algorithm traces an Euler trail one edge at a time and deletes each edge it crosses. Its single rule is never to cross a bridge of the remaining graph unless there is no other choice.
Fleury(graph):
check: connected, and 0 or 2 vertices of odd degree
u = an odd vertex if there is one, else any vertex
trail = [u]
while u has edges left:
choose an edge (u, v) that is not a bridge
of the remaining graph, unless it is the only one
delete (u, v)
u = v, trail.append(u)
return trailCrossing a bridge splits the remaining edges into two parts, and the trail can never come back to the part it leaves. Refusing to cross a bridge while another edge is available therefore keeps all remaining edges reachable from the current vertex, and the walk can only stop once every edge has been used.
Trace an Euler trail from C on the example this page loads: a triangle and a square joined by a single edge, designed so that the first edge in label order is the one to avoid.
Example graph: Undirected edges C-A (the link), B-C, C-D and B-D (the triangle), and A-E, E-G, G-F and F-A (the square). C and A have degree 3, every other vertex degree 2.
The Euler trail is C-B-D-C-A-E-G-F-A, eight edges from one odd vertex to the other. A naive walk that took the first edge in label order would have crossed C-A immediately, walked around the square and stopped at A with the triangle untouched, which is exactly the failure Fleury's rule prevents.
Time: O(E^2) · Space: O(V + E)
The trail takes E steps. At each step the candidate edge must be tested for being a bridge of the remaining graph, which takes a DFS or a connectivity check in O(V + E). The total is O(E (V + E)), which is O(E^2) for connected graphs. Dynamic connectivity structures can lower this in theory, but nobody does that in practice because Hierholzer's algorithm builds an Euler circuit or trail in O(E) without any bridge tests. Fleury is taught because its rule is easy to state and to check by hand.
Fleury and Hierholzer produce the same kind of answer. The choice depends on whether you want clarity or speed.
| Alternative | Prefer it when | Cost |
|---|---|---|
| Hierholzer's algorithm | Any real implementation. It walks until stuck, then splices in sub-circuits from vertices with unused edges. | O(E) |
| Euler's theorem check | You only need to know whether a trail or circuit exists: connectivity plus counting odd degrees. | O(V + E) |
| Chinese postman | The graph has more than two odd vertices, so some edges must be repeated, and you want the cheapest way to do it. | O(V^3) |
| Hamiltonian path search | Every vertex must be visited once, rather than every edge. That problem is NP-complete. | exponential |
Read the full article: Eulerian Trail, Path and Circuit: Rules, Algorithm, Code
Read the full article: Connected Components, Bridges and Articulation Points
Related algorithms: Eulerian Path (Undirected), Chinese Postman, Bridge Finding, Depth-First Search