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 and the two banks and , and call the land to the east, between two branches of the river, . Two bridges joined with , two joined with , and one bridge joined with each of , and , 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 and three each for , and . 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 , cross to the island , and return to on the other bridge between them. Then cross to , go from to , from to , and from to . That walk uses six different bridges. The seventh, the second bridge between and , is still unused, but the walker stands in , and all three bridges at 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,
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 of vertices and edges in which each edge joins and , for , 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 , , , and seven edges. Name the two edges between and as and , the two between and as and , and the other three as , and . The walk 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 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 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 edges whose vertices have degrees ,
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 has degree , and each of , and has degree . The degrees add up to , twice the edges, and there are four odd vertices, an even number as the lemma requires. Remove the edge and the degrees become , , and , which add up to , twice the 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 or odd vertices. With 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 from Königsberg. The degrees become for , for and for each of and , and the graph is still connected, so an Eulerian path exists and must run between and . One is
which goes from to on , back to on , and then along , , and . It passes through , and 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 and from the seven bridges. The degrees become for and for each of , and , all even, and the graph is still connected. Start at and follow to , to and back to . Both bridges at are now used, so this first loop is closed. The bridges and are still unused, and they meet the loop at , so walk the second loop and insert it where the first loop passes through . The result
is an Eulerian circuit through all five bridges.
Check yourself
- Suppose an eighth bridge is built between the two banks and . 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 and , so the degrees are for , for , for and for . The graph is connected and has exactly two odd vertices, and , so by Euler’s theorem such a walk exists, and it must start at one of and and finish at the other. One walk starts at , goes to and back on the two bridges between them, goes to and back on the two bridges between those, crosses to , then goes from to , takes the new bridge from to , and finishes by crossing from to . In order the regions are , and the eight bridges crossed are , , , , , , and , each once.
- A town has six land regions , , , , and and six bridges, joining with , with , with , with , with , and with . 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 , so the degree condition holds, but the connectivity condition fails. No bridge joins any of , , to any of , , , 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 , 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.
- 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 and and one between and . The degrees become for and for each of , and , all even, and the graph is connected, so an Eulerian circuit exists. One starts at and visits the regions in the order
It crosses both old bridges between and , both old bridges between and , the old bridge from to , then , the new bridge , , and finally the new bridge from back to . That is nine bridges, each crossed once. Pairing the odd regions differently, with new bridges and or and , works too.