Algorithm Search⌘K

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. G=(V,E)G = (V, E) is a simple graph with nn vertices. A coloring is a partial map cc from VV to {0,…,4}\{0, \ldots, 4\}; 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 vv is removed, it has at most 5 neighbours that are not yet removed. If GG is planar, every vertex is removed, so line L5 does not fail.

Proof. Let deg[u]deg[u] be the number of neighbours of uu that are not removed; line L4 keeps this true, since it decreases deg[u]deg[u] exactly when a neighbour of uu is removed. A vertex is pushed on QQ at line L1 if deg≤5deg \le 5 at the start, or at line L4 when degdeg drops from 6 to 5. Since degdeg 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 deg[v]≤5deg[v] \le 5 when vv is popped: a vertex in QQ has deg≤5deg \le 5, and it stays so. So the loop of line L2 runs at most nn times.

Now let GG be planar, and suppose the loop ends with a nonempty set RR of vertices that are not removed. Then QQ is empty, so each u∈Ru \in R has deg[u]≥6deg[u] \ge 6 (a vertex with deg[u]≤5deg[u] \le 5 was pushed when its degree first became at most 5, at line L1 or line L4, and is therefore removed). So the induced subgraph G[R]G[R] has minimum degree at least 6. But G[R]G[R] is a simple planar graph, and if ∣R∣≥3|R| \ge 3 it has at most 3∣R∣−63|R| - 6 edges by Euler's formula, so its average degree is less than 6, a contradiction; if ∣R∣≤2|R| \le 2 every degree is at most 1. □\square

Let S=s1,…,snS = s_1, \ldots, s_n be the removal order. By Lemma 1, each sks_k has at most 5 neighbours among sk+1,…,sns_{k+1}, \ldots, s_n.

Lemma 2 (Kempe swap). Let cc be a proper coloring, i≠ji \ne j two colors, xx a vertex of color ii, and KK the set of line L11. After swapping ii and jj on KK, the coloring is proper and has the same colored vertices.

Proof. KK is the vertex set of the connected component of xx in the subgraph HH induced by the colored vertices of color ii or jj; line L11 finds it by breadth-first search on HH. Consider an edge abab with both ends colored. If neither end is in KK, nothing changes. If both are in KK, both colors are swapped by the same bijection, so they stay different. If a∈Ka \in K and b∉Kb \notin K, then bb is not in HH, since bb is adjacent to a∈Ka \in K and KK is a component of HH. So c(b)∉{i,j}c(b) \notin \{i, j\}, while the new color of aa is in {i,j}\{i, j\}. □\square

Lemma 3 (some pair works). Let GG be planar, cc a proper coloring, and vv an uncolored vertex with exactly five colored neighbours of five different colors. Then for some pair of colors i<ji < j, the vertex yy of color jj among them is not in the chain KK of the vertex xx of color ii.

Proof. Fix a drawing of GG in the plane. Let x1,…,x5x_1, \ldots, x_5 be the five colored neighbours of vv in the cyclic order of their edges around vv, with colors c1,…,c5c_1, \ldots, c_5. Suppose that the {c1,c3}\{c_1, c_3\}-chain of x1x_1 contains x3x_3. Then there is a path PP from x1x_1 to x3x_3 whose vertices have colors c1c_1 or c3c_3. The path PP with the edges vx1v x_1 and vx3v x_3 is a cycle CC of GG, drawn as a simple closed curve. By the Jordan curve theorem, the plane minus CC has two regions. Near vv, a small disk around vv is cut by the two arcs of vx1vx_1 and vx3vx_3 into two sectors, one in each region; since the edges at vv come in the cyclic order x1,x2,x3,x4,x5x_1, x_2, x_3, x_4, x_5, the edge vx2v x_2 starts in one sector and vx4v x_4 in the other. These edges do not meet CC except at vv, because x2,x4∉Cx_2, x_4 \notin C (their colors are c2,c4∉{c1,c3}c_2, c_4 \notin \{c_1, c_3\}, and they differ from vv). So x2x_2 and x4x_4 lie in different regions of the plane minus CC.

Now suppose also that the {c2,c4}\{c_2, c_4\}-chain of x2x_2 contains x4x_4, by a path P′P' whose vertices have colors c2c_2 or c4c_4. No vertex of P′P' is on CC: the vertices of CC are vv, which is uncolored, and the vertices of PP, of colors c1c_1 or c3c_3. Edges of a plane drawing meet only at common ends, so the drawing of P′P' does not meet CC. It is a connected set from x2x_2 to x4x_4 in the plane minus CC, which contradicts the previous paragraph. So one of the two pairs {c1,c3}\{c_1, c_3\} or {c2,c4}\{c_2, c_4\} has the property of the lemma, for the vertex of the smaller color as xx (the chain of xx contains yy exactly when the chain of yy contains xx, since both are the component of HH containing xx). □\square

Theorem. If GG is planar, FIVE-COLOR stops and returns a proper coloring of all vertices with colors 00 to 44.

Proof. By Lemma 1 line L5 does not fail, and SS 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 vv in SS. At the start nothing is colored. At an iteration for v=skv = s_k, the colored neighbours of vv are its neighbours among sk+1,…,sns_{k+1}, \ldots, s_n, 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 vv a color that no colored neighbour has, so the coloring stays proper.

Otherwise vv has exactly 5 colored neighbours, of 5 different colors, and owner[k]owner[k] is the unique neighbour of color kk. The loop of line L9 tries the 10 pairs. By Lemma 3, some pair has y∉Ky \notin K, so line L13 is not reached. At the first such pair, line L12 swaps ii and jj on KK; by Lemma 2 the coloring stays proper. After the swap, x∈Kx \in K has color jj. The other neighbours of vv keep their colors: y∉Ky \notin K, and the other three have colors outside {i,j}\{i, j\}, so they are not in KK. So no colored neighbour of vv has color ii, and c(v)=ic(v) = i keeps the coloring proper.

Every loop is finite: lines L2 to L4 run at most nn times by Lemma 1, line L6 runs nn times, line L9 at most 10 times for each vv, and the search of line L11 adds each vertex to KK at most once. After the last iteration all vertices are colored, and line L14 returns a proper 5-coloring. ■\blacksquare

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.

Back to Five-color algorithm