Video 2, chapter 22

The Seven Bridges of Königsberg

Why no walk crosses each of the seven bridges of Königsberg exactly once, shown by counting vertex degrees, and Euler's theorem on when a graph has an Eulerian path or an Eulerian circuit.

  • Video 2, chapter 22
  • Turn a route into a graph

The city of Königsberg had seven bridges joining four pieces of land. Is there a walk that crosses every bridge exactly once, if you may start and finish wherever you like? Routes tried by hand always seem to leave one bridge over. This page turns the map into a graph, shows that its odd vertex degrees rule out every possible route at once, and states exactly when a walk of this kind exists.

Key terms

Seven Bridges of Königsberg

Definition In the eighteenth century the river Pregel divided the city of Königsberg, then in Prussia and now Kaliningrad in Russia, into four land regions. Call the island in the river AA and the two banks BB and CC, and call the land to the east, between two branches of the river, DD. Two bridges joined AA with BB, two joined AA with CC, and one bridge joined DD with each of AA, BB and CC, seven bridges in all. The puzzle asks for a walk that crosses every bridge exactly once. The walk may start and finish in any regions, the same one or two different ones, and it may pass through a region as often as it likes, but it may cross the water only by the bridges, and every crossing goes all the way over. The answer is that no such walk exists. Take a region where the walk neither starts nor finishes. Each of its bridges is crossed exactly once, either to arrive or to leave. Every arrival there is followed by a departure and every departure follows an arrival, each on its own bridge, so its bridges are used in pairs and their number would have to be even. Only the start and the finish can have an odd number of bridges, so at most two regions can. In Königsberg all four do, five for AA and three each for BB, CC and DD. Leonhard Euler gave this argument in the 1730s, and it is usually counted as the beginning of graph theory.

In plain words Each time you pass through a piece of land you use one bridge to arrive and another to leave. Land with an odd number of bridges is left with one bridge that has no partner, so the walk must start or end there. Königsberg has four such pieces of land, and a walk has only two ends.

Example Start on bank BB, cross to the island AA, and return to BB on the other bridge between them. Then cross to DD, go from DD to AA, from AA to CC, and from CC to DD. That walk uses six different bridges. The seventh, the second bridge between AA and CC, is still unused, but the walker stands in DD, and all three bridges at DD have been crossed. Every other attempt also runs out of bridges, and a computer search through every possible order confirms that no walk crosses more than six of the bridges once each. The count of bridge ends explains why. Every bridge has two ends, so the numbers of bridges at the four regions add up to twice the number of bridges,

5+3+3+3=14=2⋅7,5 + 3 + 3 + 3 = 14 = 2 \cdot 7,

and all four of these numbers are odd.

Graph theory

Definition A graph consists of points called vertices and of edges, where each edge joins two different vertices. On this page two vertices may be joined by more than one edge, just as two bridges can join the same two regions, and such edges count separately. Some books call this a multigraph and keep the word graph for the case of at most one edge per pair. A walk in a graph is a list v0,e1,v1,e2,…,ek,vkv_0, e_1, v_1, e_2, \ldots, e_k, v_k of vertices and edges in which each edge eie_i joins vi−1v_{i-1} and viv_i, for i=1,…,ki = 1, \ldots, k, so it moves from vertex to vertex along edges. A graph is connected when any two of its vertices are joined by some walk. Graph theory is the branch of mathematics that studies graphs. Only which vertices each edge joins matters, not where the vertices are drawn or how long or how curved the edges are.

In plain words A graph keeps only what is connected to what. For the bridges, each region becomes a dot and each bridge becomes a line between two dots. Distances, shapes and the river itself are dropped, because the puzzle does not depend on them.

Example The Königsberg graph has the four vertices AA, BB, CC, DD and seven edges. Name the two edges between AA and BB as AB1AB_1 and AB2AB_2, the two between AA and CC as AC1AC_1 and AC2AC_2, and the other three as ADAD, BDBD and CDCD. The walk B,AB1,A,AB2,BB, AB_1, A, AB_2, B goes to the island and back on two different bridges, which is why parallel edges must be kept apart. The graph is connected, and a walk that crosses each bridge once is exactly a walk that uses each edge once. Moving DD to another place on the page, or bending the edges, gives the same graph, since the same pairs of vertices are still joined by the same numbers of edges.

Vertex degree

Definition The degree of a vertex is the number of edges that meet it. Each edge joining it to another vertex counts once, so two edges to the same neighbor count twice. A vertex of degree 00 is called isolated, and a vertex is called odd or even according to its degree. Each edge has two ends, so adding the degrees of all the vertices counts every edge exactly twice. For a graph with mm edges whose vertices have degrees d1,d2,…,dnd_1, d_2, \ldots, d_n,

d1+d2+⋯+dn=2m.d_1 + d_2 + \cdots + d_n = 2m.

This is called the handshake lemma. The even degrees add up to an even number, so the odd degrees must also add up to an even number, which happens only when there is an even number of them. Every graph therefore has an even number of odd vertices.

In plain words The degree counts the lines at a dot. Every line has two ends, so the degrees always add up to an even number, and the number of dots with odd degree is always even.

Example In the Königsberg graph the island AA has degree 55, and each of BB, CC and DD has degree 33. The degrees add up to 1414, twice the 77 edges, and there are four odd vertices, an even number as the lemma requires. Remove the edge AB2AB_2 and the degrees become 44, 22, 33 and 33, which add up to 1212, twice the 66 remaining edges, with two odd vertices left. No graph has exactly one odd vertex, or exactly three, which is why Euler’s theorem below speaks of zero or two odd vertices.

Eulerian path

Definition A trail is a walk that never uses the same edge twice, though it may pass through the same vertex several times. An Eulerian path, also called an Euler trail, is a trail that uses every edge of the graph exactly once. Some books reserve the name for a trail whose two ends are different. Euler’s theorem says when one exists. Let a graph have at least one edge, and suppose that any two of its vertices of positive degree are joined by a walk, so that the graph is connected once its isolated vertices are ignored. Then the graph has an Eulerian path exactly when it has 00 or 22 odd vertices. With 22 odd vertices, every Eulerian path starts at one of them and ends at the other. With none, every Eulerian path ends at the vertex where it started. The degree condition is needed because each pass of a trail through a vertex uses one edge to arrive and another to leave, so at every vertex other than the two ends of the trail, the trail’s edges come in pairs. If the trail uses every edge, each vertex other than its ends therefore has even degree, its two ends have odd degree when they are different vertices, and every degree is even when the trail ends where it began. Connectivity is needed because a walk can never get from one part of a graph to another part that no edge joins it to.

In plain words A drawing in one connected piece can be traced in a single stroke, without lifting the pen and without going over any line twice, exactly when it has no odd dots or exactly two. With two, the stroke must begin at one odd dot and end at the other.

Example Remove the bridge AB2AB_2 from Königsberg. The degrees become 44 for AA, 22 for BB and 33 for each of CC and DD, and the graph is still connected, so an Eulerian path exists and must run between CC and DD. One is

C→A→C→D→A→B→D,\begin{aligned} &C \to A \to C \to D \\[0.4em] &\quad \to A \to B \to D, \end{aligned}

which goes from CC to AA on AC1AC_1, back to CC on AC2AC_2, and then along CDCD, ADAD, AB1AB_1 and BDBD. It passes through AA, CC and DD twice each, which is allowed, and uses each of the six bridges exactly once.

Eulerian circuit

Definition An Eulerian circuit is an Eulerian path that ends at the vertex where it started. Under the same conditions as in Euler’s theorem, at least one edge and every two vertices of positive degree joined by a walk, a graph has an Eulerian circuit exactly when every vertex has even degree, and then a circuit can start at any vertex of positive degree. Such a circuit can be built step by step, a method known as Hierholzer’s algorithm. Start at any vertex of positive degree and keep following unused edges. Whenever the walk enters a vertex other than the start, it has used an odd number of that vertex’s edges, so an unused one remains to leave by, and the walk can only get stuck back at the start, closing a loop. The loop used its edges in pairs at every vertex, so the unused edges still meet every vertex an even number of times. If some edges are still unused, connectivity guarantees that one of them meets a vertex of the loop. Walk a second loop of unused edges from there, which again can only close where it began, and insert it into the first loop at that vertex. Repeat until every edge is used. For a graph with exactly two odd vertices, add a temporary edge between them, which makes every degree even, build an Eulerian circuit, and delete the temporary edge from it. What is left is an Eulerian path from one odd vertex to the other.

In plain words A walk that crosses every bridge once and comes home exists exactly when every region has an even number of bridges and every region with a bridge can be reached from every other one.

Example Remove AB2AB_2 and CDCD from the seven bridges. The degrees become 44 for AA and 22 for each of BB, CC and DD, all even, and the graph is still connected. Start at BB and follow AB1AB_1 to AA, ADAD to DD and BDBD back to BB. Both bridges at BB are now used, so this first loop is closed. The bridges AC1AC_1 and AC2AC_2 are still unused, and they meet the loop at AA, so walk the second loop A,C,AA, C, A and insert it where the first loop passes through AA. The result

B→A→C→A→D→B\begin{aligned} &B \to A \to C \\[0.4em] &\quad \to A \to D \to B \end{aligned}

is an Eulerian circuit through all five bridges.

Check yourself

  1. Suppose an eighth bridge is built between the two banks BB and CC. Is there now a walk that crosses each of the eight bridges exactly once? If so, where must it start and finish, and what is one such walk?
Show the answer

The new bridge adds one to the degrees of BB and CC, so the degrees are 55 for AA, 44 for BB, 44 for CC and 33 for DD. The graph is connected and has exactly two odd vertices, AA and DD, so by Euler’s theorem such a walk exists, and it must start at one of AA and DD and finish at the other. One walk starts at AA, goes to BB and back on the two bridges between them, goes to CC and back on the two bridges between those, crosses to DD, then goes from DD to BB, takes the new bridge from BB to CC, and finishes by crossing from CC to DD. In order the regions are A,B,A,C,A,D,B,C,DA, B, A, C, A, D, B, C, D, and the eight bridges crossed are AB1AB_1, AB2AB_2, AC1AC_1, AC2AC_2, ADAD, BDBD, BCBC and CDCD, each once.

  1. A town has six land regions PP, QQ, RR, SS, TT and UU and six bridges, joining PP with QQ, QQ with RR, RR with PP, SS with TT, TT with UU, and UU with SS. Every region has an even number of bridges. Is there a walk that crosses every bridge exactly once?
Show the answer

No. Every region has degree 22, so the degree condition holds, but the connectivity condition fails. No bridge joins any of PP, QQ, RR to any of SS, TT, UU, so a walk that starts in one group can never reach the bridges of the other. Each group on its own has a circuit, for example P,Q,R,PP, Q, R, P, but no single walk covers both. Even degrees are not enough by themselves. Euler’s theorem also needs every two regions that have bridges to be joined by a walk.

  1. What is the smallest number of new bridges that must be added to the original seven, each joining two different regions, so that some walk crosses every bridge exactly once and returns to the region where it started? Give one way to place them and such a walk.
Show the answer

A new bridge adds one to the degree of each of its two ends, so it turns each of those two regions from odd to even or from even to odd and leaves the other regions alone. All four regions start out odd, so a single new bridge makes its two ends even and leaves the other two regions odd. Every degree must be even for a circuit, so one new bridge is not enough.

Two new bridges are enough. Add one between BB and CC and one between AA and DD. The degrees become 66 for AA and 44 for each of BB, CC and DD, all even, and the graph is connected, so an Eulerian circuit exists. One starts at AA and visits the regions in the order

A,B,A,C,A,D,B,C,D,A.\begin{aligned} &A, B, A, C, A, \\[0.4em] &D, B, C, D, A. \end{aligned}

It crosses both old bridges between AA and BB, both old bridges between AA and CC, the old bridge from AA to DD, then BDBD, the new bridge BCBC, CDCD, and finally the new bridge from DD back to AA. That is nine bridges, each crossed once. Pairing the odd regions differently, with new bridges ABAB and CDCD or ACAC and BDBD, works too.

How this lesson connects