Graph Coloring and the Chromatic Number

Published on 2026-11-06·v1.0

Learning Objectives

  • Define the chromatic number χ(G)\chi(G) and prove ω(G)≤χ(G)≤Δ(G)+1\omega(G)\le\chi(G)\le\Delta(G)+1, 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 kk colors is a map c:V→{1,…,k}c:V\to\{1,\dots,k\} with c(u)≠c(v)c(u)\neq c(v) for every edge uvuv. GG is kk-colorable if one exists, and the chromatic number χ(G)\chi(G) is the least such kk. Color classes are independent sets. Loops make coloring impossible and parallel edges change nothing, so graphs here are simple. Basic values: χ(Kn)=n\chi(K_n)=n, an even cycle has χ=2\chi=2, an odd cycle has χ=3\chi=3.

Coloring splits along the structure of graph-connectivity-cut-vertices-and-bridges. χ(G)\chi(G) is the maximum of χ\chi over the components, and if GG is the union of G1G_1 and G2G_2 sharing only a cut vertex vv, then χ(G)=max⁡(χ(G1),χ(G2))\chi(G)=\max(\chi(G_1),\chi(G_2)): color each part optimally, then rename the colors of G2G_2 so that vv gets the same color in both. The running graph of that lesson thus has χ=3\chi=3, from its triangle.

The clique lower bound

A clique is a set of pairwise adjacent vertices, and ω(G)\omega(G) is the size of the largest. Clique vertices need distinct colors, so ω(G)≤χ(G)\omega(G)\le\chi(G). The gap can be large: the Grötzsch graph (11 vertices, 20 edges, no triangle) has ω=2\omega=2 and χ=4\chi=4, and Erdős proved in 1959 that for every kk some graph has no cycle of length at most kk and χ>k\chi>k (Diestel, Theorem 5.2.5).

The greedy upper bound

Greedy coloring: fix an order v1,…,vnv_1,\dots,v_n and give each viv_i the smallest color not used by its already colored neighbors. When viv_i is reached, at most Δ(G)\Delta(G) neighbors are colored, so one of Δ+1\Delta+1 colors is free:

χ(G)≤Δ(G)+1for every graph, with any order.\chi(G)\le\Delta(G)+1\quad\text{for every graph, with any order.}

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 χ(G)≤max⁡H⊆Gδ(H)+1\chi(G)\le\max_{H\subseteq G}\delta(H)+1. 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 GG be connected. If GG is neither a complete graph nor an odd cycle, then χ(G)≤Δ(G)\chi(G)\le\Delta(G).

So the greedy bound Δ+1\Delta+1 is attained, among connected graphs, only by complete graphs and odd cycles. Each hypothesis matters:

  • Complete: K4K_4 has Δ=3\Delta=3 and χ=4\chi=4.
  • Odd cycle: C5C_5 has Δ=2\Delta=2 and χ=3\chi=3.
  • Connected: the disjoint union of K4K_4 and C4C_4 is neither complete nor an odd cycle, has Δ=3\Delta=3, and χ=4\chi=4. 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 χ(G)\chi(G) colors: list the vertices class by class from an optimal coloring. A vertex of class ii has no earlier neighbor in its own class, and earlier neighbors from classes 1,…,i−11,\dots,i-1 hold colors at most i−1i-1 (by induction), so it receives a color at most ii. 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 χ=2\chi=2 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 O(V+E)O(V+E): 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 gg of degree at most 5, from the planar-graphs lemma.

  • If deg⁡g<5\deg g<5, color G−gG-g by induction; gg sees at most four colors, so a fifth is free.
  • If deg⁡g=5\deg g=5, two neighbors n1,n2n_1,n_2 are non-adjacent, since five pairwise adjacent neighbors would form K5K_5, which is not planar. Merge n1n_1, gg and n2n_2 into one vertex, which keeps the graph planar and removes two vertices. Color the smaller graph by induction, give n1n_1 and n2n_2 the merged vertex's color, and gg's five neighbors now use at most four colors, so gg takes the fifth.

Why not four colors? The same trick handles deg⁡g≤4\deg g\le4 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-levin lists 3-colorability among the problems in NP; hardness comes from a reduction in the style of proving-np-completeness-via-reduction.
  • k≥3k\ge3 colors: also NP-complete. Adding k−3k-3 new vertices, adjacent to each other and to every old vertex, turns a 3-coloring question into a kk-coloring question.
  • Planar, 4 colors: always yes, and a coloring is found in polynomial time.

So computing χ\chi is NP-hard; brute force over 3n3^n assignments is already 330≈2.06×10143^{30}\approx2.06\times10^{14} at n=30n=30.

Worked Examples

Example 1: the bounds on nine graphs

χ\chi was computed by exhaustive backtracking, ω\omega from the maximal cliques (networkx 3.4.2). The last column is Brooks' bound when its hypotheses hold.

graph nn mm ω\omega χ\chi Δ+1\Delta+1 Brooks
K4K_4 4 6 4 4 4 complete
C5C_5 5 5 2 3 3 odd cycle
C6C_6 6 6 2 2 3 ≤2\le2
star K1,6K_{1,6} 7 6 2 2 7 ≤6\le6
K3,3K_{3,3} 6 9 2 2 4 ≤3\le3
wheel (hub + C5C_5) 6 10 3 4 6 ≤5\le5
Petersen 10 15 2 3 4 ≤3\le3
Grötzsch 11 20 2 4 6 ≤5\le5
icosahedron 12 30 3 4 6 ≤5\le5

The star shows how loose Δ+1\Delta+1 can be (7 against 2), the Grötzsch graph how loose ω\omega 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 11-22-33-44, the order 1,2,3,41,2,3,4 gives colors 1,2,1,21,2,1,2. The order 1,4,2,31,4,2,3 gives 11 and 44 color 1, 22 color 2, and then 33 sees colors 2 and 1, so it takes color 3: three colors on a bipartite graph.

The crown graph on a1,…,an,b1,…,bna_1,\dots,a_n,b_1,\dots,b_n has an edge aibja_ib_j for every i≠ji\neq j. It is bipartite. With n=4n=4 (12 edges) and the order a1,b1,a2,b2,a3,b3,a4,b4a_1,b_1,a_2,b_2,a_3,b_3,a_4,b_4, each pair ai,bia_i,b_i is non-adjacent but sees every earlier color, so greedy gives aia_i and bib_i color ii and uses 4 colors. The order a1,…,a4,b1,…,b4a_1,\dots,a_4,b_1,\dots,b_4 uses 2. Over all 8!=40,3208!=40{,}320 orders, 30,240 give 2 colors, 7,200 give 3 and 2,880 give 4. With nn pairs the bad order uses nn colors (an exercise in Diestel). networkx's greedy_color strategies largest_first, smallest_last and DSATUR used 2 colors on the crowns with n=3,4,5n=3,4,5, but no polynomial-time ordering rule is optimal on every graph unless P = NP.

Example 3: the 2-coloring test on C5C_5

Label the cycle 00-11-22-33-44-00 and run BFS from 00 with color 0. Vertices 11 and 44 get color 1; then 22 (from 11) and 33 (from 44) get color 0. The edge 22-33 joins two vertices of color 0. The BFS paths 0,1,20,1,2 and 0,4,30,4,3 plus that edge form the closed walk 0,1,2,3,4,00,1,2,3,4,0 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 00 has neighbors 1,5,7,8,111,5,7,8,11, which induce a 5-cycle; the non-adjacent pairs are {1,7},{1,11},{5,7},{5,8},{8,11}\{1,7\},\{1,11\},\{5,7\},\{5,8\},\{8,11\}. Merging 11, 00 and 77 gives a graph with 10 vertices that check_planarity confirms is planar and whose chromatic number is 4. Giving 11 and 77 the merged color leaves vertex 00 facing at most four colors, so a fifth is free. (The icosahedron itself has χ=4\chi=4; smallest-last greedy found a 4-coloring.)

Common Misconceptions & Pitfalls

  • "Greedy coloring finds χ\chi." It depends on the order: 3 colors on a path, 4 on a bipartite crown (Example 2).
  • "χ≤Δ\chi\le\Delta for every graph." Brooks needs connected, not complete and not an odd cycle; K4K_4, C5C_5 and K4∪C4K_4\cup C_4 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 χ\chi of the interference graph." register-allocation-via-graph-coloring colors with KK colors, one per machine register, using a removal order and spilling a value to memory when no safe node remains.

Summary

χ(G)\chi(G) is the fewest colors that give adjacent vertices different colors, and it splits over components and cut vertices. Cliques give ω≤χ\omega\le\chi, greedy coloring gives χ≤Δ+1\chi\le\Delta+1 in any order, and both can be far from χ\chi. Brooks lowers the upper bound to Δ\Delta for connected graphs that are neither complete nor odd cycles. Greedy depends on the order: some order is optimal, a bad one uses nn 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 χ\chi is NP-hard. register-allocation-via-graph-coloring applies coloring with a fixed number of registers.

Documentation Links