Algorithm Search⌘K

Proofs: Path cover by bipartite matching

These are the human proofs of Path cover by bipartite matching, at full length.

The matching on the split graph gives a minimum path cover of a DAG full

This proof shows: correctness, termination.

Let G=(V,A)G = (V, A) be a directed acyclic graph with nn vertices, parallel arcs allowed. The split graph HH has left vertices uoutu^{\text{out}}, right vertices vinv^{\text{in}}, and an edge uoutvinu^{\text{out}} v^{\text{in}} for each arc u→vu \to v. Since GG has no self-loop, no edge of HH joins the two copies of one vertex. A matching is a set of edges of HH with no common end. An augmenting path for a matching MM is a path in HH whose edges alternate between non-matched and matched, and whose two end vertices are not covered by MM.

Lemma 1 (covers and matchings). For every matching MM of HH, the arcs S(M)={u→v:uoutvin∈M}S(M) = \{u \to v : u^{\text{out}} v^{\text{in}} \in M\} form vertex-disjoint paths that cover VV, and there are exactly n−∣M∣n - |M| of them. Conversely, every cover of VV by pp vertex-disjoint paths gives a matching of size n−pn - p. Hence the least number of paths is n−ν(H)n - \nu(H), where ν(H)\nu(H) is the size of a maximum matching.

Proof. In S(M)S(M) every vertex has at most one outgoing arc, since uoutu^{\text{out}} is matched at most once, and at most one incoming arc, since vinv^{\text{in}} is matched at most once. A graph on VV with in-degrees and out-degrees at most 1 is a union of vertex-disjoint paths and cycles, and S(M)⊆AS(M) \subseteq A has no cycle. Each vertex is on exactly one of these paths (possibly a path of one vertex). A path with kk vertices has k−1k - 1 arcs, so summing over the paths, ∣S(M)∣=n−p|S(M)| = n - p, and ∣S(M)∣=∣M∣|S(M)| = |M|. Conversely, for a cover by pp disjoint paths, take the edges uoutvinu^{\text{out}} v^{\text{in}} for consecutive vertices u,vu, v of a path: each vertex has at most one successor and one predecessor, so this is a matching, of size n−pn - p. □\square

Lines L12 and L13 output exactly the paths of S(M)S(M): a path starts at a vertex ss with no predecessor, matchR[s]=NIL\mathrm{matchR}[s] = \mathrm{NIL}, and matchL\mathrm{matchL} follows its arcs. By Lemma 1 every vertex is on one of them. It remains to show that the final MM is maximum.

Lemma 2 (Berge). If a matching MM is not maximum, it has an augmenting path.

Proof. Let M∗M^* be a larger matching. In the symmetric difference M⊕M∗M \oplus M^* every vertex has degree at most 2, so its components are paths and even cycles whose edges alternate between MM and M∗M^*. Some component has more edges of M∗M^* than of MM; it is a path that starts and ends with an M∗M^* edge, and its ends are not covered by MM. It is an augmenting path for MM. □\square

In the bipartite graph HH an augmenting path has odd length, so it has one end on each side; call its left end its start.

Lemma 3 (one search). Let MM be the matching before the search from root rr (lines L4 to L11), with routr^{\text{out}} not covered. The search ends; if an augmenting path starting at routr^{\text{out}} exists, it finds one and line L10 replaces MM by M⊕PM \oplus P, a matching with one more edge; otherwise MM does not change.

Proof. Invariant: the stack is x1=r,x2,…,xkx_1 = r, x_2, \ldots, x_k, the list via\mathrm{via} is y1,…,yk−1y_1, \ldots, y_{k-1} (or y1,…,yky_1, \ldots, y_k just after line L8 appends), xioutyiinx_i^{\text{out}} y_i^{\text{in}} is an edge not in MM, and yiinxi+1outy_i^{\text{in}} x_{i+1}^{\text{out}} is in MM. So rout,y1in,x2out,…r^{\text{out}}, y_1^{\text{in}}, x_2^{\text{out}}, \ldots is an alternating path. Line L8 appends vv adjacent to the top xkx_k, line L11 pushes matchR[v]\mathrm{matchR}[v], and line L7 pops a frame together with the via\mathrm{via} entry that led to it; each keeps the invariant. The right vertices on the path are distinct because each is marked visited when appended, and so the left vertices xi+1=matchR[yi]x_{i+1} = \mathrm{matchR}[y_i] are distinct, and different from rr, which is not covered.

Termination. Each iteration either reads a new list entry through ptr\mathrm{ptr} or pops a frame. A left vertex is pushed only as matchR[v]\mathrm{matchR}[v] for a newly visited vv, so at most nn pushes happen, and the lists are finite.

Success. At line L9, v=ykv = y_k is not covered, so the alternating path from routr^{\text{out}} to ykiny_k^{\text{in}} is augmenting. Line L10 matches xix_i with yiy_i for all ii, which removes the matched edges yixi+1y_i x_{i+1} (each xi+1x_{i+1} is rematched to yi+1y_{i+1} and each yiy_i to xix_i) and adds the others: this is M⊕PM \oplus P, a matching of size ∣M∣+1|M| + 1.

Failure. Suppose the stack empties. Let YY be the visited right vertices. Every y∈Yy \in Y is covered (otherwise line L9 succeeds), its partner matchR[y]\mathrm{matchR}[y] was pushed and later popped with its whole list read, and so every right neighbour of it is in YY; also every right neighbour of rr is in YY. By induction along any alternating path from routr^{\text{out}}, every right vertex on it is in YY and so is covered. Hence no augmenting path starts at routr^{\text{out}}. □\square

Lemma 4 (Kuhn). Let PP be an augmenting path for MM with start xx, and M′=M⊕PM' = M \oplus P. If no augmenting path for MM starts at a left vertex uu, then no augmenting path for M′M' starts at uu.

Proof. Suppose QQ is an augmenting path for M′M' with start uu. Then uu is not covered by M′M', so not by MM, and u≠xu \ne x and uu is not on PP (every vertex of PP is covered by M′M'). If QQ has no vertex on PP, then MM and M′M' agree on the edges of QQ, and QQ is augmenting for MM, a contradiction. Otherwise let zz be the first vertex of QQ, from uu, that lies on PP, and let yy be the vertex before it. The edge yzyz is not on PP, since yy is not, so it is in M′M' exactly when it is in MM. If zz is a left vertex, QQ enters it by a matched edge of M′M'; but the M′M' partner of a vertex of PP lies on PP, and yy does not, a contradiction. So zz is a right vertex yiy_i of P=x,y1,x1,y2,…,xk−1,ykP = x, y_1, x_1, y_2, \ldots, x_{k-1}, y_k, where xj−1yj∉Mx_{j-1} y_j \notin M and yjxj∈My_j x_j \in M. The part of QQ from uu to zz alternates with respect to MM and enters zz by a non-matched edge, and yi,xi,yi+1,…,yky_i, x_i, y_{i+1}, \ldots, y_k alternates with respect to MM, starting with the matched edge yixiy_i x_i and ending at yky_k, which MM does not cover. The two parts share only zz, so together they are an augmenting path for MM starting at uu, a contradiction. □\square

Theorem. PATH-COVER terminates and returns a cover of VV by n−ν(H)n - \nu(H) vertex-disjoint paths, which is the minimum.

Proof. Each of the nn searches terminates by Lemma 3, and lines L12 to L14 follow at most nn pointers. The algorithm keeps a matching, by Lemma 3. A covered left vertex stays covered, because line L10 only rematches covered vertices and covers new ones. Claim: after the search from rr, no augmenting path starts at any uncovered left vertex among 0,…,r0, \ldots, r. If rr is covered after its search, the claim for rr is empty; otherwise its search failed and Lemma 3 shows there is none from rr. For earlier uncovered roots, the claim held before, and the matching changed only by augmenting paths, so it still holds by Lemma 4. At the end, no augmenting path starts at any uncovered left vertex, and every augmenting path has a left start, so there is none at all. By Lemma 2 the matching is maximum, and by Lemma 1 the output is a minimum path cover. ■\blacksquare

Back to Path cover by bipartite matching