Graph Coloring

Chromatic number, the four color theorem, and applications

Coloring Graphs

Graph coloring assigns labels (called "colors") to vertices so that no two adjacent vertices share the same color. The minimum number of colors needed for a proper coloring is called the chromatic number of the graph.

Finding the chromatic number is NP-hard in general, but greedy algorithms provide fast approximations. The celebrated Four Color Theorem guarantees that every planar graph can be properly colored with at most four colors. Graph coloring also models practical problems such as exam scheduling and register allocation.

Chromatic Number Explorer

Select a color from the palette and click vertices to color them. Try to achieve a proper coloring using the minimum number of colors. Switch between preset graphs with known chromatic numbers to test your intuition.

Select color:

Click a vertex to color it with the selected color

0
Colors Used
3
χ(G) Optimal
0
Conflicts

Key insight: Complete graphs Kn require exactly n colors, bipartite graphs need only 2, and odd cycles need 3. The chromatic number captures the essential "conflict density" of a graph.

Greedy Coloring Algorithm

The greedy algorithm processes vertices in a fixed order, assigning each the smallest color not used by its already-colored neighbors. Shuffle the vertex ordering and run the algorithm again to see how different orderings produce different results.

Vertex Ordering

1.A
2.B
3.C
4.D
5.E
6.F
0 / 6
Vertices Colored
Colors Used
3
χ(G) Optimal

Key insight: Greedy coloring runs in O(V + E) time but does not always achieve the optimal chromatic number. The result depends entirely on the vertex ordering, and some orderings may use far more colors than necessary.

Map Coloring and the Four Color Theorem

The Four Color Theorem states that any map can be colored with at most four colors so that no two adjacent regions share a color. Select a color and click regions to color this map. Hover over a region to highlight its neighbors.

Select color:
ABCDEFG

Click a region to color it. Hover to see adjacent regions highlighted.

0 / 7
Regions Colored
0 / 4
Colors Used
0
Conflicts

Key insight: First conjectured in 1852, the Four Color Theorem was proven in 1976 by Appel and Haken using computer-assisted proof -- the first major theorem to require computational verification.

Exam Scheduling as Graph Coloring

Graph coloring models real scheduling problems. Here, exams are vertices and edges connect exams with shared students. Colors represent time slots. Click an exam to select it, then assign a time slot, or let the greedy algorithm schedule automatically.

Time Slots:
9:00 AM
11:00 AM
2:00 PM
4:00 PM

Click an exam to select it, then choose a time slot below

0 / 5
Exams Scheduled
0
Time Slots Used
0
Conflicts

Key insight: Graph coloring appears in register allocation (variables that overlap in lifetime cannot share a register), frequency assignment (adjacent transmitters need different frequencies), and even Sudoku puzzles.

Key Takeaways

  • Chromatic number -- the minimum colors for a proper coloring; NP-hard to compute in general, but known for many graph families
  • Greedy coloring -- fast O(V + E) algorithm that assigns the smallest available color, but the result depends on vertex ordering
  • Four Color Theorem -- every planar graph (and thus every map) can be properly colored with at most 4 colors
  • Applications -- graph coloring models scheduling, register allocation, frequency assignment, and constraint satisfaction problems