Definition: Chromatic Number
The chromatic number (die chromatische Zahl) of a graph is the minimum number of colors needed to color its vertices so that adjacent vertices have different colors.
Equivalence
is -partite

The Coloring Problem
A NP-hard question
Given a graph , is ?
Approximation
Approximating the chromatic number is also hard:
- For every , approximating within a factor of is NP-hard.
- Even for the promise version with (that is, when the graph is known to be 3-colorable), finding an optimal coloring is hard.
- However, for 3-colorable graphs, there is an algorithm that uses colors within time
Greedy Algorithm
- Choose an order of the vertices.
- Go through the vertices one by one.
- Assign each vertex the smallest color that is not already used by its colored neighbors.
Degree bound
For any graph , greedy coloring uses at most colors, where is the maximum degree of .
Time:
One common heuristic is:
- Repeatedly delete a vertex of smallest current degree.
- Store the deleted vertices in a stack.
- Reinsert them in reverse order and rcolor each vertex greedily.
This is the smallest-degree-last ordering. we start with the vertex that has the highest degree (NOT in any order from highest to lowest).
An counter example would be :
Counter example coloring order.excalidraw
⚠ Switch to EXCALIDRAW VIEW in the MORE OPTIONS menu of this document. ⚠ You can decompress Drawing data with the command palette: ‘Decompress current Excalidraw file’. For more info check in plugin settings under ‘Saving’
Excalidraw Data
Text Elements
1
2
3
4
5
6
not possible
Link to original
So the algorithm is less likely to introduce a new color, and it yields a coloring with at most colors, where is the degeneracy of the graph. The degeneracy of a graph is the smallest number d such that every subgraph has a vertex of degree at most d.
Brook’s theorem
Brooks' theorem
If is connected and is neither a complete graph nor an odd cycle, then
Time:
Proof idea
The ordinary greedy bound gives .
Brooks’ theorem improves this by forcing two neighbors of one vertex to receive the same color, which frees one color for that vertex at the end.
Coloring by blocks
Coloring by blocks
Let be a graph. If every block of can be colored with colors, then itself can be colored with colors.
Examples
Interference Graph Example
In register allocation, two variables interfere if they are live at the same time, so they cannot use the same register.
t1 = a + b
t2 = t1 * c
t3 = t1 - d
return t2 + t3Here t2 and t3 are both needed at the return, so they are live at the same time. Also, t1 interferes with t2 and t3 while those values are being computed.
Interference graph:
t1 -- t2
|
t3
t2 -- t3So the graph is a triangle. A triangle needs 3 colors, which means this code needs 3 different registers if we want to keep all three temporaries in registers at once.
Example: 4-color Theorem
In map coloring, each region is a vertex, and two vertices are connected if the regions share a border. A graph is planar if it can be drawn in the plane without any edges crossing.
4 Color Theorem
Every planar graph can be colored with at most 4 colors. Equivalently, if is planar, then .
Degree bound for planar graphs
Every planar graph has at least one vertex of degree at most .