Part I · Chapter 1

Seven Bridges

A city, a river, seven bridges and a Sunday puzzle nobody could crack. The way Leonhard Euler cracked it, by throwing away almost everything about the city, is where the science of networks begins.

Picture a river city in the 1700s. The river splits around an island, then splits again, so the town is carved into four pieces of land: a north bank, a south bank, a central island and a stretch of land to the east. Seven bridges stitch the pieces together. The city is Königsberg, in what was then Prussia.

The story goes that its residents liked a teasing puzzle on their walks: can you stroll through the city and cross every bridge exactly once? You may start anywhere and finish anywhere. You just may not swim, and you may not cross any bridge twice. Before reading on, try it.

Interactive 1.1

The Königsberg walk

Click a piece of land to start, then click bridges (lettered a–g) to cross them. Try to use all seven.

cross bridge
Click any piece of land to start your walk.
However you start, you get stuck with bridges left over. Switch to dots and lines and look at the numbers: every piece of land touches an odd number of bridges. Then build the eighth bridge and try again: suddenly a complete walk exists, but only if you start in the right place.

Euler’s leap: throw away the map

In 1736 the Swiss mathematician Leonhard Euler settled the question for good: no such walk exists. What makes his solution famous is not the answer but the way he got it. He noticed that almost nothing about the city matters. Not the shape of the island, not the length of the bridges, not the width of the river, not where the streets run. The only thing that matters is which pieces of land are joined by which bridges.

So shrink each piece of land to a dot, and draw each bridge as a line between two dots. That is the toggle in the figure above. Four dots, seven lines. In that stripped-down picture the puzzle becomes a question you can answer by counting.

Here is the counting. Imagine you are halfway through a walk and you pass through some piece of land. You arrive on one bridge and leave on another. Every visit in the middle of a walk uses up bridges in pairs. So a piece of land that is neither your start nor your finish must have an even number of bridges, or you will eventually arrive with no unused bridge left to leave by.

Only the start and the finish can break that rule, because the start has one extra “leaving” and the finish one extra “arriving”. So at most two dots may have an odd count. In Königsberg the island has 5 bridges and the other three pieces of land have 3 each: four odd dots. Too many. No walk can exist, however clever you are, and nobody needs to try every route to know it.

Key idea

In a connected network, a walk that uses every line exactly once exists precisely when zero or two dots have an odd number of lines; with zero you can end where you began, with two you must start at one odd dot and finish at the other.

The number of lines touching a dot is so useful that it has a name: the dot’s degree. You will meet it again in every chapter. The figure below lets you test Euler’s rule on networks of your own. It starts with a puzzle many children know: draw this little house with an envelope-cross in it without lifting your pen and without going over any line twice.

Interactive 1.2

Euler walk tester

Click two dots (or drag from one to another) to link them. Click a line to cut it. Click empty space to add a dot.

even degreeodd degreethe traced walk
Start from
The verdict appears before any tracing: Euler’s rule predicts whether a walk exists just from the amber count. The house has exactly two odd corners, so every successful drawing starts at one bottom corner and ends at the other. Cut the floor line between those two corners and both become even: with zero odd dots you can start anywhere and return home.
A closer look at the history

Euler’s paper did not contain the dots-and-lines drawing you just used; he labelled the land masses with letters and reasoned about the bridges between them. The dots-and-lines picture came later, but the idea is all his, and his paper is commonly cited as the start of graph theory. Euler showed why the odd count must be zero or two. That this is also enough, so that a walk always exists in a connected network with zero or two odd dots, was proved later; a complete proof was published in 1873 by Carl Hierholzer. Königsberg itself is now the Russian city of Kaliningrad.

What a graph is, and what it is not

Mathematicians call the stripped-down picture a graph: a set of dots, called nodes (or vertices), and a set of lines, called links (or edges), each joining two nodes. Scientists who study real-world graphs usually say network instead. This book uses both words for the same thing.

Careful: in school, “graph” often means a chart, a line plotted against axes. That is a different thing that happens to share the name. A network graph has no axes. Its dots can sit anywhere on the page, and moving them changes nothing that matters. That is worth feeling with your hands.

Interactive 1.3

Same graph, new drawing

Drag the dots. Can you get the number of crossings down to zero?

The crossings count changes as you drag, but the list of who is linked to whom never does. Crossings belong to the drawing; the graph is only the list. This one is the skeleton of a cube, and it can be drawn with no crossings at all.

Three kinds of link

Real networks come in a few flavours, and it pays to notice which one you are looking at:

Königsberg even has a quirk: two pairs of land masses are joined by two bridges each. A graph that allows several links between the same two nodes is sometimes called a multigraph. Most networks in this book have at most one link between any pair.

Once you start looking, the same picture is everywhere: people and friendships, airports and flights, routers and cables, web pages and hyperlinks, species and who-eats-whom, neurons and synapses. Each time, the same move as Euler’s: keep who connects to whom, forget the rest, and see what the shape alone can tell you.

Key idea

A graph keeps only who is connected to whom; positions, distances on the page and crossings are properties of a drawing, not of the network.

Intuition check

A connected network has five nodes with degrees 3, 3, 2, 2 and 4. Can you trace a walk that uses every link exactly once?

What you now see

  • A graph (or network) is nodes plus links: who is connected to whom, and nothing else.
  • A node’s degree is its number of links, and degrees alone can settle questions that look like they need endless trial and error.
  • A walk using every link once exists in a connected network exactly when 0 or 2 nodes have odd degree. Königsberg had four.
  • Links can be two-way, one-way or weighted, and the same dots-and-lines picture describes cities, friendships, the web and the brain.