Proofs: Five-color algorithm
These are the human proofs of Five-color algorithm, at full length.
The five-color algorithm returns a proper 5-coloring of every planar graph full
This proof shows: correctness, termination.
We use the pseudocode of the page. is a simple graph with vertices. A coloring is a partial map from to ; it is proper if no edge has two colored ends of the same color.
Lemma 1 (peeling). Lines L1 to L4 remove each vertex at most once. When a vertex is removed, it has at most 5 neighbours that are not yet removed. If is planar, every vertex is removed, so line L5 does not fail.
Proof. Let be the number of neighbours of that are not removed; line L4 keeps this true, since it decreases exactly when a neighbour of is removed. A vertex is pushed on at line L1 if at the start, or at line L4 when drops from 6 to 5. Since only decreases, and by exactly 1 at a time, each vertex is pushed at most once, so it is popped and removed at most once, and when is popped: a vertex in has , and it stays so. So the loop of line L2 runs at most times.
Now let be planar, and suppose the loop ends with a nonempty set of vertices that are not removed. Then is empty, so each has (a vertex with was pushed when its degree first became at most 5, at line L1 or line L4, and is therefore removed). So the induced subgraph has minimum degree at least 6. But is a simple planar graph, and if it has at most edges by Euler's formula, so its average degree is less than 6, a contradiction; if every degree is at most 1.
Let be the removal order. By Lemma 1, each has at most 5 neighbours among .
Lemma 2 (Kempe swap). Let be a proper coloring, two colors, a vertex of color , and the set of line L11. After swapping and on , the coloring is proper and has the same colored vertices.
Proof. is the vertex set of the connected component of in the subgraph induced by the colored vertices of color or ; line L11 finds it by breadth-first search on . Consider an edge with both ends colored. If neither end is in , nothing changes. If both are in , both colors are swapped by the same bijection, so they stay different. If and , then is not in , since is adjacent to and is a component of . So , while the new color of is in .
Lemma 3 (some pair works). Let be planar, a proper coloring, and an uncolored vertex with exactly five colored neighbours of five different colors. Then for some pair of colors , the vertex of color among them is not in the chain of the vertex of color .
Proof. Fix a drawing of in the plane. Let be the five colored neighbours of in the cyclic order of their edges around , with colors . Suppose that the -chain of contains . Then there is a path from to whose vertices have colors or . The path with the edges and is a cycle of , drawn as a simple closed curve. By the Jordan curve theorem, the plane minus has two regions. Near , a small disk around is cut by the two arcs of and into two sectors, one in each region; since the edges at come in the cyclic order , the edge starts in one sector and in the other. These edges do not meet except at , because (their colors are , and they differ from ). So and lie in different regions of the plane minus .
Now suppose also that the -chain of contains , by a path whose vertices have colors or . No vertex of is on : the vertices of are , which is uncolored, and the vertices of , of colors or . Edges of a plane drawing meet only at common ends, so the drawing of does not meet . It is a connected set from to in the plane minus , which contradicts the previous paragraph. So one of the two pairs or has the property of the lemma, for the vertex of the smaller color as (the chain of contains exactly when the chain of contains , since both are the component of containing ).
Theorem. If is planar, FIVE-COLOR stops and returns a proper coloring of all vertices with colors to .
Proof. By Lemma 1 line L5 does not fail, and holds every vertex once. We show by induction on the number of vertices processed by line L6 that before each iteration the coloring is proper and the colored vertices are exactly those after in . At the start nothing is colored. At an iteration for , the colored neighbours of are its neighbours among , at most 5 of them by Lemma 1. Line L7 records one neighbour for each color used.
If fewer than 5 colors are used, line L8 gives a color that no colored neighbour has, so the coloring stays proper.
Otherwise has exactly 5 colored neighbours, of 5 different colors, and is the unique neighbour of color . The loop of line L9 tries the 10 pairs. By Lemma 3, some pair has , so line L13 is not reached. At the first such pair, line L12 swaps and on ; by Lemma 2 the coloring stays proper. After the swap, has color . The other neighbours of keep their colors: , and the other three have colors outside , so they are not in . So no colored neighbour of has color , and keeps the coloring proper.
Every loop is finite: lines L2 to L4 run at most times by Lemma 1, line L6 runs times, line L9 at most 10 times for each , and the search of line L11 adds each vertex to at most once. After the last iteration all vertices are colored, and line L14 returns a proper 5-coloring.
Non-planar inputs. Lemmas 1 and 2 and the induction hold for every simple graph; only Lemma 3 uses planarity. So on any input the algorithm either fails at line L5 or line L13, or returns a proper 5-coloring.