Mathwords logoMathwords

k-Coloring — Definition, Formula & Examples

A k-coloring of a graph is an assignment of at most kk distinct colors to the graph's vertices such that no two vertices connected by an edge receive the same color. If a valid k-coloring exists, the graph is called k-colorable.

Given a graph G=(V,E)G = (V, E) and a positive integer kk, a proper kk-coloring is a function c:V{1,2,,k}c: V \to \{1, 2, \ldots, k\} such that c(u)c(v)c(u) \neq c(v) for every edge {u,v}E\{u, v\} \in E. The chromatic number χ(G)\chi(G) is the smallest kk for which a proper kk-coloring of GG exists.

How It Works

To find a k-coloring, you try to label each vertex with one of kk colors while ensuring every pair of adjacent vertices gets different colors. Start by picking any vertex and assigning it color 1. Move to an adjacent vertex and assign the lowest-numbered color that does not conflict with its already-colored neighbors. Repeat until all vertices are colored or you discover that kk colors are insufficient. If you succeed, the graph is kk-colorable; if not, you need more colors. The minimum kk that works is the chromatic number χ(G)\chi(G).

Worked Example

Problem: Determine whether the cycle graph C4C_4 (a square with vertices v1,v2,v3,v4v_1, v_2, v_3, v_4 and edges forming a cycle) is 2-colorable.
Step 1: Assign color 1 to v1v_1. Its neighbor v2v_2 must differ, so assign color 2 to v2v_2.
c(v1)=1,c(v2)=2c(v_1) = 1,\quad c(v_2) = 2
Step 2: v3v_3 is adjacent to v2v_2 (color 2), so assign color 1 to v3v_3. Then v4v_4 is adjacent to both v3v_3 (color 1) and v1v_1 (color 1), so assign color 2 to v4v_4.
c(v3)=1,c(v4)=2c(v_3) = 1,\quad c(v_4) = 2
Step 3: Check all edges: (v1,v2)(v_1,v_2): 121 \neq 2, (v2,v3)(v_2,v_3): 212 \neq 1, (v3,v4)(v_3,v_4): 121 \neq 2, (v4,v1)(v_4,v_1): 212 \neq 1. Every edge has differently colored endpoints.
Answer: Yes, C4C_4 is 2-colorable. Its chromatic number is χ(C4)=2\chi(C_4) = 2.

Why It Matters

Graph coloring appears directly in scheduling problems (assigning time slots so conflicting events don't overlap), register allocation in compilers, and map coloring. The Four Color Theorem — every planar graph is 4-colorable — is one of the most famous results in mathematics, and understanding k-colorings is the foundation for studying it.

Common Mistakes

Mistake: Confusing k-colorable with requiring exactly k colors.
Correction: A k-coloring uses at most k colors. A graph that is 3-colorable is automatically 4-colorable, 5-colorable, and so on. The chromatic number χ(G)\chi(G) is the minimum k needed.