ViewWiki

The world, a little closer

Graph theory.

Can you stroll through a town crossing each of its bridges exactly once? In 1736 Euler settled it by counting, and graph theory began.

Explore the scene Interactive article

01 / The experiment

Seven bridges, one walk?

Add or remove bridges and watch the walker try to cross each one once. Then look at the town as a graph and count the lines at each dot.

Still of the Graph theory 3D scene, which explores: Why can no walk cross each of Königsberg's seven bridges exactly once?
Interactive scene

Loading the interactive version…

The explanation below is available while the scene loads.

A model of Königsberg's river and its four pieces of land, with the bridges in a simplified layout. The walks are worked out by the same rule Euler found.The map is schematic, not a survey of the old city, and the extra bridges are imaginary. Only which land each bridge joins matters to the puzzle.

02 / Three towns

Count the odd ones.

Each dot is a piece of land and each line a bridge. The number in a dot is how many bridges it has.

Königsberg01
5333

Seven (1736)

Every piece of land has an odd number of bridges. Any walk gets stuck with a bridge still uncrossed.

Bridges
7
Odd lands
A, B, C, D
Walk
Impossible
Six bridges02
4233

Remove one

Two pieces of land are left odd. A walk crosses every bridge once, but only from one of them to the other.

Bridges
6
Odd lands
C, D
Walk
C to D
Nine bridges03
6444

Add two

Every count is even. The walk crosses each bridge once and comes home to where it started.

Bridges
9
Odd lands
None
Walk
Circuit from A
The big idea

A walk can cross every line of a connected graph exactly once only if no more than two dots have an odd number of lines. With none, it ends where it began; with two, it runs from one to the other.

Σ deg = 2E

A puzzle about a walk

The Prussian city of Königsberg, now Kaliningrad in Russia, was built where the river Pregel splits around an island called the Kneiphof and then flows on as one. In the early eighteenth century seven bridges joined the island, the two river banks and the land between the river’s eastern arms. A puzzle went round: could you take a walk that crosses every bridge exactly once?

Nobody could find one. In 1736 the Swiss mathematician Leonhard Euler showed that nobody ever would, and he did it without trying a single route.

Only the connections matter

Euler noticed that almost everything about the town is irrelevant. The shape of the island, the length of the streets and where on a bank you stand make no difference. All that matters is which pieces of land each bridge joins.

So shrink each piece of land to a dot and draw each bridge as a line between two dots. What is left is a graph: a set of points, called vertices or nodes, joined by lines, called edges. Choose Graph under Turn the town into a graph and the model town turns into exactly this drawing, with island A in the middle, the banks B and C, and the eastern land D.

Counting the bridges at each piece of land

Now think about a walk passing through a piece of land. Every time it arrives over one bridge, it must leave over another. So the bridges at a piece of land the walk merely passes through are used up in pairs, and their number must be even. The number of edges at a vertex is called its degree.

The only places allowed an odd degree are where the walk starts and where it ends. That means:

  • If every degree is even, a walk can cross every edge once and finish where it began, a circuit.
  • If exactly two degrees are odd, a walk can cross every edge once, but it must start at one odd vertex and end at the other.
  • If more than two are odd, no such walk exists.

In Königsberg the island has five bridges and each of the other three pieces of land has three. All four degrees are odd, so the walk is impossible. In the scene the walker crosses as many bridges as it can, and the bridge it cannot reach stays glowing red.

Try it: set Bridges to 7, as in 1736, and choose Graph under Turn the town into a graph: every dot glows orange. Then set Bridges to 6 and to 9 and watch the orange dots disappear.

Back to the experiment

There can never be exactly one odd vertex. Each edge has two ends, so the degrees always add up to twice the number of edges, an even number, and the odd ones must come in pairs.

Finding the walk

Euler’s counting tells you when a walk exists. Actually finding one takes a recipe, and a neat one was published in 1873 by the German mathematician Carl Hierholzer, who proved that Euler’s condition is enough as well as necessary. Start at an odd vertex if there is one, and keep walking along any unused edge until you get stuck. If edges are left over, go back to a vertex on your route that still has unused edges, walk a loop from there until you return, and splice the loop into your route. Repeat until every edge is used. The scene’s walker follows a route found exactly this way.

Walks that use every edge once are now called Euler paths and Euler circuits. The same reasoning plans routes for street sweepers, snowploughs and delivery rounds that must cover every street, and graphs in general describe anything made of connections: road maps, electrical circuits, molecules, friendships and the links between web pages.

What this model leaves out

The town is a simplified model. The river, the land and the bridge positions are drawn to show which land each bridge joins, not to match old maps, and the eighth and ninth bridges are invented to show what changes. A real stroller could also cross by boat; the puzzle forbids that, and so does the model. Finally, Euler worked with letters for the pieces of land and counts of bridges rather than a drawing of dots and lines; the graph picture is the modern way of showing his idea.

Reuse with credit to ViewWiki and a link to this page.

04 / Learn this in a course

Practise it, step by step.

These 2 lessons teach the topic with checked questions, in course order.

  1. Nodes and edges Computer science · Graphs and networks
  2. Euler paths Computer science · Graphs and networks