Graph Coloring and the Chromatic Number
Learning Objectives
- Define the chromatic number and prove , with graphs where each bound is far off.
- State Brooks' theorem with its hypotheses and show a failure when one is dropped.
- Show that greedy coloring depends on the vertex order, and test 2-colorability in linear time.
- Sketch the short five color proof and state the four color theorem with its proof history precisely.
- Place 3-colorability among the NP-complete problems.
Context & Motivation
Scheduling exams so no student has two at once and assigning frequencies so overlapping radio stations differ are the same problem: put conflicting items in a graph and give adjacent vertices different labels, called colors, using as few as possible.
planar-graphs stated the four color theorem without proof and derived the key fact behind it: every simple planar graph has a vertex of degree at most 5. This lesson proves five colors from that fact and explains why four was so much harder.
Core Theory
Proper colorings and the chromatic number
A proper coloring with colors is a map with for every edge . is -colorable if one exists, and the chromatic number is the least such . Color classes are independent sets. Loops make coloring impossible and parallel edges change nothing, so graphs here are simple. Basic values: , an even cycle has , an odd cycle has .
Coloring splits along the structure of graph-connectivity-cut-vertices-and-bridges. is the maximum of over the components, and if is the union of and sharing only a cut vertex , then : color each part optimally, then rename the colors of so that gets the same color in both. The running graph of that lesson thus has , from its triangle.
The clique lower bound
A clique is a set of pairwise adjacent vertices, and is the size of the largest. Clique vertices need distinct colors, so . The gap can be large: the Grötzsch graph (11 vertices, 20 edges, no triangle) has and , and Erdős proved in 1959 that for every some graph has no cycle of length at most and (Diestel, Theorem 5.2.5).
The greedy upper bound
Greedy coloring: fix an order and give each the smallest color not used by its already colored neighbors. When is reached, at most neighbors are colored, so one of colors is free:
Equality holds for complete graphs and odd cycles. Only earlier neighbors count, so the smallest-last order (put a minimum-degree vertex last, delete it, repeat) helps; Diestel's Proposition 5.2.2 shows it gives . Since every subgraph of a simple planar graph has a vertex of degree at most 5, planar graphs are 6-colorable.
Brooks' theorem
Theorem (Brooks 1941). Let be connected. If is neither a complete graph nor an odd cycle, then .
So the greedy bound is attained, among connected graphs, only by complete graphs and odd cycles. Each hypothesis matters:
- Complete: has and .
- Odd cycle: has and .
- Connected: the disjoint union of and is neither complete nor an odd cycle, has , and . Apply the theorem per component.
Diestel credits Lovász (1973) with a proof that runs greedy coloring on a carefully chosen order.
Order matters
For every graph some order makes greedy use exactly colors: list the vertices class by class from an optimal coloring. A vertex of class has no earlier neighbor in its own class, and earlier neighbors from classes hold colors at most (by induction), so it receives a color at most . Finding that order is as hard as finding the coloring, and a bad order can be arbitrarily worse (Example 2).
Two colors: bipartite graphs
A graph with at least one edge has exactly when it is bipartite, and Lehman, Leighton and Meyer prove that a graph is 2-colorable if and only if it has no odd cycle. The test runs in : in each component, color a vertex by the parity of its BFS distance from a start vertex. If an edge joins two vertices of the same color, the two BFS paths to its ends plus that edge form a closed walk of odd length, which contains an odd cycle. The Princeton Bipartite.java does the same with DFS.
Five colors with a short proof
Theorem. Every planar graph is 5-colorable.
The proof in Lehman, Leighton and Meyer is a strong induction on the number of vertices, using that deleting a vertex or merging two adjacent vertices keeps a graph planar. Take a vertex of degree at most 5, from the planar-graphs lemma.
- If , color by induction; sees at most four colors, so a fifth is free.
- If , two neighbors are non-adjacent, since five pairwise adjacent neighbors would form , which is not planar. Merge , and into one vertex, which keeps the graph planar and removes two vertices. Color the smaller graph by induction, give and the merged vertex's color, and 's five neighbors now use at most four colors, so takes the fifth.
Why not four colors? The same trick handles with four colors, but a planar graph may have every degree equal to 5 (Example 4). At degree 5 the neighbors may use all four colors even after one merge, and the argument would need two merges at once, which nothing guarantees. Kempe's 1879 attempt at four colors failed at this degree-5 case, in a step that swaps colors along two-colored chains: swapping one chain can scramble another, which Kempe missed (Gonthier's account). Heawood found the error in 1890 and turned the argument into a proof of five colors (Diestel's notes).
The four color theorem
Theorem. Every planar graph is 4-colorable. For maps: the regions of a map can be colored with four colors so that regions sharing a boundary segment (not just a point) differ, provided each region is one connected piece. Regions in several pieces can require more colors.
The proof history, from the open accounts listed below:
- Francis Guthrie raised the question in 1852. Kempe's 1879 proof was wrong (Heawood, 1890).
- Kenneth Appel and Wolfgang Haken announced a proof in 1976 and published it in 1977 in two parts in the Illinois Journal of Mathematics, the second with Koch. The method: exhibit an unavoidable set of configurations (one of them must appear in any minimal counterexample, shown by "discharging") and prove each one reducible (it cannot appear in a minimal counterexample). Reducibility was checked by computer, over more than a thousand configurations, and the unavoidability part, done by hand, was itself large; Gonthier describes it as 10,000 cases, difficult to verify, in which several small errors were found.
- Robertson, Sanders, Seymour and Thomas gave a new proof, published in 1997 after an announcement in 1996, with 633 reducible configurations and 32 discharging rules. Reducibility still needs a computer. Their method also yields a quadratic-time algorithm to 4-color a planar graph.
- Georges Gonthier wrote a formal proof checked by the Coq proof assistant, following Robertson et al. and covering both the mathematical and the computational parts, as his report linked below describes. What remains to trust is general-purpose software and hardware, not programs written for this theorem.
Why computing the chromatic number is hard
- 2 colors: linear time, by the bipartite test.
- 3 colors: deciding 3-colorability is NP-complete, and Lehman, Leighton and Meyer note that this remains true for planar graphs. A proposed coloring is checked edge by edge, which is why
np-completeness-and-cook-levinlists 3-colorability among the problems in NP; hardness comes from a reduction in the style ofproving-np-completeness-via-reduction. - colors: also NP-complete. Adding new vertices, adjacent to each other and to every old vertex, turns a 3-coloring question into a -coloring question.
- Planar, 4 colors: always yes, and a coloring is found in polynomial time.
So computing is NP-hard; brute force over assignments is already at .
Worked Examples
Example 1: the bounds on nine graphs
was computed by exhaustive backtracking, from the maximal cliques (networkx 3.4.2). The last column is Brooks' bound when its hypotheses hold.
| graph | Brooks | |||||
|---|---|---|---|---|---|---|
| 4 | 6 | 4 | 4 | 4 | complete | |
| 5 | 5 | 2 | 3 | 3 | odd cycle | |
| 6 | 6 | 2 | 2 | 3 | ||
| star | 7 | 6 | 2 | 2 | 7 | |
| 6 | 9 | 2 | 2 | 4 | ||
| wheel (hub + ) | 6 | 10 | 3 | 4 | 6 | |
| Petersen | 10 | 15 | 2 | 3 | 4 | |
| Grötzsch | 11 | 20 | 2 | 4 | 6 | |
| icosahedron | 12 | 30 | 3 | 4 | 6 |
The star shows how loose can be (7 against 2), the Grötzsch graph how loose can be (2 against 4). The planar wheel and icosahedron need four colors, so four cannot be improved to three.
Example 2: greedy order on a path and a crown
On the path ---, the order gives colors . The order gives and color 1, color 2, and then sees colors 2 and 1, so it takes color 3: three colors on a bipartite graph.
The crown graph on has an edge for every . It is bipartite. With (12 edges) and the order , each pair is non-adjacent but sees every earlier color, so greedy gives and color and uses 4 colors. The order uses 2. Over all orders, 30,240 give 2 colors, 7,200 give 3 and 2,880 give 4. With pairs the bad order uses colors (an exercise in Diestel). networkx's greedy_color strategies largest_first, smallest_last and DSATUR used 2 colors on the crowns with , but no polynomial-time ordering rule is optimal on every graph unless P = NP.
Example 3: the 2-coloring test on
Label the cycle ----- and run BFS from with color 0. Vertices and get color 1; then (from ) and (from ) get color 0. The edge - joins two vertices of color 0. The BFS paths and plus that edge form the closed walk of length 5, an odd cycle, which certifies that no 2-coloring exists.
Example 4: the five color step on the icosahedron
The icosahedron is planar with every vertex of degree exactly 5, so the low-degree lemma is tight and the proof must use its second case. In networkx's labeling, vertex has neighbors , which induce a 5-cycle; the non-adjacent pairs are . Merging , and gives a graph with 10 vertices that check_planarity confirms is planar and whose chromatic number is 4. Giving and the merged color leaves vertex facing at most four colors, so a fifth is free. (The icosahedron itself has ; smallest-last greedy found a 4-coloring.)
Common Misconceptions & Pitfalls
- "Greedy coloring finds ." It depends on the order: 3 colors on a path, 4 on a bipartite crown (Example 2).
- " for every graph." Brooks needs connected, not complete and not an odd cycle; , and break it.
- "Every planar graph needs four colors." At most four. Trees with an edge need two; the theorem bounds the maximum.
- "The four color theorem is just a computer search." The computer checks the reducibility of a finite set of configurations chosen by a mathematical argument, and the whole proof has since been checked formally in Coq.
- "Planar graphs are 4-colorable, so 3-coloring them is easy." Deciding planar 3-colorability is NP-complete.
- "A compiler computes of the interference graph."
register-allocation-via-graph-coloringcolors with colors, one per machine register, using a removal order and spilling a value to memory when no safe node remains.
Summary
is the fewest colors that give adjacent vertices different colors, and it splits over components and cut vertices. Cliques give , greedy coloring gives in any order, and both can be far from . Brooks lowers the upper bound to for connected graphs that are neither complete nor odd cycles. Greedy depends on the order: some order is optimal, a bad one uses colors on a bipartite graph. Two colors suffice exactly when there is no odd cycle, testable in linear time. Planar graphs are 5-colorable by a short induction; four colors took Appel and Haken's computer-assisted proof, the shorter proof of Robertson, Sanders, Seymour and Thomas, and Gonthier's formal verification. Deciding 3-colorability is NP-complete even for planar graphs, so computing is NP-hard. register-allocation-via-graph-coloring applies coloring with a fixed number of registers.
Documentation Links
- Lehman, Leighton and Meyer (2015): Mathematics for Computer Science
- Diestel (2025): Graph Theory, 6th ed., Chapter 5 (free preview)
- Robin Thomas: The Four Color Theorem
- Gonthier: A computer-checked proof of the Four Color Theorem
- rocq-community: fourcolor
- Sedgewick and Wayne: Algorithms, 4.1 Undirected Graphs
- NetworkX: greedy_color