Algorithm Search⌘K

Proofs: Vizing's algorithm

These are the human proofs of Vizing's algorithm, at full length.

Each step of Misra-Gries colors one more edge and keeps the coloring proper full

This proof shows: correctness, termination.

Let k=Δ+1k = \Delta + 1. A partial edge coloring is proper when two colored edges with a common end have different colors. A color is free at xx when no colored edge at xx has it. Every vertex has at most Δ<k\Delta < k edges, so it always has a free color.

We show: if before a turn of line L1 the colored edges form a proper partial coloring and uvuv is uncolored, then after the turn the same holds with uvuv colored and no colored edge uncolored. The loop runs once per edge, so it terminates, and by induction the final coloring is proper with all edges colored and colors in {1,…,k}\{1, \ldots, k\}.

Rotation. Let (f0,…,fj)(f_0, \ldots, f_j) be a fan at uu. After the rotation, ufiu f_i has the old color of ufi+1u f_{i+1} for i<ji < j, and ufju f_j is uncolored. At uu, the edges uf0,…,ufj−1u f_0, \ldots, u f_{j-1} now carry the old colors of uf1,…,ufju f_1, \ldots, u f_j, and ufju f_j carries none, so the set of colors at uu is unchanged and no color repeats. At fif_i for i<ji < j, the new color of ufiu f_i was free at fif_i by the fan condition, and fif_i has no other changed edge. So the result is proper.

Swap. For colors c≠dc \ne d, the edges colored cc or dd form vertex-disjoint paths and cycles. Swapping cc and dd on one whole component keeps the coloring proper: inside the component, consecutive edges still differ, and at an end xx of a path, the color that the end edge gets was free at xx, since xx is an end. If cc is free at uu, then uu meets at most one edge of color cc or dd, so uu is an end of its component, which is the cd-path at uu (empty if dd is also free at uu). If c=dc = d, then dd is free at uu and the path is empty.

Line L4 frees dd at uu. If dd was free at uu, nothing changes. Otherwise the first edge of the path is the edge at uu of color dd, which becomes cc, and cc was free at uu. So after line L4, dd is free at uu.

Line L5 succeeds. Let F=(f0,…,ft)F = (f_0, \ldots, f_t) be the maximal fan of line L2, cc free at uu and dd free at ftf_t, all before line L4. It suffices to exhibit one jj such that, after line L4, (f0,…,fj)(f_0, \ldots, f_j) is a fan and dd is free at fjf_j; the first such jj also qualifies.

  • dd was free at uu. The path is empty, FF is unchanged and dd is free at ftf_t. Take j=tj = t.
  • dd was not free at uu. Let uxux be the edge of color dd. Since dd is free at ftf_t, the vertex xx would extend FF if x∉Fx \notin F, and x≠f0x \ne f_0 because uf0u f_0 is uncolored. So x=fs+1x = f_{s+1} with 0≤s<t0 \le s < t, and dd is free at fsf_s by the fan condition. No edge ufiu f_i with i≠s+1i \ne s + 1 has color cc or dd, as cc is free at uu and dd is used at uu only by ufs+1u f_{s+1}. The swap changes only colors cc and dd, so for i≠s+1i \ne s + 1, the edge ufiu f_i keeps its color, and that color stays free or not free at each vertex as before. Let PP be the cd-path at uu; it starts with the edge ufs+1u f_{s+1}.
    • PP does not end at fsf_s. Since dd is free at fsf_s, the vertex fsf_s meets at most one edge of PP's colors, so if it were on PP it would be an end; the ends are uu and some vertex other than fsf_s. So fs∉Pf_s \notin P, and dd stays free at fsf_s. The conditions for (f0,…,fs)(f_0, \ldots, f_s) involve only the edges uf1,…,ufsu f_1, \ldots, u f_s, which keep their colors, so it is still a fan. Take j=sj = s.
    • PP ends at fsf_s. The last edge of PP at fsf_s had color cc, because dd was free there, so after the swap cc is free at fsf_s, and ufs+1u f_{s+1} now has color cc. So the condition for fs+1f_{s+1} holds again, and the conditions for the other indices are unchanged: FF is still a fan. The vertex ftf_t is not on PP: it would have to be an end, since dd is free at ftf_t, and the ends are uu and fs≠ftf_s \ne f_t. So dd is still free at ftf_t. Take j=tj = t.

Lines L6 and L7. Let w=fjw = f_j be the vertex found at line L5. Rotating the fan (f0,…,w)(f_0, \ldots, w) keeps the coloring proper, colors uf0=uvu f_0 = uv, and uncolors uwuw. The rotation does not add any color at uu, and at ww it only removes the color of uwuw, so dd is still free at both uu and ww. Line L7 colors uwuw with dd, which keeps the coloring proper. All edges colored before the turn are colored after it, and uvuv is now colored too. ∎

Back to Vizing's algorithm