Algorithm Search⌘K

Proofs: Edmonds' blossom algorithm

These are the human proofs of Edmonds' blossom algorithm, at full length.

Edmonds' blossom algorithm runs in O(n^3) time full

This proof shows: time.worst.

Let GG have nn vertices and mm edges. The graph G′G' is represented as in the implementation: the adjacency lists of GG, an array base\text{base}, the labels, the tree of each vertex, the array mate\text{mate}, and parent links. Each array access and comparison costs O(1)O(1) on the word RAM.

Phases. By the termination argument of the correctness proof there are at most ⌊n/2⌋+1\lfloor n/2 \rfloor + 1 phases.

Scanning. In one phase each vertex is enqueued at most once, and when dequeued it scans its adjacency list once. The test of line L6 compares base[v]\text{base}[v] with base[w]\text{base}[w] and mate[v]\text{mate}[v] with ww, line L7 reads two labels and two tree names, and line L11 sets a constant number of entries. So the scans cost O(n+m)O(n + m) per phase, apart from the work of lines L8 and L10.

Contractions. Each contraction replaces the vertices of an odd cycle of G′G', at least three of them, by one, so the number of vertices of G′G' drops by at least 2, and there are at most n/2n/2 contractions per phase. A contraction finds the base by walking from vv to the root and from ww upwards until the first marked vertex, following mate\text{mate}, the parent links and base\text{base}: O(n)O(n) steps. Marking the two paths costs O(n)O(n), and the loop that sets base[x]←b\text{base}[x] \leftarrow b for the vertices of the blossom and enqueues the formerly inner ones visits all nn vertices once: O(n)O(n). So the contractions cost O(n2)O(n^2) per phase.

Augmentation. Line L8 follows mate\text{mate} and the links from vv and from ww to their roots; each step visits a new vertex of the path, so this costs O(n)O(n), and flipping the path costs O(n)O(n) too.

Total. One phase costs O(n+m+n2)=O(n2+m)O(n + m + n^2) = O(n^2 + m), and all phases O(n(n2+m))O(n(n^2 + m)). For a simple graph m≤n2/2m \le n^2/2, which gives O(n3)O(n^3). The space is Θ(n+m)\Theta(n + m): the adjacency lists and a constant number of arrays of length nn, plus the queue, which holds each vertex at most once per phase. ■\blacksquare

Edmonds' blossom algorithm returns a maximum matching full

This proof shows: correctness, termination.

Let G=(V,E)G = (V, E) be a finite graph and MM the matching at the start of a phase; MM does not change until line L8. Write G0=GG_0 = G, M0=MM_0 = M, and let GiG_i, MiM_i be the graph and matching after the ii-th contraction of the phase, so that Gi=Gi−1/BiG_i = G_{i-1}/B_i and Mi=Mi−1∖E(Bi)M_i = M_{i-1} \setminus E(B_i). A vertex of GiG_i is a set of vertices of GG, the set with a common value of base\text{base}.

Claim 1 (the forest). At every moment of a phase, with G′=GiG' = G_i and M′=MiM' = M_i: the labelled vertices of G′G' form an alternating forest FF with one tree per free vertex of G′G', rooted at it; every path in FF from a root to an outer vertex is M′M'-alternating, of even length, and ends with a matched edge or has no edge; each inner vertex is a single vertex of GG, with exactly one child, its partner, which is outer; and each vertex of G′G' that is a contracted set is outer and has an odd number of vertices of GG. Proof. Line L3 makes every free vertex a root and nothing else is labelled. Line L11 adds an unmatched edge from an outer vv to an unlabelled ww; ww is matched, because every free vertex is a root, and its partner is unlabelled too, because the partner of a labelled vertex is labelled (its parent or its child, or none for a root). So the tree grows by a path of two edges, unmatched then matched, and the claim is kept. In line L10, vv and ww are outer in the same tree; by the blossom page, the two tree paths to their lowest common ancestor bb and the edge vwvw form a blossom BB with base bb, an outer vertex, and stem the tree path from the root to bb. Contracting BB replaces it by one vertex β\beta, which is matched by the stem edge of bb or is the root. The tree minus the vertices of BB, with β\beta in the place of bb, is still an alternating tree: every inner vertex of BB had its parent and its child in BB, and every other child of a vertex of BB now hangs from β\beta by the same unmatched edge. β\beta is outer, and it consists of an odd number of odd sets, so it is odd. □\square

Claim 2 (lifting). Let BB be a blossom of Mi−1M_{i-1} in Gi−1G_{i-1} with base bb, whose stem starts at a free vertex, and let P′P' be an MiM_i-augmenting path in Gi=Gi−1/BG_i = G_{i-1}/B. Replacing the vertex β\beta of BB on P′P' by a suitable path in BB gives an Mi−1M_{i-1}-augmenting path in Gi−1G_{i-1}. Proof. If β∉P′\beta \notin P' there is nothing to do. Otherwise, P′P' has one edge at β\beta that is not matched and comes from an edge xyxy of Gi−1G_{i-1} with x∈Bx \in B and y∉By \notin B; and either β\beta is an end of P′P', so it is free and bb is free, or β\beta is an inner vertex of P′P', whose other edge is the matched edge ebe_b of bb. In both cases replace β\beta by the way round BB from bb to xx that has even length, which is empty if x=bx = b. This way starts at bb with an unmatched edge, because both edges of BB at bb are unmatched, and ends at xx with a matched edge, because it alternates and has even length. So at bb the matched edge ebe_b, if present, is followed by an unmatched edge, and at xx a matched edge is followed by the unmatched edge xyxy. If x≠bx \ne b, the edge xyxy is unmatched since the matched edge of xx lies in BB; if x=bx = b, xyxy is the unmatched edge of P′P'. The vertices of BB appear only in the inserted part, so the result is a path, it alternates, and its ends are the free ends of P′P', or bb in place of the free β\beta. □\square

Claim 3 (augmentation). When line L8 runs, PP is an MM-augmenting path of GG, so M△PM \triangle P is a matching with one more edge. Proof. Let G′=GkG' = G_k. The vertices vv and ww lie in outer vertices of G′G' in different trees, so by Claim 1 the tree path from the root of vv to vv and from ww to its root are even alternating paths from free vertices that end with matched edges, and they are vertex-disjoint. The edge vwvw is not matched, since a matched edge at an outer vertex goes to its parent or child in the same tree. So P′P' is an MkM_k-augmenting path of GkG_k. Applying Claim 2 for i=k,k−1,…,1i = k, k - 1, \ldots, 1 expands Bk,…,B1B_k, \ldots, B_1 in turn and gives an MM-augmenting path PP of GG; each BiB_i satisfies the hypothesis by Claim 1. By the flipping rule for augmenting paths, M△PM \triangle P is a matching of size ∣M∣+1|M| + 1. □\square

Claim 4 (the end of a failing phase). Suppose a phase ends with QQ empty and no augmentation. Then every edge xzxz of GG with xx in an outer vertex XX of G′G' has z∈Xz \in X or zz inner. Proof. A vertex of GG is enqueued when it first lies in an outer vertex of G′G': as a root in line L3, as a partner in line L11, or as a formerly inner vertex in line L10, and it stays in an outer vertex afterwards. So xx was dequeued and scanned the edge xzxz at a time when it was already outer. Consider the state of zz then. If zz was in the same vertex of G′G', it still is, since vertices of G′G' only merge. If xz∈Mxz \in M, then zz is the parent or the child of xx's vertex in the tree, or in the same vertex; a blossom that contains an inner vertex contains its child and the vertex of its parent, so zz is now inner or in the same vertex as xx. If zz was outer, line L7 or L9 applied: the first is excluded by hypothesis, and the second merged the two. If zz was unlabelled, line L11 made it inner with parent xx's vertex; if it later became outer, it did so in a blossom, which then also contains its parent's vertex, so zz is in the same vertex as xx. If zz was inner and later became outer, then zz was enqueued again and scanned the edge zxzx while xx was outer, so by the previous cases they are now in one vertex. Otherwise zz is still inner. □\square

Claim 5 (maximality). If a phase ends without augmenting, MM is a maximum matching. Proof. Let UU be the set of inner vertices, each a single vertex of GG, and let O\mathcal O be the set of outer vertices of G′G'. By Claim 4, each X∈OX \in \mathcal O is joined only to vertices of UU and to itself, and XX is connected, as a nest of contracted cycles; so each XX is a component of G−UG - U, with an odd number of vertices by Claim 1. Hence odd(G−U)≥∣O∣\text{odd}(G - U) \ge |\mathcal O|. In each tree of FF every inner vertex has exactly one child and every outer vertex except the root has an inner parent, so the tree has one more outer vertex than inner vertices, and ∣O∣−∣U∣|\mathcal O| - |U| is the number of trees, which is the number ff of free vertices of MM in GG. For any matching NN and any set UU, each odd component of G−UG - U has a vertex that is not matched by NN inside the component, so it is free or matched to UU; at most ∣U∣|U| are matched to UU, so NN leaves at least odd(G−U)−∣U∣\text{odd}(G - U) - |U| vertices free, and ∣N∣≤12(n−odd(G−U)+∣U∣)|N| \le \frac{1}{2}(n - \text{odd}(G - U) + |U|). With our UU this gives ∣N∣≤12(n−∣O∣+∣U∣)=12(n−f)=∣M∣|N| \le \frac{1}{2}(n - |\mathcal O| + |U|) = \frac{1}{2}(n - f) = |M|. □\square

Termination. Inside a phase each vertex is enqueued at most once, since it is enqueued only when it first becomes outer, so the loop of lines L4 to L11 ends. Each phase that augments raises ∣M∣|M| by one, by Claim 3, and ∣M∣≤n/2|M| \le n/2, so at most ⌊n/2⌋+1\lfloor n/2 \rfloor + 1 phases run.

Correctness. The algorithm stops only after a phase without augmentation, and then MM is maximum by Claim 5. ■\blacksquare

Back to Edmonds' blossom algorithm