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 be a directed acyclic graph with vertices, parallel arcs allowed. The split graph has left vertices , right vertices , and an edge for each arc . Since has no self-loop, no edge of joins the two copies of one vertex. A matching is a set of edges of with no common end. An augmenting path for a matching is a path in whose edges alternate between non-matched and matched, and whose two end vertices are not covered by .
Lemma 1 (covers and matchings). For every matching of , the arcs form vertex-disjoint paths that cover , and there are exactly of them. Conversely, every cover of by vertex-disjoint paths gives a matching of size . Hence the least number of paths is , where is the size of a maximum matching.
Proof. In every vertex has at most one outgoing arc, since is matched at most once, and at most one incoming arc, since is matched at most once. A graph on with in-degrees and out-degrees at most 1 is a union of vertex-disjoint paths and cycles, and has no cycle. Each vertex is on exactly one of these paths (possibly a path of one vertex). A path with vertices has arcs, so summing over the paths, , and . Conversely, for a cover by disjoint paths, take the edges for consecutive vertices of a path: each vertex has at most one successor and one predecessor, so this is a matching, of size .
Lines L12 and L13 output exactly the paths of : a path starts at a vertex with no predecessor, , and follows its arcs. By Lemma 1 every vertex is on one of them. It remains to show that the final is maximum.
Lemma 2 (Berge). If a matching is not maximum, it has an augmenting path.
Proof. Let be a larger matching. In the symmetric difference every vertex has degree at most 2, so its components are paths and even cycles whose edges alternate between and . Some component has more edges of than of ; it is a path that starts and ends with an edge, and its ends are not covered by . It is an augmenting path for .
In the bipartite graph 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 be the matching before the search from root (lines L4 to L11), with not covered. The search ends; if an augmenting path starting at exists, it finds one and line L10 replaces by , a matching with one more edge; otherwise does not change.
Proof. Invariant: the stack is , the list is (or just after line L8 appends), is an edge not in , and is in . So is an alternating path. Line L8 appends adjacent to the top , line L11 pushes , and line L7 pops a frame together with the 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 are distinct, and different from , which is not covered.
Termination. Each iteration either reads a new list entry through or pops a frame. A left vertex is pushed only as for a newly visited , so at most pushes happen, and the lists are finite.
Success. At line L9, is not covered, so the alternating path from to is augmenting. Line L10 matches with for all , which removes the matched edges (each is rematched to and each to ) and adds the others: this is , a matching of size .
Failure. Suppose the stack empties. Let be the visited right vertices. Every is covered (otherwise line L9 succeeds), its partner was pushed and later popped with its whole list read, and so every right neighbour of it is in ; also every right neighbour of is in . By induction along any alternating path from , every right vertex on it is in and so is covered. Hence no augmenting path starts at .
Lemma 4 (Kuhn). Let be an augmenting path for with start , and . If no augmenting path for starts at a left vertex , then no augmenting path for starts at .
Proof. Suppose is an augmenting path for with start . Then is not covered by , so not by , and and is not on (every vertex of is covered by ). If has no vertex on , then and agree on the edges of , and is augmenting for , a contradiction. Otherwise let be the first vertex of , from , that lies on , and let be the vertex before it. The edge is not on , since is not, so it is in exactly when it is in . If is a left vertex, enters it by a matched edge of ; but the partner of a vertex of lies on , and does not, a contradiction. So is a right vertex of , where and . The part of from to alternates with respect to and enters by a non-matched edge, and alternates with respect to , starting with the matched edge and ending at , which does not cover. The two parts share only , so together they are an augmenting path for starting at , a contradiction.
Theorem. PATH-COVER terminates and returns a cover of by vertex-disjoint paths, which is the minimum.
Proof. Each of the searches terminates by Lemma 3, and lines L12 to L14 follow at most 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 , no augmenting path starts at any uncovered left vertex among . If is covered after its search, the claim for is empty; otherwise its search failed and Lemma 3 shows there is none from . 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.