Proofs: Edmonds' algorithm for minimum arborescence
These are the human proofs of Edmonds' algorithm for minimum arborescence, at full length.
Edmonds' algorithm returns a minimum arborescence, or NONE exactly when no arborescence exists full
This proof shows: correctness, termination.
Let be a finite directed graph with vertices, a root and a real cost on each arc. Parallel arcs, self-loops and negative costs are allowed, and costs may tie. An arborescence (rooted at , spanning) is a set in which each vertex has exactly one entering arc, no arc enters , and each vertex is reachable from along arcs of . Such a has arcs and no cycle.
We prove that EDMONDS (lines L1 to L10 of the page) stops, returns NONE exactly when has no arborescence, and otherwise returns an arborescence of least cost.
Facts used
Fact 1 (a test for arborescences). A set in which each has exactly one entering arc and no arc enters is an arborescence if and only if has no cycle. Indeed, follow the entering arcs backwards from any : the walk either reaches , where it stops, or repeats a vertex, which gives a cycle. If has no cycle, every walk reaches , so is reachable. If has a cycle , no vertex of is reachable from , because the only arc of into a vertex of is the arc of , so a path from into would have to start inside .
Fact 2 (shifting the costs into one vertex). For a vertex and a number , replace by for each arc entering . Each arborescence has exactly one arc entering , so the cost of every arborescence drops by exactly , and the set of optimal arborescences does not change.
The cycle lemma
Fix one level of the recursion. For each let be the arc chosen at line L2: an arc of least cost among the arcs with . Let be a cycle formed by these arcs, with vertex set ; since no chosen arc enters .
Lemma 1. If has an arborescence, then it has an optimal arborescence with exactly one arc entering from outside, and contains for each except the head of that arc.
Proof. By Fact 2, applied with at each , we may assume that each chosen arc has cost 0 and every arc that is not a self-loop and does not enter has cost at least 0 (self-loops and arcs into are in no arborescence); the optimal arborescences are the same. Let be an optimal arborescence. In , take a shortest path from to a vertex of ; its last arc is with and , and the path from to uses no vertex of . Let
Each has exactly one entering arc in : for it is the arc of ; for it is ; for the other it is . Each vertex is reachable from in . The path of from to enters only vertices outside , so it is in ; then reaches , and the arcs of other than form a path from through all of . For , take the path from to in . If it meets , let be its last vertex in ; the part after enters only vertices outside , so it lies in , and is reachable. If it does not meet , the whole path lies in . So is an arborescence. The arcs added have cost 0, and the arcs removed have cost at least 0, so and is optimal.
The contraction
Line L6 builds : the vertices of become one vertex , arcs with both ends in are dropped, an arc with and becomes of cost , and every other arc keeps its ends (with for an end in ) and its cost. The root of is . Each arc of remembers the arc of it came from.
Call an arborescence of -shaped when it has exactly one arc entering from outside and contains for each .
Lemma 2. The map that sends a -shaped arborescence of to the images in of its arcs that do not have both ends in is a bijection onto the arborescences of , and
Proof. Let be -shaped with entering arc . The arcs of inside are exactly the arcs , , since each has one entering arc and only gets it from outside. So has arcs, where . Each vertex of other than has exactly one entering arc in : has the image of , and other vertices keep their arc. Contracting a set of vertices maps a path of to a walk of , so every vertex of is reachable from , and is an arborescence.
Conversely, let be an arborescence of . Its arc into comes from an arc of with ; let be the set of the original arcs of together with for . Each of has exactly one entering arc in . A path from to a vertex in lifts to : each time it passes through it enters at and can leave from any vertex of , all of which reaches along . So is a -shaped arborescence, and and are inverse to each other.
For the costs: arcs not entering keep their cost, the arc has , and the arcs inside cost . Adding these gives the formula.
Lemma 3. has an arborescence if and only if has one, and if is an optimal arborescence of , then is an optimal arborescence of .
Proof. If has an arborescence, Lemma 1 gives a -shaped one, and maps it to an arborescence of . If has one, maps it to an arborescence of . Now let be optimal for and let be the -shaped optimal arborescence of Lemma 1. By Lemma 2, with ,
so is optimal.
The theorem
Theorem. On every input, EDMONDS stops. It returns NONE if and only if has no arborescence rooted at , and otherwise it returns a minimum-cost arborescence.
Proof. By induction on . Each call either returns at line L3 or L4, or recurses on , which has vertices, because a cycle of chosen arcs has at least two vertices (self-loops are never chosen). So there are at most nested calls, and the algorithm stops.
Return at line L3. Some has no entering arc other than self-loops. Then no arborescence exists, and NONE is correct.
Return at line L4. Each has exactly one chosen arc, no chosen arc enters , and the chosen arcs form no cycle, so by Fact 1 they form an arborescence . Every arborescence has one arc into each , which costs at least , so , and is optimal.
Recursion at lines L5 to L10. By the induction hypothesis the recursive call returns NONE exactly when has no arborescence, which by Lemma 3 is exactly when has none; line L8 then returns NONE correctly. Otherwise it returns an optimal arborescence of . Lines L9 and L10 find the arc of behind the arc of into and return the arcs behind together with , which is . By Lemma 3 it is an optimal arborescence of .
Ties. Nothing above uses distinct costs: Lemma 1 works with any choice of cheapest arcs at line L2, so breaking ties by index is correct. With ties the optimum need not be unique, and the algorithm returns one optimum.