Euler paths and circuits
Can a walk cross every bridge of a city exactly once, and how could anyone tell without trying every route?
Where you are 10 in Introductory graph theory
Why this exists
The old city of Königsberg, today Kaliningrad, was built where its river forks around an island, so four pieces of land faced each other across the water, joined by seven bridges. The puzzle, as it is usually told, asked for a walk crossing each bridge exactly once. Trying routes is slow, and failing to find one proves nothing. Euler settled the question in 1736 with an argument that forgets the shape of the map and keeps only which land each bridge touches. The same question comes back whenever every link of a network must be covered once: a mail carrier’s streets, a snowplow’s route, a drawing made without lifting the pen. One count, the degree of each vertex, answers all of them.
Definition
This lesson takes two days. Day 1 is Euler circuits and trails and the theorem that decides them (Examples 1 to 4). Day 2 is building a circuit, adding edges, and route problems (Examples 5 to 7).
The words are those of Walks, paths, cycles and connected graphs: a walk (v_0, v_1, \ldots, v_k) is closed when k \ge 1 and v_k = v_0, a trail is a walk using no edge twice, and a graph is connected when every two vertices are joined by a walk. Degree is as in Degree, the handshake lemma and complete graphs.
The bridge map has two bridges between the same pair of land areas, so this lesson allows repeated edges. A multigraph here is a graph in which two vertices may be joined by more than one edge (but no edge joins a vertex to itself). Repeated edges are told apart by names, and a walk lists them, (v_0, e_1, v_1, \ldots, e_k, v_k) with e_i joining v_{i-1} and v_i. A list of vertices alone is enough when no pair is passed more often than it has edges: each pass takes a different one. The degree \deg(v) counts edge ends at v, each repeated edge separately, and the handshake lemma \sum_v \deg(v) = 2\lvert E \rvert holds with the same proof. A vertex is odd or even as its degree is. Every simple graph is a multigraph.
- An Euler trail of G is a trail that uses every edge of G exactly once.
- An Euler circuit is a closed Euler trail. An Euler trail that is not closed is open.
- A closed trail (v_0, v_1, \ldots, v_k = v_0) may be started at any of its vertices: (v_i, \ldots, v_k, v_1, \ldots, v_i) uses the same edges.
Intuition
Figure 1 keeps what matters: a vertex for each piece of land, an edge for each bridge. Follow a walker. Each time she reaches a piece of land where her walk neither starts nor ends, she leaves again, so the bridges there are used in pairs, one in and one out. A piece of land with an odd number of bridges must be the start or the end. A walk has one start and one end, and here all four pieces of land are odd.
The surprise is the other direction: once every vertex is even and the graph is connected, a route always exists.
Results
1. Euler circuits (Euler). A connected multigraph with at least one edge has an Euler circuit exactly when every vertex has even degree.
2. Euler trails. A connected multigraph has an open Euler trail exactly when it has exactly two odd vertices, and every open Euler trail starts at one of them and ends at the other.
So a connected multigraph with an edge has an Euler circuit if it has no odd vertices, an open Euler trail if it has two, and neither if it has four or more.
3. Pairing up the odd vertices. Let a connected multigraph G have 2m odd vertices, m \ge 1 (the count is even by Result 2 of Degree, the handshake lemma and complete graphs). Adding m new edges that join the odd vertices in pairs gives a multigraph with an Euler circuit, and fewer than m added edges never do. The edges of G split into m trails, and not into fewer.
4. One-way edges. In a directed multigraph each edge points from one end to the other; \deg^+(v) counts edges leaving v and \deg^-(v) edges entering it. If the graph is connected when directions are ignored, it has a directed Euler circuit exactly when \deg^+(v) = \deg^-(v) for every v. This is stated without proof; the proof of Result 1 carries over with “leaves” and “enters” in place of the two edge ends.
Why it is true
Result 1, only if. Proof. Let (v_0, e_1, v_1, \ldots, e_k, v_k) with v_k = v_0 be an Euler circuit and fix a vertex v. At each position v_i, 1 \le i \le k, two steps meet: e_i arrives and e_{i+1} leaves, where e_{k+1} means e_1. Each meeting at v uses two edge ends at v. Every edge is used once, so each edge end at v belongs to exactly one meeting. Hence \deg(v) is twice the number of meetings at v, an even number. \square
A lemma. In a multigraph where every degree is even, every vertex v of positive degree starts a closed trail. Proof. Walk from v along unused edges for as long as possible. On arriving at a vertex w \ne v, the walk has used an odd number of edge ends at w: two for each earlier pass and one for the arrival. As \deg(w) is even, an unused edge remains and the walk goes on. The edges are finite, so the walk stops, and only at v. It used at least one edge, so it is a closed trail. \square
Result 1, if. Proof. By Strong induction and well-ordering on the number of edges q \ge 1. Let G be connected with q edges and even degrees, and assume the result for connected multigraphs with fewer edges. The lemma gives a closed trail T. Delete the edges of T, keeping every vertex, to get H. By the first half, T uses an even number of edge ends at each vertex, so H has even degrees. If H has no edges, T is an Euler circuit. Otherwise let H_1, \ldots, H_r be the components of H with an edge. Each is connected with even degrees and fewer than q edges, so it has an Euler circuit C_j.
Each H_j meets T. Take x in H_j, a walk (x = w_0, \ldots, w_s) in G ending on T, and its first vertex w_t on T. For i \le t the edge from w_{i-1} to w_i has an end off T, so it is not an edge of T; it is in H, and w_t lies in H_j. Now go round T, and the first time it reaches a vertex of H_j, go round C_j from there (rotated to start there) before going on. Doing this for each j gives a closed walk that uses every edge of T and of each C_j once: every edge of G. \square
Result 2. Proof. Let u and v be the only odd vertices. Add a new edge f joining them. Every degree is now even and the multigraph is connected, so it has an Euler circuit, which may be started (u, f, v, \ldots, u). Dropping the first step leaves an Euler trail of G from v to u, open since u \ne v. Conversely, let an open Euler trail run from u to v \ne u. An added edge f from v to u closes it into an Euler circuit, so with f every degree is even by Result 1. Removing f lowers \deg(u) and \deg(v) by one: in G exactly u and v are odd. \square
Result 3. Proof. An added edge changes the degrees of its two ends by one each, so it changes the number of odd vertices by -2, 0 or 2; going from 2m to 0 takes at least m edges. The m pairing edges make every degree even and keep the graph connected, so Result 1 applies.
In any split of the edges into trails, the degree of a vertex is the sum of its degrees in the trails. A closed trail, or an open one passing through, adds an even amount; only the ends of an open trail add an odd amount. So every odd vertex of G ends some trail, and s trails have at most 2s ends: s \ge m. For m trails, take an Euler circuit C of G with the pairing edges. Each odd vertex meets exactly one new edge and each new edge has odd ends, so no two new edges are consecutive in C. Deleting the m new edges cuts C into m pieces with at least one edge each, and they are trails of G. \square
Worked examples
Day 1: the seven bridges
Figure 1 shows the island K, the north bank N, the south bank S and the land E to the east, with two bridges from K to each bank and one bridge from E to each of K, N and S. Is there a walk crossing every bridge exactly once, ending where it began or not?
SolutionA walk crossing each bridge once is an Euler trail of the multigraph. Counting bridges,
All four vertices are odd. An Euler circuit needs no odd vertices (Result 1) and an open Euler trail exactly two (Result 2), so no such walk exists, wherever it starts. Check: the degrees add to 14 = 2 \cdot 7, two ends for each of the seven bridges.
Day 1: sorting four graphs
For each graph in Figure 2, decide whether it has an Euler circuit, an open Euler trail, or neither, and give a route when one exists.
Solution(a) Vertex 4 has degree 4, every other vertex degree 2, and the graph is connected. By Result 1 it has an Euler circuit, such as (1, 2, 3, 4, 5, 6, 7, 4, 1), which uses the eight edges 12, 23, 34, 45, 56, 67, 74, 41 once each.
(b) The center 0 has degree 5 and each of 1 to 5 degree 3. Six odd vertices: neither.
(c) The chord 14 gives 1 and 4 degree 3; the rest have degree 2. Exactly two odd vertices, so an open Euler trail runs from 1 to 4, such as (1, 2, 3, 4, 5, 6, 1, 4), and there is no circuit.
(d) Every degree is 2, but the graph is not connected. A trail stays inside one component, so none uses edges of both triangles: neither.
Day 1: ladders
The ladder L_n, for n \ge 2, has vertices u_1, \ldots, u_n and w_1, \ldots, w_n, rails u_i u_{i+1} and w_i w_{i+1} for 1 \le i \le n - 1, and rungs u_i w_i for 1 \le i \le n. For which n does L_n have an Euler circuit, and for which an open Euler trail?
SolutionL_n is connected: each rail line is a path, and a rung joins the two. It has 3n - 2 edges. The corners u_1, w_1, u_n, w_n have one rail and one rung, degree 2; every other vertex has two rails and a rung, degree 3. So L_n has 2(n - 2) odd vertices.
- n = 2: no odd vertices. L_2 is a 4-cycle, its own Euler circuit.
- n = 3: two odd vertices, u_2 and w_2, so an open Euler trail joins them: (u_2, u_1, w_1, w_2, w_3, u_3, u_2, w_2) uses all 7 edges.
- n \ge 4: at least four odd vertices, so neither.
Day 1: no edge is a weak link
Let G be a connected multigraph in which every vertex has even degree. Prove that removing any one edge e, keeping every vertex, leaves a connected multigraph.
SolutionProof. G has the edge e, so by Result 1 it has an Euler circuit. Start it at an end u of e with e as the first step: (u, e, v, \ldots, u). Dropping that step leaves a trail from v to u using every edge except e. As G is connected and has an edge, every vertex has an edge, so every vertex lies on the circuit and therefore on this trail. Any two vertices are joined along the trail, which avoids e. \square
Even degrees are needed: removing either edge of the path (1, 2, 3) disconnects it.
Day 2: building a circuit by splicing
The graph of Figure 3 has edges ab, bc, cd, da, be, ef, fb, fg, gh, hf. Find an Euler circuit.
Solutionb and f have degree 4, the other six vertices degree 2, and the graph is connected, so a circuit exists. The proof of Result 1 builds one: grow a closed trail, then splice in closed trails of unused edges. To make each choice definite, move to the alphabetically first neighbor along an unused edge; any choice works.
From a: a, b, c, d, a, and at a nothing unused remains. The lemma says such a walk can only stop at its start. So T_1 = (a, b, c, d, a).
Six edges are unused, and each vertex still has an even number of them, since T_1 used two ends at each of its vertices. Along T_1, the first vertex with an unused edge is b. From b: T_2 = (b, e, f, b). Putting T_2 in place of the b in T_1 gives
still a closed walk, and still a trail because T_2 used only edges T_1 did not.
Unused now: fg, gh, hf. Along the new circuit, a, b and e have nothing unused; f does. From f: (f, g, h, f). Splicing it in at the first f,
Its 10 steps use different edges and the graph has 10 edges: an Euler circuit. Growing and splicing closed trails like this is known as Hierholzer’s method.
Day 2: a drawing in the fewest strokes
Zhenya wants to draw a regular hexagon with its three long diagonals (Figure 4), never going over a line twice. Can she do it without lifting the pen? If not, what is the fewest number of strokes?
SolutionThe corners 0 to 5 and the center z, where the diagonals cross, are vertices, and the 12 segments between them are edges. A stroke is a trail, so a drawing splits the edges into trails.
Each corner has two sides and one diagonal, degree 3; the center has degree 6. Six odd vertices rule out one stroke (Results 1 and 2), and by Result 3 the fewest is \displaystyle \frac{6}{2} = 3. Three strokes that work:
They use 4 + 6 + 2 = 12 different edges.
Day 2: a mail route
Zhenya delivers mail on the streets of Figure 5: a grid of intersections A to I with one diagonal street from B to D, 13 blocks in all. She starts and ends at the post office at A and must walk every block. What is the fewest number of blocks she walks twice, and what route achieves it?
SolutionB, D and E have degree 4; A, C, G, I degree 2; F and H degree 3. Two odd intersections rule out a closed route using each block once (Result 1), so some blocks repeat.
Lower bound. Record the repeats as extra copies of blocks, a multigraph R on the intersections. The route is an Euler circuit of the streets together with R, so every total degree is even, and in R the odd vertices are exactly F and H. In the component of R containing F the odd vertices come in pairs (Degree, the handshake lemma and complete graphs, Result 2), so H is there too. A walk in R from F to H contains a path, so at least d(F, H) = 2 different blocks are repeated.
Upper bound. Repeat FI and IH. Then F, H, I have degree 4, every degree is even, and a circuit exists:
That is 15 blocks, the 13 streets once and FI, IH twice. The fewest repeated blocks is 2.
Boundaries
- Connected. Two disjoint triangles (Example 2(d)) have even degrees and no Euler trail.
- At least one edge. A single vertex has no closed trail, since a closed walk has k \ge 1.
- Loops. This lesson leaves them out. If allowed, a loop adds 2 to the degree of its vertex, and Results 1 to 3 still hold.
- Exactly once. Covering every edge at least once is always possible in a connected graph; the question is then how much to repeat, as in Example 7.
- One-way edges. With directions, even degree is not enough: a \to b, b \to c, a \to c gives every vertex degree 2 and has no directed circuit. Result 4 replaces evenness.
Where this goes next
Swap edges for vertices and the question changes character: Hamiltonian paths and cycles asks for a route through every vertex once, and no test as simple as Result 1 is known. Giving streets lengths turns Example 7 into a cheapest-route problem built on Weighted and directed graphs and Finding a shortest path.
Exercises
Day 1: Euler circuits and trails
- Decide whether each has an Euler circuit, an open Euler trail, or neither, and give a route when one exists. (a) Vertices 1 to 5 and edges 12, 23, 34, 45, 51, 13, 14. (b) The prism: triangles abc and xyz with the edges ax, by, cz. (c) The multigraph on p, q, r in which each pair is joined by two edges.
- A river town has a north bank N, a south bank S and an island I, with three bridges between N and I, two between S and I, and one between N and S. Can a walk cross every bridge exactly once? If so, where must it start and end? Give one.
- A connected graph has degree sequence (6, 4, 4, 3, 3, 2, 2). How many edges does it have, does it have an Euler circuit or an open Euler trail, and where must a route start?
- The fan F_n, for n \ge 2, is the path (1, 2, \ldots, n) with a vertex h joined to each of 1, \ldots, n. For which n does F_n have an Euler circuit, an open Euler trail, or neither? Give a route for each n that has one.
Day 1: reasoning
- Prove that a connected graph with n \ge 2 vertices and an Euler circuit has at least n edges.
- Let G be a graph in which every vertex has even degree. Prove that the edges of G split into cycles, each edge in exactly one.
- Refute with a counterexample: “every connected graph in which each vertex has degree at least 2 has an Euler trail.”
- Let G be a connected graph with exactly two odd vertices u and v. Add a new vertex w and the edges wu and wv. Show that the result has an Euler circuit, and use it to find an Euler trail of G from u to v. What does this give that adding a second edge uv does not?
Day 2: building routes
- A graph has edges 12, 23, 31, 34, 45, 53, 56, 67, 75. Starting from the closed trail (1, 2, 3, 1), splice in closed trails to get an Euler circuit.
- The graph on 0, 1, \ldots, 6 joins i to i \pm 1 and i \pm 2, taken modulo 7. Show that it has an Euler circuit, and find one by splicing (0, 2, 4, 6, 1, 3, 5, 0) into (0, 1, 2, 3, 4, 5, 6, 0).
- A square is divided into a 3-by-3 board of nine small squares, as for tic-tac-toe with the outer border drawn. What is the fewest number of strokes that draws it without going over a line twice?
- Add as few edges as possible to the prism of Exercise 1(b) so that the result is still a simple graph and has an Euler circuit. How many are needed, and which work?
- A town’s streets form a ring of intersections 1, 2, \ldots, 8, with 8 joined back to 1, and an avenue from 1 through 9 and 10 to 5. The snowplow starts and ends at 1 and must clear every block; one pass clears a block. What is the fewest number of blocks it drives twice? Give a route.
- One-way streets join a, b, c, d. (a) They run a \to b, b \to c, c \to d, d \to a, a \to c, c \to a. Is there a closed drive along every street exactly once, with the traffic? Give one if so. (b) The same with d \to a replaced by a \to d.
Day 2: reasoning
- Let G be a connected graph in which every vertex has degree 4. Prove that its edges can be colored red and blue so that every vertex meets two red and two blue edges.
- Prove that if a directed multigraph has a directed Euler circuit, then \deg^+(v) = \deg^-(v) for every vertex v.
- Find the flaw: “Let every vertex of a connected graph be even. Start anywhere and walk along unused edges. By the lemma the walk can only get stuck back at the start, so it uses every edge and is an Euler circuit.”
Answers
- (a) 3 and 4 have degree 3, the others 4 or 2: an open Euler trail from 3 to 4, such as (3, 2, 1, 5, 4, 1, 3, 4). (b) Every vertex has degree 3: six odd vertices, neither. (c) Every vertex has degree 4: an Euler circuit, (p, q, r, p, q, r, p).
- Yes. \deg(N) = 4, \deg(I) = 5, \deg(S) = 3, so the walk starts at I or S and ends at the other (Result 2), for example (I, N, I, N, S, I, S). No closed walk does it.
- 12 edges, as the degrees add to 24. Exactly two odd vertices, so an open Euler trail and no Euler circuit; it starts at one vertex of degree 3 and ends at the other.
- 1 and n have degree 2, 2, \ldots, n - 1 degree 3, and h degree n. n = 2: a triangle, circuit (1, 2, h, 1). n = 3: odd 2 and h, trail (2, 1, h, 3, 2, h). n = 4: odd 2 and 3, trail (2, 1, h, 2, 3, h, 4, 3). n \ge 5: the n - 2 \ge 3 vertices 2, \ldots, n - 1 are odd, so neither.
- Connected with n \ge 2 vertices, so no vertex is isolated. By Result 1 every degree is even, so at least 2, and the handshake lemma gives 2\lvert E \rvert \ge 2n.
- Strong induction and well-ordering on the number of edges. With none, use no cycles. Otherwise a vertex of positive degree starts a closed trail (the lemma), and every closed trail contains a cycle Z (Walks, paths, cycles and connected graphs, Exercise 16). Removing the edges of Z lowers each degree by 0 or 2, so degrees stay even; the rest splits into cycles by hypothesis, and Z joins them. \square
- The complete graph K_4: connected, every degree 3, so four odd vertices and no Euler trail (Results 1 and 2).
- u and v gain one each and become even, w has degree 2, and the result is connected, so Result 1 gives a circuit. It passes w once; start it there and reverse it if needed, to get (w, u, \ldots, v, w). Deleting w and its two edges leaves (u, \ldots, v), an Euler trail of G. The new graph stays simple, while a second edge uv makes a multigraph.
- Unused: 34, 45, 53, 56, 67, 75. Splice (3, 4, 5, 3) at 3: (1, 2, 3, 4, 5, 3, 1). Splice (5, 6, 7, 5) at 5: (1, 2, 3, 4, 5, 6, 7, 5, 3, 1), all 9 edges.
- Every degree is 4, and (0, 1, \ldots, 6, 0) reaches every vertex. The two closed trails use the \pm 1 edges and the \pm 2 edges. Splicing at 0: (0, 1, 2, 3, 4, 5, 6, 0, 2, 4, 6, 1, 3, 5, 0), all 14 edges.
- 4. The board has 16 points and 24 segments. The 4 outer corners have degree 2, the 8 other boundary points degree 3, the 4 inner points degree 4. Eight odd vertices give \displaystyle \frac{8}{2} = 4 strokes by Result 3.
- 3: there are six odd vertices and each added edge evens at most two. The six non-edges form the cycle (a, y, c, x, b, z, a), so exactly two triples work: ay, cx, bz or yc, xb, za. Each gives every vertex degree 4, connected.
- 3. The odd intersections are 1 and 5. As in Example 7, the repeats contain a walk from 1 to 5, so at least d(1, 5) = 3 blocks (the ring takes 4). Repeating the avenue: (1, 2, 3, 4, 5, 10, 9, 1, 8, 7, 6, 5, 10, 9, 1), 14 blocks.
- (a) Yes. a and c have \deg^+ = \deg^- = 2, b and d have 1 and 1, and the streets are connected, so Result 4 applies: (a, b, c, a, c, d, a). (b) No: \deg^+(a) = 3 but \deg^-(a) = 1.
- With n vertices, G has 2n edges, an even number, and an Euler circuit (Result 1). Color its steps red and blue in turn; as 2n is even, the last and first steps also differ. At each meeting at a vertex the two steps are consecutive, so one is red and one blue. A vertex of degree 4 has two meetings: two red and two blue edges. \square
- Each step leaves its start and enters its end. Each arrival at v is followed by a departure from v (the last arrival by the first step), which pairs arrivals with departures. Every edge is used once, so the arrivals number \deg^-(v) and the departures \deg^+(v). \square
- The lemma says where the walk stops, not that it used every edge. It can return to the start with edges left elsewhere, as in Example 5, where the walk from a stopped after 4 of the 10 edges. The missing step is splicing.