Graph Coloring

Chromatic number, the four color theorem, and applications

Graph Coloring

Graph coloring assigns labels (called "colors") to vertices so that no two adjacent vertices share the same color. This seemingly simple concept has profound applications in scheduling, map making, and computer science!

In this section, you'll discover the chromatic number, learn coloring algorithms, explore the famous Four Color Theorem, and see how graph coloring solves real scheduling problems.

What You'll Learn

🎨
Chromatic Number
The minimum colors needed for a proper coloring
🔢
Greedy Coloring
A simple algorithm and its limitations
🗺️
Four Color Theorem
Any map needs at most 4 colors
📅
Applications
Scheduling, register allocation, and more

Chromatic Number Explorer

The chromatic number χ(G) is the minimum number of colors needed to color a graph so no adjacent vertices share a color. Select a color and click vertices to color them!

Select color:

Click a vertex to color it with the selected color

0
Colors Used
3
χ(G) Optimal
0
Conflicts

About Chromatic Numbers

  • A proper coloring assigns colors so no adjacent vertices match
  • χ(G) is the minimum colors needed for a proper coloring
  • Complete graph Kn has χ(Kn) = n (every vertex is adjacent)
  • Bipartite graphs have χ(G) = 2
  • Odd cycles have χ(G) = 3, even cycles have χ(G) = 2

Greedy Coloring Algorithm

The greedy algorithm colors vertices in order, always picking the smallest available color. Watch how different orderings can 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

Greedy Coloring Algorithm

  1. Process vertices in the given order
  2. For each vertex, find colors used by its neighbors
  3. Assign the smallest color not used by any neighbor

Note: Greedy doesn't always find the optimal coloring! Different orderings can give different results. Try shuffling and running again!

Map Coloring & Four Color Theorem

The Four Color Theorem states that any map can be colored with at most 4 colors such that no adjacent regions share a color. Try coloring this map!

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

The Four Color Theorem

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 be proven this way!

The theorem states: Any planar graph can be colored with at most 4 colors such that no two adjacent vertices share a color. This applies directly to map coloring since maps are planar graphs.

Exam Scheduling as Graph Coloring

Graph coloring solves real scheduling problems! Here, exams are vertices, and edges connect exams with shared students (can't be at the same time). Colors represent time slots.

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

Other Applications of Graph Coloring

  • Register Allocation: Assign CPU registers to variables (conflicts when variables are used simultaneously)
  • Frequency Assignment: Assign radio frequencies to transmitters (adjacent transmitters need different frequencies)
  • Sudoku: A 9-coloring problem on a special graph!

What We've Learned

1. Chromatic Number: The chromatic number χ(G) is the minimum number of colors needed for a proper vertex coloring. Finding χ(G) is NP-hard in general, but some graphs have known values: complete Kn has χ = n, bipartite graphs have χ = 2.

2. Greedy Coloring: Process vertices in order, assigning the smallest available color. It's fast (O(V + E)) but doesn't always find the optimal coloring—the result depends on vertex ordering.

3. Four Color Theorem: Any planar graph (and thus any map) can be colored with at most 4 colors. This was proven in 1976 using computer assistance, making it one of the first major computer-assisted proofs.

4. Applications: Graph coloring models many real problems: exam scheduling (conflicts = edges, colors = time slots), register allocation in compilers, frequency assignment in wireless networks, and even Sudoku puzzles!

Next Up: In the next section, you'll learn about planar graphs — graphs that can be drawn without edge crossings, Euler's formula, and Kuratowski's theorem!