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 have vertices and edges. The graph is represented as in the implementation: the adjacency lists of , an array , the labels, the tree of each vertex, the array , and parent links. Each array access and comparison costs on the word RAM.
Phases. By the termination argument of the correctness proof there are at most 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 with and with , line L7 reads two labels and two tree names, and line L11 sets a constant number of entries. So the scans cost per phase, apart from the work of lines L8 and L10.
Contractions. Each contraction replaces the vertices of an odd cycle of , at least three of them, by one, so the number of vertices of drops by at least 2, and there are at most contractions per phase. A contraction finds the base by walking from to the root and from upwards until the first marked vertex, following , the parent links and : steps. Marking the two paths costs , and the loop that sets for the vertices of the blossom and enqueues the formerly inner ones visits all vertices once: . So the contractions cost per phase.
Augmentation. Line L8 follows and the links from and from to their roots; each step visits a new vertex of the path, so this costs , and flipping the path costs too.
Total. One phase costs , and all phases . For a simple graph , which gives . The space is : the adjacency lists and a constant number of arrays of length , plus the queue, which holds each vertex at most once per phase.
Edmonds' blossom algorithm returns a maximum matching full
This proof shows: correctness, termination.
Let be a finite graph and the matching at the start of a phase; does not change until line L8. Write , , and let , be the graph and matching after the -th contraction of the phase, so that and . A vertex of is a set of vertices of , the set with a common value of .
Claim 1 (the forest). At every moment of a phase, with and : the labelled vertices of form an alternating forest with one tree per free vertex of , rooted at it; every path in from a root to an outer vertex is -alternating, of even length, and ends with a matched edge or has no edge; each inner vertex is a single vertex of , with exactly one child, its partner, which is outer; and each vertex of that is a contracted set is outer and has an odd number of vertices of . Proof. Line L3 makes every free vertex a root and nothing else is labelled. Line L11 adds an unmatched edge from an outer to an unlabelled ; 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, and are outer in the same tree; by the blossom page, the two tree paths to their lowest common ancestor and the edge form a blossom with base , an outer vertex, and stem the tree path from the root to . Contracting replaces it by one vertex , which is matched by the stem edge of or is the root. The tree minus the vertices of , with in the place of , is still an alternating tree: every inner vertex of had its parent and its child in , and every other child of a vertex of now hangs from by the same unmatched edge. is outer, and it consists of an odd number of odd sets, so it is odd.
Claim 2 (lifting). Let be a blossom of in with base , whose stem starts at a free vertex, and let be an -augmenting path in . Replacing the vertex of on by a suitable path in gives an -augmenting path in . Proof. If there is nothing to do. Otherwise, has one edge at that is not matched and comes from an edge of with and ; and either is an end of , so it is free and is free, or is an inner vertex of , whose other edge is the matched edge of . In both cases replace by the way round from to that has even length, which is empty if . This way starts at with an unmatched edge, because both edges of at are unmatched, and ends at with a matched edge, because it alternates and has even length. So at the matched edge , if present, is followed by an unmatched edge, and at a matched edge is followed by the unmatched edge . If , the edge is unmatched since the matched edge of lies in ; if , is the unmatched edge of . The vertices of appear only in the inserted part, so the result is a path, it alternates, and its ends are the free ends of , or in place of the free .
Claim 3 (augmentation). When line L8 runs, is an -augmenting path of , so is a matching with one more edge. Proof. Let . The vertices and lie in outer vertices of in different trees, so by Claim 1 the tree path from the root of to and from to its root are even alternating paths from free vertices that end with matched edges, and they are vertex-disjoint. The edge is not matched, since a matched edge at an outer vertex goes to its parent or child in the same tree. So is an -augmenting path of . Applying Claim 2 for expands in turn and gives an -augmenting path of ; each satisfies the hypothesis by Claim 1. By the flipping rule for augmenting paths, is a matching of size .
Claim 4 (the end of a failing phase). Suppose a phase ends with empty and no augmentation. Then every edge of with in an outer vertex of has or inner. Proof. A vertex of is enqueued when it first lies in an outer vertex of : 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 was dequeued and scanned the edge at a time when it was already outer. Consider the state of then. If was in the same vertex of , it still is, since vertices of only merge. If , then is the parent or the child of '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 is now inner or in the same vertex as . If was outer, line L7 or L9 applied: the first is excluded by hypothesis, and the second merged the two. If was unlabelled, line L11 made it inner with parent 's vertex; if it later became outer, it did so in a blossom, which then also contains its parent's vertex, so is in the same vertex as . If was inner and later became outer, then was enqueued again and scanned the edge while was outer, so by the previous cases they are now in one vertex. Otherwise is still inner.
Claim 5 (maximality). If a phase ends without augmenting, is a maximum matching. Proof. Let be the set of inner vertices, each a single vertex of , and let be the set of outer vertices of . By Claim 4, each is joined only to vertices of and to itself, and is connected, as a nest of contracted cycles; so each is a component of , with an odd number of vertices by Claim 1. Hence . In each tree of 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 is the number of trees, which is the number of free vertices of in . For any matching and any set , each odd component of has a vertex that is not matched by inside the component, so it is free or matched to ; at most are matched to , so leaves at least vertices free, and . With our this gives .
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 by one, by Claim 3, and , so at most phases run.
Correctness. The algorithm stops only after a phase without augmentation, and then is maximum by Claim 5.