Graph Coloring
Graph coloring assigns a color to each vertex of a graph so that no two vertices joined by an edge share a color. The chromatic number χ(G) is the fewest colors that work. To find it, show that some number of colors is needed, then find a coloring that uses exactly that many.
Before this lesson: Graph Theory Basics, Bipartite Graphs and Hamilton Paths and Circuits
The idea
Suppose six classes need final exam times, and some students take two of the classes. Two classes that share a student cannot meet at the same time. Make each class a vertex and join two classes when they share a student. Each time slot is a “color,” and the fewest time slots is the chromatic number.
The same model fits radio stations that are too close to share a frequency, countries on a map that share a border, and registers in a computer program. In each case, “joined by an edge” means “must be different.”
Graph coloring definitions
- A proper coloring gives every vertex a color so that the two ends of every edge get different colors. A proper coloring with k colors is a k-coloring.
- The chromatic number χ(G) (Greek letter chi) is the smallest k for which G has a k-coloring.
- The vertices of one color form a color class. No two vertices in a color class are adjacent, and the color classes split the vertex set into parts, like the classes of an equivalence relation.
We usually write colors as numbers 1, 2, 3, …, so a coloring is a list such as A = 1, B = 2, C = 1.
Rules for the chromatic number
- χ(G) = 1 exactly when G has no edges.
- χ(G) ≤ 2 exactly when G is bipartite, that is, when G has no cycle of odd length. So an even cycle has χ = 2, and an odd cycle has χ = 3.
- The complete graph has \chi(K_n) = n, because every pair of vertices is adjacent.
- Lower bound: if G contains a clique of k vertices (k vertices all joined to each other), then \chi(G) \ge k. An odd cycle also forces at least 3.
- Upper bound: if the largest degree in G is Δ, then \chi(G) \le \Delta + 1. The greedy method below always stays within this bound.
How to find χ(G): find a lower bound L (a clique, an odd cycle, or a short argument), then find a proper coloring with L colors. When the two numbers match, χ(G) = L.
The greedy coloring algorithm
- List the vertices in some order. The Welsh–Powell version lists them from largest degree to smallest.
- Give the first vertex color 1.
- Go down the list and give each vertex the smallest color number not already used by one of its colored neighbors.
- Stop when every vertex is colored.
Greedy coloring is fast, but the order matters. It always gives a proper coloring with at most Δ + 1 colors, yet it can use more colors than χ(G). That is why you still need a lower bound to prove the answer is the smallest.
Graph coloring examples
Example 1: Coloring an odd cycle
Find the chromatic number of the 5-cycle C_5 with vertices 1, 2, 3, 4, 5 in order around the cycle.
1 \to \text{A}, \ 2 \to \text{B}Try 2 colors: vertices 1 and 2 are adjacent, so they need different colors, A and B.
3 \to \text{A}, \ 4 \to \text{B}With only 2 colors, each next vertex must switch, so the colors alternate.
5 \to \text{?}Vertex 5 is adjacent to 4 (B) and to 1 (A), so 2 colors fail.
\chi(C_5) \ge 3
So at least 3 colors are needed.
1, 2, 1, 2, 3
Give vertices 1–5 these colors; check all five edges: 1–2, 2–1, 1–2, 2–3 and 3–1 all differ.
Answer: \chi(C_5) = 3. The same argument works for every odd cycle.
Example 2: A wheel that needs four colors
The wheel W_5 has a hub H joined to every vertex of a 5-cycle A, B, C, D, E. Find its chromatic number.
\chi(C_5) = 3
The rim is an odd cycle, so it needs 3 colors by Example 1.
H \ne \text{all rim colors}The hub is adjacent to every rim vertex, so it cannot reuse any of those 3 colors.
\chi(W_5) \ge 3 + 1 = 4
The hub needs a fourth color.
A, B, C, D, E \to 1, 2, 1, 2, 3
Color the rim as in Example 1.
H = 4
Give the hub the fourth color.
Answer: \chi(W_5) = 4. A wheel around an even cycle needs only 3 colors (see Example 4).
Example 3: The Welsh–Powell greedy algorithm
Graph G has vertices A to F and edges AB, AC, AD, BC, BE, CD, CF, DE and EF. Color it with the Welsh–Powell method and find χ(G).
\deg(C) = 4
C lies on AC, BC, CD and CF.
\deg(A) = \deg(B) = \deg(D) = \deg(E) = 3
Count edges at each; F has degree 2.
C, A, B, D, E, F
List the vertices by degree, largest first (ties alphabetical).
C = 1
The first vertex gets color 1.
A = 2
A is adjacent to C (1), so it gets 2.
B = 3
B is adjacent to C (1) and A (2), so it gets 3.
D = 3
D is adjacent to C (1) and A (2), but not to B, so 3 is available.
E = 1
E is adjacent to B (3) and D (3), but not to C, so 1 is available.
F = 2
F is adjacent to C (1) and E (1), so it gets 2.
\{A, B, C\} \text{ is a triangle}AB, AC and BC are all edges, so \chi(G) \ge 3.
Answer: the coloring C = 1, E = 1, A = 2, F = 2, B = 3, D = 3 uses 3 colors, and the triangle shows 3 are needed, so χ(G) = 3.
Example 4: Coloring a map
A map has a central region E surrounded by four regions A, B, C and D in a ring. Each outer region borders E and the two outer regions next to it. What is the fewest number of colors needed so that bordering regions differ?
\text{region} \to \text{vertex}Make each region a vertex and join regions that share a border.
A, B, C, D, A
The outer regions form a 4-cycle, an even cycle.
A = 1, B = 2, C = 1, D = 2
An even cycle needs only 2 colors.
E = 3
E borders all four outer regions, so it needs a third color.
\{A, B, E\} \text{ is a triangle}A, B and E all border each other, so at least 3 colors are needed.
Answer: 3 colors. The four color theorem says that 4 colors are always enough for any map drawn in the plane; the Planar Graphs lesson explains the graphs behind it.
Example 5: Scheduling exams (word problem)
Five exams need time slots. Students take these pairs together: Math and Biology, Math and Chemistry, Math and English, Biology and Chemistry, Chemistry and History, and English and History. What is the fewest number of time slots so that no student has two exams at once?
M, B, C, E, H
Make each exam a vertex, and join two exams that share students.
\{M, B, C\} \text{ is a triangle}Math, Biology and Chemistry all conflict, so at least 3 slots are needed.
M = 1, \ B = 2, \ C = 3
The triangle needs three different slots.
E = 2
English conflicts with Math (1) and History (not yet set), so slot 2 works.
H = 1
History conflicts with Chemistry (3) and English (2), so slot 1 works.
Answer: 3 time slots. Slot 1: Math and History; slot 2: Biology and English; slot 3: Chemistry.
Common mistakes
| Mistake | Example of the error | Fix |
|---|---|---|
| Coloring edges instead of vertices | Making sure two edges at a vertex differ | In vertex coloring, the two ends of each edge must differ. |
| Stopping at a coloring without a lower bound | “I found a 4-coloring, so χ(G) = 4.” | A coloring only shows χ(G) ≤ 4. Find a clique or odd cycle that proves you cannot do better. |
| Trusting greedy coloring as the answer | Greedy on a path in the order a, d, b, c uses 3 colors | Greedy gives an upper bound only. A path is bipartite, so χ = 2. |
| Thinking an odd number of vertices needs 3 colors | “A path with 5 vertices needs 3 colors.” | Odd cycles need 3. A path has no cycle, so 2 colors work. |
| Assuming χ equals the largest clique | “The wheel W₅ has no K₄, so 3 colors are enough.” | A clique gives only a lower bound; W₅ has no K₄ yet needs 4. |
| Treating corner-touching regions as neighbors | Coloring two map regions differently because they meet at one point | Only regions that share a border segment are adjacent. |
Related ideas
Brooks’ theorem
The greedy bound χ(G) ≤ Δ + 1 is reached only in special cases. Brooks’ theorem says that a connected graph has χ(G) ≤ Δ unless it is a complete graph or an odd cycle.
The chromatic polynomial
The chromatic polynomial P(G, k) counts the proper colorings of G with k available colors. For a triangle, the first vertex has k choices, the second k − 1 and the third k − 2, so P = k(k − 1)(k − 2) by the product rule for counting. The chromatic number is the smallest k with P(G, k) > 0.
Edge coloring and Sudoku
In edge coloring, edges that share a vertex must get different colors; this models scheduling games so that no team plays twice in one round. A Sudoku puzzle is a vertex coloring with 9 colors of a graph with 81 vertices, where cells in the same row, column or box are adjacent.
Practice problems
- Find \chi(K_6).
- Find the chromatic numbers of the cycles C_8 and C_7.
- Find the chromatic number of a path with 5 vertices.
- Find \chi(K_{3,4}).
- A graph contains four vertices that are all adjacent to each other. What can you say about its chromatic number?
- Every vertex of a graph has degree at most 3. What upper bound does the greedy method give for χ(G)?
- Is the coloring A = 1, B = 2, C = 1 a proper coloring of the triangle ABC?
- Find the chromatic number of the wheel W_6, a hub joined to every vertex of a 6-cycle.
- Six committees P, Q, R, S, T and U need meeting times. These pairs share members: P–Q, P–R, Q–R, R–S, S–T, T–U and U–P. Find the fewest meeting times needed.
- Color the path a–b–c–d greedily in the order a, d, b, c. How many colors does greedy use? What is the chromatic number?
Show answers
1.
\chi(K_n) = n
In a complete graph every pair is adjacent, so every vertex needs its own color.
Answer: 6
2.
C_8 \text{ is even}An even cycle is bipartite, so colors can alternate 1, 2, 1, 2, ….
C_7 \text{ is odd}Alternating fails at the last vertex, so an odd cycle needs 3.
Answer: \chi(C_8) = 2 and \chi(C_7) = 3
3.
1, 2, 1, 2, 1
Alternate colors along the path; a path has no cycles.
Answer: 2
4.
K_{3,4} \text{ is bipartite}Color one side 1 and the other side 2; it has at least one edge.
Answer: 2
5.
K_4 \subseteq G
Four mutually adjacent vertices form a clique of size 4.
\chi(G) \ge 4
A clique of k vertices needs k colors.
Answer: χ(G) ≥ 4
6.
\Delta + 1 = 3 + 1 = 4
Use the greedy bound with Δ = 3.
Answer: χ(G) ≤ 4
7.
A = C = 1
A and C are adjacent in a triangle, but they share color 1.
Answer: no
8.
1, 2, 1, 2, 1, 2
The rim is an even cycle, so 2 colors alternate.
H = 3
The hub touches every rim vertex, so it needs a third color.
\{H, 1, 2\} \text{ is a triangle}So at least 3 colors are needed.
Answer: 3
9.
\{P, Q, R\} \text{ is a triangle}P, Q and R all share members, so at least 3 times are needed.
P = 1, \ Q = 2, \ R = 3
Give the triangle three different times.
S = 1
S conflicts only with R (3) and T (not yet set).
T = 2
T conflicts with S (1) and U (not yet set).
U = 3
U conflicts with T (2) and P (1).
Answer: 3 meeting times (P and S; Q and T; R and U)
10.
a = 1, \ d = 1
a and d are not adjacent, so both get color 1.
b = 2
b is adjacent to a (1).
c = 3
c is adjacent to b (2) and d (1).
1, 2, 1, 2
But coloring in path order a, b, c, d uses only 2 colors.
Answer: greedy uses 3 colors in that order, but χ = 2
Graph coloring FAQ
What is the chromatic number of a graph?
It is the smallest number of colors needed to color the vertices so that every edge joins two different colors. It is written χ(G).
How do you find the chromatic number?
Find a lower bound, such as a clique of k vertices or an odd cycle, then find a proper coloring with that many colors. If the coloring matches the bound, that number is the chromatic number.
What is the four color theorem?
It says that the regions of any map drawn in the plane can be colored with at most 4 colors so that regions sharing a border differ. It was proved in 1976 with the help of a computer.
What is graph coloring used for?
Graph coloring models scheduling (exams, meetings, sports rounds), assigning radio frequencies, coloring maps, solving Sudoku, and assigning registers in computer programs.
Summary
- A proper coloring gives adjacent vertices different colors; χ(G) is the fewest colors possible.
- χ(G) ≤ 2 exactly for bipartite graphs; odd cycles need 3, and K_n needs n.
- A clique of k vertices gives \chi(G) \ge k; greedy coloring gives \chi(G) \le \Delta + 1.
- To find χ(G), match a lower bound with a coloring that uses that many colors.
- Coloring models scheduling and map problems, and every planar map needs at most 4 colors.
Previous lesson: Hamilton Paths and Circuits
Next lesson: Planar Graphs
Back to the Discrete Math Index