Algorithm Search⌘K

Proofs: Welsh-Powell algorithm

These are the human proofs of Welsh-Powell algorithm, at full length.

Welsh-Powell gives the greedy coloring of the degree order full

This proof shows: correctness, termination.

Let σ=(σ1,…,σn)\sigma = (\sigma_1, \ldots, \sigma_n) be the order of line L1. For a vertex vv write pos(v)\mathrm{pos}(v) for its position in σ\sigma, and call a neighbor ww of vv earlier if pos(w)<pos(v)\mathrm{pos}(w) < \mathrm{pos}(v). Define the greedy color g(v)g(v) by induction along σ\sigma: g(σi)g(\sigma_i) is the smallest positive integer that is not g(w)g(w) for an earlier neighbor ww of σi\sigma_i. The map gg is a proper coloring, because for an edge {u,v}\{u, v\} with uu earlier, g(v)≠g(u)g(v) \ne g(u) by the choice of g(v)g(v).

Termination. The loops of lines L4 and L7 are for loops with fixed bounds, and line L11 scans a finite list. So the algorithm stops after at most n2+2mn^2 + 2m steps of the inner loops.

Claim. When the algorithm returns, c(v)=g(v)c(v) = g(v) for each vertex vv.

We prove by induction on k≥0k \ge 0:

(Pk_k) After the pass with color kk ends (for k=0k = 0: before the first pass), each vertex vv with g(v)≤kg(v) \le k has c(v)=g(v)c(v) = g(v), and each vertex with g(v)>kg(v) > k has c(v)=0c(v) = 0.

Base. Before the first pass, c(v)=0c(v) = 0 for all vv (line L2), and no vertex has g(v)≤0g(v) \le 0. So (P0_0) holds.

Step. Assume (Pk−1_{k-1}) and that pass kk starts at position ii, that is, σi\sigma_i is the first vertex with c=0c = 0. By (Pk−1_{k-1}), the vertices with c=0c = 0 are exactly those with g≥kg \ge k. In pass kk, line L11 sets blocked[w]=k\mathrm{blocked}[w] = k only for neighbors of vertices that get color kk in this pass. No earlier pass wrote the value kk, because pass jj writes only the value jj. So during pass kk, blocked[v]=k\mathrm{blocked}[v] = k holds exactly when some neighbor of vv got color kk earlier in this pass.

We show by induction on j=i,i+1,…,nj = i, i + 1, \ldots, n that when position jj is scanned, σj\sigma_j gets color kk if and only if g(σj)=kg(\sigma_j) = k. Let v=σjv = \sigma_j.

  • If c(v)≠0c(v) \ne 0 before the scan, then g(v)≤k−1g(v) \le k - 1 by (Pk−1_{k-1}), and line L9 does not color vv. Both sides of the equivalence are false.
  • Otherwise g(v)≥kg(v) \ge k. Every vertex before position ii has c≠0c \ne 0, and every vertex scanned so far in this pass comes before vv in σ\sigma. So the neighbors of vv with color kk at this moment are earlier neighbors of vv, and by the inner induction hypothesis they are exactly the earlier neighbors ww of vv with g(w)=kg(w) = k (a later neighbor has not been scanned yet, so it has no color kk). Hence line L9 colors vv if and only if no earlier neighbor of vv has greedy color kk.
  • Since g(v)≥kg(v) \ge k, the colors 1,…,k−11, \ldots, k - 1 all occur on earlier neighbors of vv (by the definition of gg as the smallest free value). So g(v)=kg(v) = k if and only if no earlier neighbor has greedy color kk. This matches the condition of the previous point.

So after pass kk, the vertices with c=kc = k are exactly those with g=kg = k, the vertices with g<kg < k keep their colors, and the vertices with g>kg > k still have c=0c = 0. This is (Pk_k).

End. Each pass colors σi\sigma_i, since blocked[σi]≠k\mathrm{blocked}[\sigma_i] \ne k at the start of the pass. So each pass colors at least one new vertex, there are at most nn passes, and the loop of line L4 ends with every vertex colored. If the last pass has color KK, then (PK_K) and c(v)≠0c(v) \ne 0 for all vv give c=gc = g. Since gg is a proper coloring, so is cc. The colors used are 1,…,K1, \ldots, K, each one by at least one vertex.

The bound. The vertex σi\sigma_i has at most i−1i - 1 earlier neighbors, and at most d(σi)d(\sigma_i) neighbors in all. Its greedy color exceeds the number of distinct colors among its earlier neighbors by at most one, so c(σi)=g(σi)≤min⁡(d(σi),i−1)+1c(\sigma_i) = g(\sigma_i) \le \min(d(\sigma_i), i - 1) + 1. With di=d(σi)d_i = d(\sigma_i), this gives K≤max⁡imin⁡(di+1,i)K \le \max_i \min(d_i + 1, i). ■\blacksquare

Back to Welsh-Powell algorithm