Algorithm Search⌘K

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 G=(V,A)G = (V, A) be a finite directed graph with nn vertices, a root r∈Vr \in V and a real cost c(a)c(a) on each arc. Parallel arcs, self-loops and negative costs are allowed, and costs may tie. An arborescence (rooted at rr, spanning) is a set T⊆AT \subseteq A in which each vertex v≠rv \ne r has exactly one entering arc, no arc enters rr, and each vertex is reachable from rr along arcs of TT. Such a TT has n−1n - 1 arcs and no cycle.

We prove that EDMONDS (lines L1 to L10 of the page) stops, returns NONE exactly when GG has no arborescence, and otherwise returns an arborescence of least cost.

Facts used

Fact 1 (a test for arborescences). A set TT in which each v≠rv \ne r has exactly one entering arc and no arc enters rr is an arborescence if and only if TT has no cycle. Indeed, follow the entering arcs backwards from any vv: the walk either reaches rr, where it stops, or repeats a vertex, which gives a cycle. If TT has no cycle, every walk reaches rr, so vv is reachable. If TT has a cycle CC, no vertex of CC is reachable from rr, because the only arc of TT into a vertex of CC is the arc of CC, so a path from rr into CC would have to start inside CC.

Fact 2 (shifting the costs into one vertex). For a vertex v≠rv \ne r and a number yy, replace c(a)c(a) by c(a)−yc(a) - y for each arc aa entering vv. Each arborescence has exactly one arc entering vv, so the cost of every arborescence drops by exactly yy, and the set of optimal arborescences does not change.

The cycle lemma

Fix one level of the recursion. For each v≠rv \ne r let in[v]\mathrm{in}[v] be the arc chosen at line L2: an arc of least cost among the arcs (u,v)(u, v) with u≠vu \ne v. Let CC be a cycle formed by these arcs, with vertex set VCV_C; r∉VCr \notin V_C since no chosen arc enters rr.

Lemma 1. If GG has an arborescence, then it has an optimal arborescence T∗T^* with exactly one arc entering VCV_C from outside, and T∗T^* contains in[w]\mathrm{in}[w] for each w∈VCw \in V_C except the head of that arc.

Proof. By Fact 2, applied with y=c(in[v])y = c(\mathrm{in}[v]) at each v≠rv \ne r, we may assume that each chosen arc has cost 0 and every arc that is not a self-loop and does not enter rr has cost at least 0 (self-loops and arcs into rr are in no arborescence); the optimal arborescences are the same. Let TT be an optimal arborescence. In TT, take a shortest path from rr to a vertex of VCV_C; its last arc is (a,b)(a, b) with a∉VCa \notin V_C and b∈VCb \in V_C, and the path from rr to aa uses no vertex of VCV_C. Let

T∗=(T∖{arcs of T entering VC})∪{(a,b)}∪{in[w]:w∈VC,w≠b}.T^* = \bigl(T \setminus \{\text{arcs of } T \text{ entering } V_C\}\bigr) \cup \{(a, b)\} \cup \{\mathrm{in}[w] : w \in V_C, w \ne b\}.

Each v≠rv \ne r has exactly one entering arc in T∗T^*: for v∉VCv \notin V_C it is the arc of TT; for v=bv = b it is (a,b)(a, b); for the other w∈VCw \in V_C it is in[w]\mathrm{in}[w]. Each vertex is reachable from rr in T∗T^*. The path of TT from rr to aa enters only vertices outside VCV_C, so it is in T∗T^*; then (a,b)(a, b) reaches bb, and the arcs of CC other than in[b]\mathrm{in}[b] form a path from bb through all of VCV_C. For v∉VCv \notin V_C, take the path from rr to vv in TT. If it meets VCV_C, let zz be its last vertex in VCV_C; the part after zz enters only vertices outside VCV_C, so it lies in T∗T^*, and zz is reachable. If it does not meet VCV_C, the whole path lies in T∗T^*. So T∗T^* is an arborescence. The arcs added have cost 0, and the arcs removed have cost at least 0, so c(T∗)≤c(T)c(T^*) \le c(T) and T∗T^* is optimal. □\square

The contraction

Line L6 builds G′G': the vertices of VCV_C become one vertex xx, arcs with both ends in VCV_C are dropped, an arc (u,v)(u, v) with v∈VCv \in V_C and u∉VCu \notin V_C becomes (u,x)(u, x) of cost c′(u,x)=c(u,v)−c(in[v])c'(u, x) = c(u, v) - c(\mathrm{in}[v]), and every other arc keeps its ends (with xx for an end in VCV_C) and its cost. The root of G′G' is rr. Each arc of G′G' remembers the arc of GG it came from.

Call an arborescence TT of GG CC-shaped when it has exactly one arc (u,v)(u, v) entering VCV_C from outside and contains in[w]\mathrm{in}[w] for each w∈VC∖{v}w \in V_C \setminus \{v\}.

Lemma 2. The map ϕ\phi that sends a CC-shaped arborescence TT of GG to the images in G′G' of its arcs that do not have both ends in VCV_C is a bijection onto the arborescences of G′G', and

c(T)=c′(ϕ(T))+∑w∈VCc(in[w]).c(T) = c'(\phi(T)) + \sum_{w \in V_C} c(\mathrm{in}[w]).

Proof. Let TT be CC-shaped with entering arc (u,v)(u, v). The arcs of TT inside VCV_C are exactly the ∣VC∣−1|V_C| - 1 arcs in[w]\mathrm{in}[w], w≠vw \ne v, since each w∈VCw \in V_C has one entering arc and only vv gets it from outside. So ϕ(T)\phi(T) has (n−1)−(∣VC∣−1)=n′−1(n - 1) - (|V_C| - 1) = n' - 1 arcs, where n′=n−∣VC∣+1n' = n - |V_C| + 1. Each vertex of G′G' other than rr has exactly one entering arc in ϕ(T)\phi(T): xx has the image of (u,v)(u, v), and other vertices keep their arc. Contracting a set of vertices maps a path of TT to a walk of ϕ(T)\phi(T), so every vertex of G′G' is reachable from rr, and ϕ(T)\phi(T) is an arborescence.

Conversely, let T′T' be an arborescence of G′G'. Its arc into xx comes from an arc (u,v)(u, v) of GG with v∈VCv \in V_C; let ψ(T′)\psi(T') be the set of the original arcs of T′T' together with in[w]\mathrm{in}[w] for w∈VC∖{v}w \in V_C \setminus \{v\}. Each v′≠rv' \ne r of GG has exactly one entering arc in ψ(T′)\psi(T'). A path from rr to a vertex in T′T' lifts to GG: each time it passes through xx it enters VCV_C at vv and can leave from any vertex of VCV_C, all of which vv reaches along C∖{in[v]}C \setminus \{\mathrm{in}[v]\}. So ψ(T′)\psi(T') is a CC-shaped arborescence, and ϕ\phi and ψ\psi are inverse to each other.

For the costs: arcs not entering VCV_C keep their cost, the arc (u,v)(u, v) has c(u,v)=c′(u,x)+c(in[v])c(u, v) = c'(u, x) + c(\mathrm{in}[v]), and the arcs inside VCV_C cost ∑w≠vc(in[w])\sum_{w \ne v} c(\mathrm{in}[w]). Adding these gives the formula. □\square

Lemma 3. GG has an arborescence if and only if G′G' has one, and if T′T' is an optimal arborescence of G′G', then ψ(T′)\psi(T') is an optimal arborescence of GG.

Proof. If GG has an arborescence, Lemma 1 gives a CC-shaped one, and ϕ\phi maps it to an arborescence of G′G'. If G′G' has one, ψ\psi maps it to an arborescence of GG. Now let T′T' be optimal for G′G' and let T∗T^* be the CC-shaped optimal arborescence of Lemma 1. By Lemma 2, with K=∑w∈VCc(in[w])K = \sum_{w \in V_C} c(\mathrm{in}[w]),

c(ψ(T′))=c′(T′)+K≤c′(ϕ(T∗))+K=c(T∗),c(\psi(T')) = c'(T') + K \le c'(\phi(T^*)) + K = c(T^*),

so ψ(T′)\psi(T') is optimal. □\square

The theorem

Theorem. On every input, EDMONDS stops. It returns NONE if and only if GG has no arborescence rooted at rr, and otherwise it returns a minimum-cost arborescence.

Proof. By induction on nn. Each call either returns at line L3 or L4, or recurses on G′G', which has n−∣VC∣+1≤n−1n - |V_C| + 1 \le n - 1 vertices, because a cycle of chosen arcs has at least two vertices (self-loops are never chosen). So there are at most nn nested calls, and the algorithm stops.

Return at line L3. Some v≠rv \ne r has no entering arc other than self-loops. Then no arborescence exists, and NONE is correct.

Return at line L4. Each v≠rv \ne r has exactly one chosen arc, no chosen arc enters rr, and the chosen arcs form no cycle, so by Fact 1 they form an arborescence BB. Every arborescence TT has one arc into each v≠rv \ne r, which costs at least c(in[v])c(\mathrm{in}[v]), so c(T)≥c(B)c(T) \ge c(B), and BB is optimal.

Recursion at lines L5 to L10. By the induction hypothesis the recursive call returns NONE exactly when G′G' has no arborescence, which by Lemma 3 is exactly when GG has none; line L8 then returns NONE correctly. Otherwise it returns an optimal arborescence T′T' of G′G'. Lines L9 and L10 find the arc (u,v)(u, v) of GG behind the arc of T′T' into xx and return the arcs behind T′T' together with C∖{in[v]}C \setminus \{\mathrm{in}[v]\}, which is ψ(T′)\psi(T'). By Lemma 3 it is an optimal arborescence of GG. ■\blacksquare

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.

Back to Edmonds' algorithm for minimum arborescence