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 be the order of line L1. For a vertex write for its position in , and call a neighbor of earlier if . Define the greedy color by induction along : is the smallest positive integer that is not for an earlier neighbor of . The map is a proper coloring, because for an edge with earlier, by the choice of .
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 steps of the inner loops.
Claim. When the algorithm returns, for each vertex .
We prove by induction on :
(P) After the pass with color ends (for : before the first pass), each vertex with has , and each vertex with has .
Base. Before the first pass, for all (line L2), and no vertex has . So (P) holds.
Step. Assume (P) and that pass starts at position , that is, is the first vertex with . By (P), the vertices with are exactly those with . In pass , line L11 sets only for neighbors of vertices that get color in this pass. No earlier pass wrote the value , because pass writes only the value . So during pass , holds exactly when some neighbor of got color earlier in this pass.
We show by induction on that when position is scanned, gets color if and only if . Let .
- If before the scan, then by (P), and line L9 does not color . Both sides of the equivalence are false.
- Otherwise . Every vertex before position has , and every vertex scanned so far in this pass comes before in . So the neighbors of with color at this moment are earlier neighbors of , and by the inner induction hypothesis they are exactly the earlier neighbors of with (a later neighbor has not been scanned yet, so it has no color ). Hence line L9 colors if and only if no earlier neighbor of has greedy color .
- Since , the colors all occur on earlier neighbors of (by the definition of as the smallest free value). So if and only if no earlier neighbor has greedy color . This matches the condition of the previous point.
So after pass , the vertices with are exactly those with , the vertices with keep their colors, and the vertices with still have . This is (P).
End. Each pass colors , since at the start of the pass. So each pass colors at least one new vertex, there are at most passes, and the loop of line L4 ends with every vertex colored. If the last pass has color , then (P) and for all give . Since is a proper coloring, so is . The colors used are , each one by at least one vertex.
The bound. The vertex has at most earlier neighbors, and at most neighbors in all. Its greedy color exceeds the number of distinct colors among its earlier neighbors by at most one, so . With , this gives .