← All Labs
IDEA #34 · DISCRETE MATHS — GRAPHS

Graph theory: colouring & the seven bridges

In 1736 Euler was handed a walking puzzle about the seven bridges of Königsberg — and answered it by throwing the map away. Keep only what touches what, and a river town becomes four dots and seven lines. That single act of forgetting geography is the birth of graph theory. Three tabs below let you walk the bridges, colour a graph down to its chromatic number, and four-colour a map that seems to demand five. Everything is computed live — the counters read the graph, they are not captions.

TAB 1 · EULER, 1736
Seven Bridges of Königsberg
Try to cross every bridge exactly once. Odd-degree vertices explain why you can't — until you add a bridge.
TAB 2 · CHROMATIC NUMBER
Graph colouring
Colour nodes so no edge joins a match. Shrink the palette and race the chromatic number χ.
TAB 3 · THE 1976 THEOREM
Four-colour a map
A map that looks like it needs five. Four always suffice — however you gerrymander it.
01

Drive it — walk the bridges

The four land masses of Königsberg (two banks N/S, the island A, the east quarter D) joined by seven bridges. Click a vertex to stand there, then click an incident bridge to cross it. Cross all seven, each once, without lifting your feet.
DRIVE IT
bridges crossed0 / 7 · odd-degree vertices4 ✗ no Euler path
Each time you cross a bridge you use up one connection at each end. A vertex you pass through needs bridges in pairs (one in, one out); only your start and finish may have an odd count. Königsberg has four odd-degree vertices — two too many — so no such walk exists. Flip the toggle to build the eighth bridge and watch the parity fix itself.
DEG A
5
odd
DEG N
3
odd
DEG S
3
odd
DEG D
3
odd
STANDING AT
click a vertex
EULER RULE
0 or 2 odd
02

Walkthrough

Feel why the walk is impossible.
WALKTHROUGH
1
Click vertex A (the island) to stand there, then start crossing bridges. Notice you can get a long way — but you always end up stranded with an unused bridge on the far side.
2
Read the four DEG cards: A has 5 bridges, N/S/D have 3 each. Every one is odd — the odd-degree count is 4.
3
Here's the rule Euler proved: a walk crossing every edge once (an Euler path) exists only if 0 or 2 vertices have odd degree. Four odd vertices → the EULER RULE card shows .
4
Press + build bridge N–S. Now N and S have degree 4 (even); only A and D stay odd. Exactly 2 odd vertices → the card flips to . Reset and try again starting at A and finishing at D — it works.
THE INSIGHT
"Euler didn't measure a single distance. He replaced the town with dots and lines and counted how many bridges meet at each dot — and the answer fell out of parity alone. The birth of graph theory was an act of deliberate forgetting."
03

Explanation

Degree, parity, and the handshake.
EXPLANATION

Model each land mass as a vertex and each bridge as an edge. The degree of a vertex is the number of edges meeting it. A walk that uses every edge exactly once is an Euler path (an Euler circuit if it also returns home).

Every time the walk visits an interior vertex it arrives on one edge and leaves on another — edges get consumed two at a time. So a vertex you merely pass through must have even degree. The only vertices allowed to be odd are the two endpoints of the walk (or none, if start = finish).

Königsberg's degrees are 5, 3, 3, 3 — four odd vertices. Since a path permits at most two, no route can cross all seven bridges once. That is Euler's 1736 result, usually called the first theorem of graph theory.

A companion fact — the Handshake Lemma — says the degrees always sum to twice the number of edges, so the count of odd-degree vertices is always even. That's why fixing the puzzle takes a single new bridge: adding one edge flips the parity of exactly its two endpoints, turning four odd vertices into two.

04

Research note

The theorem, exactly.
RESEARCH NOTE
The ledger reads degree parity straight off the live edge list and counts how many vertices are odd. An Euler path exists iff that count is 0 or 2 and the graph is connected — the verdict badge updates the instant you add the eighth bridge.
Go deeper: Euler, "Solutio problematis ad geometriam situs pertinentis" (1736); the Handshake Lemma ; Fleury's and Hierholzer's algorithms for actually finding the walk. Connects to #35 Game of Life (neighbour-graphs) and the map adjacencies in Tab 3.
01

Drive it — colour the graph

Six nodes, each joined to four others (an octahedron graph). Click a node to cycle its colour. The law: no edge may join two nodes of the same colour. Shrink the palette and find the fewest colours that still work.
DRIVE IT
coloured0 / 6 · bad edges0 colour every node
A conflict is an edge whose two ends share a colour — it flashes red. With a palette of 3 you can always finish clean; drop to 2 and at least one edge is doomed, because the graph contains triangles. The smallest palette that works is the chromatic number χ — here, 3.
PALETTE k3
VERTICES
6
nodes
EDGES
12
links
χ (CHROMATIC)
3
minimum
02

Walkthrough

Push the palette to its limit.
WALKTHROUGH
1
Leave k = 3. Click nodes to colour them and try to reach 0 bad edges. Trick: opposite nodes across the hexagon are not joined — give each opposite pair the same colour and you're done in three.
2
Hit auto-colour to watch a clean 3-colouring snap into place. The bad edges counter drops to 0 and the verdict turns green.
3
Now drag PALETTE down to 2. One colour vanishes from the graph, and no matter how you click, at least one edge stays red — the counter can't reach 0.
4
That failure is a proof: the graph has odd cycles / triangles, so two colours can't separate them. Three can. Three is therefore the chromatic number χ = 3.
THE INSIGHT
"Colouring isn't decoration — it's the smallest number of time-slots, frequencies or registers you need so that things that clash never share one. The chromatic number is the hard floor beneath every scheduling problem."
03

Explanation

Why colouring is everywhere.
EXPLANATION

A proper colouring assigns each vertex a colour so that adjacent vertices differ. The chromatic number χ(G) is the fewest colours that admit a proper colouring. A single triangle already needs 3; more generally any odd cycle needs 3, and a clique of n mutually-joined vertices needs n.

The graph here is the octahedron, K2,2,2: six vertices, the only non-edges being the three "antipodal" pairs. Colour each antipodal pair alike and three colours cover everything — but it's packed with triangles, so two never can. Hence χ = 3.

Finding χ in general is NP-hard — there's no known fast recipe for large graphs — which is exactly why it models so many real bottlenecks: exam timetabling (exams that share a student are adjacent), radio-frequency assignment (nearby transmitters are adjacent), register allocation in compilers (variables live at once are adjacent), and Sudoku (a 9-colouring of a 81-vertex graph).

Greedy colouring — take vertices in some order, give each the lowest colour not used by its neighbours — is fast and never uses more than Δ+1 colours (Δ = max degree). It isn't always optimal, but it's the workhorse the auto-colour button runs.

04

Research note

The bound, exactly.
RESEARCH NOTE
The ledger recomputes every edge's endpoints live and flags those that match; a colouring is proper exactly when that count hits 0. The palette slider physically removes a colour so you can feel the floor at χ = 3.
Go deeper: Brooks' theorem (χ ≤ Δ unless G is a clique or odd cycle) ; greedy / DSATUR heuristics; graph colouring is NP-complete for k ≥ 3. The map version — every planar graph needs ≤ 4 — is Tab 3.
01

Drive it — four-colour the map

A central country ringed by five neighbours, each touching the centre and its two ring-partners. Click a region to cycle its colour. Regions sharing a border must differ. It looks like it wants five colours — prove it doesn't.
DRIVE IT
coloured0 / 6 · bad borders0 colour every region
The five outer regions form an odd ring, so they alone already need 3 colours (you can't 2-colour a 5-cycle). The centre touches all five, so it needs a colour none of them use — a 4th. But four is always enough: no arrangement of regions in a flat plane ever forces a fifth.
REGIONS
6
countries
BORDERS
10
shared edges
COLOURS NEEDED
4
this map
02

Walkthrough

Meet the map that needs a fourth.
WALKTHROUGH
1
Ignore the centre. Colour the five outer regions alternating two colours as you go round — you'll be forced into a clash when the ring closes, because 5 is odd. A third colour breaks the tie.
2
Now colour the centre. It borders all five outer regions, which between them use three colours — so the centre must take a fourth. Watch the bad borders counter: it only reaches 0 once you've used four distinct colours.
3
Press auto four-colour to see a clean solution. Try to redo it with only three by re-clicking — the counter refuses to hit 0. Four is genuinely required for this map.
4
The deep claim of the Four-Colour Theorem: every map — however jagged or gerrymandered — needs at most four. No planar map has ever forced a fifth, and in 1976 that was proved once and for all.
THE INSIGHT
"Some maps really do need four colours — this one does. The astonishing part is the ceiling: no flat map, anywhere, ever needs a fifth. Four is a hard law of the plane itself."
03

Explanation

From map to graph, and a proof by computer.
EXPLANATION

Turn a map into a graph: one vertex per region, an edge whenever two regions share a border (a single touching point doesn't count). Colouring the map is then exactly proper vertex-colouring of this planar graph. This map's graph is the wheel W₅ — a hub joined to a 5-cycle rim — whose chromatic number is 4.

Why can't a map ever need more? Because planar graphs are sparse: they can't contain K₅ (five mutually-bordering regions) or K₃,₃. Getting from "sparse" to "four is enough" is famously hard — five colours is an easy afternoon's proof, four resisted for over a century.

Conjectured by Francis Guthrie in 1852, the Four-Colour Theorem was finally proved by Appel and Haken in 1976 — the first major theorem whose proof required a computer. They reduced every possible map to 1,936 unavoidable configurations and had a machine check each one could be four-coloured, hundreds of hours of computation no human could redo by hand.

That sparked a lasting debate: if no person can verify every step, is it really a proof? Modern formal-verification systems (Coq, 2005) have since machine-checked the machine-check, and the result stands. It remains the emblem of a new kind of mathematics — true, but only readable by computers.

04

Research note

The theorem, exactly.
RESEARCH NOTE
The ledger checks every shared border live against the region adjacency list and flags matches. This particular map is the wheel W₅, so it truly needs four — but the counter would also certify any 4-colouring of a far bigger map you fed it.
Go deeper: Guthrie's conjecture (1852); Appel & Haken (1976), the first computer-assisted proof; Robertson–Sanders–Seymour–Thomas simplification (1997); Gonthier's Coq formalisation (2005). The five-colour theorem is the easy cousin. Builds on Tab 2's chromatic number.
Idea #34 of the visual-maths series · Königsberg → chromatic number → the plane's four-colour law · all objects computed live in the browser, no libraries beyond KaTeX.