Algorithm Search⌘K

Proofs: Greedy coloring

These are the human proofs of Greedy coloring, at full length.

Greedy coloring returns a proper coloring with at most Δ + 1 colors full

This proof shows: correctness, termination.

Let G=(V,E)G = (V, E) be a simple undirected graph and σ=(v1,…,vn)\sigma = (v_1, \ldots, v_n) an order of VV. For a vertex v=viv = v_i, let N−(v)={w:{v,w}∈E, w=vj with j<i}N^-(v) = \{ w : \{v, w\} \in E,\ w = v_j \text{ with } j < i \} be the set of its earlier neighbors, and d−(v)=∣N−(v)∣d^-(v) = |N^-(v)|. The array used\mathrm{used} has the indices 11 to n+1n + 1 and starts with a value that is not a vertex.

Claim. GREEDY-COLORING(G,σ)(G, \sigma) stops. The returned cc satisfies 1≤c(v)≤d−(v)+11 \le c(v) \le d^-(v) + 1 for each vv, and c(u)≠c(v)c(u) \ne c(v) for each edge {u,v}\{u, v\}.

Invariant. At the start of iteration ii of the loop of line L2:

(G) c(vj)≥1c(v_j) \ge 1 for each j<ij < i, c(vj)=0c(v_j) = 0 for each j≥ij \ge i, and no edge joins two vertices vj,vlv_j, v_l with j,l<ij, l < i and c(vj)=c(vl)c(v_j) = c(v_l).

Initialization. For i=1i = 1, line L1 set all colors to 0, and there is no pair with j,l<1j, l < 1.

Maintenance. Fix iteration ii and v=viv = v_i. By (G), the neighbors ww of vv with c(w)>0c(w) > 0 are exactly the vertices of N−(v)N^-(v). Line L4 writes the stamp vv at the index c(w)c(w) for each of them. No other entry holds the stamp vv: an entry gets a stamp only in line L4, and the iterations before ii wrote other vertices as stamps, because each vertex appears once in σ\sigma. So after line L4,

{k:used[k]=v}=C(v):={c(w):w∈N−(v)}.\{ k : \mathrm{used}[k] = v \} = C(v) := \{ c(w) : w \in N^-(v) \}.

The set C(v)C(v) has at most d−(v)d^-(v) elements. So among the d−(v)+1d^-(v) + 1 values 1,…,d−(v)+11, \ldots, d^-(v) + 1, at least one is not in C(v)C(v). As d−(v)+1≤nd^-(v) + 1 \le n, these values are valid indices. The loop of line L6 starts at k=1k = 1, adds 1 in each step, and stops at the first k∉C(v)k \notin C(v). So it stops after at most d−(v)+1d^-(v) + 1 tests, with 1≤k≤d−(v)+11 \le k \le d^-(v) + 1 and k∉C(v)k \notin C(v). Line L7 sets c(v)=kc(v) = k.

Now vv has a color of at least 1, and the vertices vi+1,…,vnv_{i+1}, \ldots, v_n are still at 0. A new edge between two colored vertices is an edge {v,w}\{v, w\} with w∈N−(v)w \in N^-(v), and c(w)∈C(v)c(w) \in C(v) while c(v)∉C(v)c(v) \notin C(v), so c(v)≠c(w)c(v) \ne c(w). Edges between earlier vertices keep their colors, which differ by (G). So (G) holds at the start of iteration i+1i + 1.

Termination. The loop of line L2 runs nn times, and each loop of line L6 runs at most d−(v)+1d^-(v) + 1 times, as shown. When the loop of line L2 ends, (G) with i=n+1i = n + 1 says that each vertex has a color of at least 1 and that each edge joins two vertices of different colors. The bound c(v)≤d−(v)+1c(v) \le d^-(v) + 1 was shown in the maintenance step, and d−(v)≤deg⁡(v)≤Δd^-(v) \le \deg(v) \le \Delta. ■\blacksquare

Back to Greedy coloring