Algorithms

Graph Coloring

Graph coloring assigns colors to vertices with adjacent vertices different. Greedy coloring is fast but can use more colors than necessary; the chromatic number is the minimum.

6 minLevel 2/3The interactive stage stays ad-free.
Colored0 / 9Colors used0Current node—MethodGreedy
012345678

Nodes are processed in degree-descending order. Each node receives the smallest color not used by an already-colored neighbor. Greedy coloring is fast, but a different order can use fewer colors. The minimum possible number is the chromatic number.

What you are seeing

1

Process vertices in some order and give each the smallest color not used by its already-colored neighbors.

2

The number of colors used depends on the vertex order. Degree-descending order often uses fewer colors.

3

The chromatic number is the minimum number of colors over all valid colorings. Finding it is NP-hard in general.

Why it matters

Graph coloring models scheduling, register allocation, frequency assignment, and map coloring.

Complexity & details

Greedy coloring: O(V + E). Exact chromatic number: NP-hard.

Frequently asked questions

Why can greedy use extra colors?+

A vertex may be forced to take a new color because all smaller colors are already used by its colored neighbors, even if a different order would avoid it.

What is the four-color theorem?+

Every planar map can be colored with at most four colors so that adjacent regions differ.