From Separate Vertices to Connected Paths
Imagine beginning with every DAG vertex as a one-vertex path. There are $n$ paths. Whenever an edge $u\to v$ is chosen to place $v$ immediately after $u$, two paths merge and the count falls by one. The optimization question is therefore: how many compatible predecessor–successor links can we choose at once?
The partial-order connection
The Problem—and Two Variants to Keep Separate
A vertex-disjoint path cover is a collection of directed paths in which every vertex appears exactly once. Paths of one vertex are allowed. The goal is to use as few paths as possible.
| Variant | When $u$ may precede $v$ | Bipartite edges | Meaning |
|---|---|---|---|
| Edge-based path cover | The original edge $u\to v$ exists | Use original DAG edges | Consecutive path vertices are directly connected. |
| Reachability chain cover | Some directed path connects $u$ to $v$ | Use the transitive closure | Vertices are comparable, even if other vertices lie between them. |
This article’s default
Unless stated otherwise, “path cover” means the edge-based, vertex-disjoint version. Using transitive closure can produce a smaller number, but it answers the reachability-chain question instead.
Split Every Vertex, Then Match
Construct a bipartite graph with a left copy $v_L$ and a right copy $v_R$ of every DAG vertex. For each DAG edge $u\to v$, add the bipartite edge $u_L\to v_R$.
Left copy
Matching $u_L$ chooses at most one successor for $u$.
Right copy
Matching $v_R$ chooses at most one predecessor for $v$.
Acyclicity
The chosen predecessor–successor links cannot close into a directed cycle.
flowchart TD
D[Copy every vertex left and right] --> E[Map each DAG edge u→v to uL→vR]
E --> M[Find a maximum bipartite matching]
M --> S[Matched pairs become successor links]
S --> P[Begin at unmatched right copies and follow links]Worked Example: From Matching to Two Paths
The example DAG has five vertices and six edges:
| Matched bipartite edge | Path-cover interpretation |
|---|---|
| $A_L\to B_R$ | $B$ immediately follows $A$. |
| $B_L\to D_R$ | $D$ immediately follows $B$. |
| $D_L\to E_R$ | $E$ immediately follows $D$. |
The matching size is $3$, so the cover size is:
Right copies $A_R$ and $C_R$ are unmatched, so reconstruction starts at $A$ and $C$. Following matched successors produces $A\to B\to D\to E$ and $C$.
Check the flexibility of matching
Remove the edge $D\to E$. Does the minimum cover size increase?
Answer: no. A different size-3 matching—$A\to B$, $B\to D$, and $C\to E$—still gives two paths: $A\to B\to D$ and $C\to E$.
Why the Formula Is $n-|M_{\max}|$
The equality follows from two directions.
From a matching to a path cover
Each matched edge chooses one successor and one predecessor. Matching constraints prevent branching: no vertex receives two chosen predecessors, and no vertex chooses two successors. Because the original graph is acyclic, the selected links form disjoint paths, not cycles. Starting from $n$ singleton paths, each of the $|M|$ selected links merges two components, leaving $n-|M|$ paths.
From a path cover to a matching
Suppose a cover has $k$ paths. A path containing $r$ vertices uses exactly $r-1$ internal edges. Summed across all paths, the cover uses $n-k$ predecessor–successor links. Those links form a valid bipartite matching, because every vertex has at most one predecessor and one successor inside its path. Therefore a maximum matching is at least $n-k$, and minimizing $k$ is equivalent to maximizing the matching.
The invariant to remember
Every legal matched link saves exactly one path, and every saved path requires exactly one legal link. That one-for-one exchange is the entire reduction.
Reconstructing the Actual Paths
A matching algorithm usually returns pairLeft[u], the right vertex matched to left copy $u_L$, or “unmatched.” Convert it into two arrays:
| Array | Definition | Use |
|---|---|---|
successor[u] | The vertex $v$ matched to $u_L$ | Follow the current path forward. |
predecessor[v] | The vertex $u$ whose left copy matched $v_R$ | Detect whether $v$ starts a path. |
- For every matched pair $u_L\to v_R$, set
successor[u] = vandpredecessor[v] = u. - Every vertex with no predecessor is a path start.
- From each start, repeatedly follow
successoruntil none exists.
Common reconstruction mistake
Starts are found from unmatched right copies, not unmatched left copies. An unmatched left copy has no successor, so it marks a path end.
Implementation: Reuse the Matching Result
Run Hopcroft–Karp or a simpler augmenting-path matcher first. The following code turns its left-pair array into the actual cover.
Implementation checklist
- Verify the input is acyclic with a topological sort.
- Create exactly one left and one right copy per original vertex.
- Add a bipartite edge for each original DAG edge—unless reachability chains are explicitly intended.
- Keep the matching pairs, not only the matching size.
- Start reconstruction at vertices unmatched on the right.
- Include isolated vertices as singleton paths.
Where Path Covers Are Useful
The reduction applies when a vertex must be used exactly once and an edge means one item may directly follow another.
Worker Sequences
If one worker may continue from task $u$ directly to compatible task $v$, each cover path is one worker’s route.
Pipeline Chains
Compress a DAG into a small set of non-overlapping processing chains for display or operational ownership.
Value Lifetimes
Compatibility edges can link values or operations that safely reuse a sequential resource.
Assembly Runs
Allowed transitions join jobs into the fewest disjoint production sequences.
Model the edge meaning carefully
A generic prerequisite edge does not automatically mean “the same worker can perform these consecutively.” The worker interpretation is valid only when edges encode allowed handoffs or sequencing, not merely dependency.
Pitfalls and Boundary Cases
| Case | What happens | Response |
|---|---|---|
| Directed cycle | A matching may select a cycle, so $n-|M|$ can even become zero. | Reject or transform cyclic input; DAG acyclicity is essential. |
| Isolated vertex | Both copies remain unmatched. | Return it as a singleton path. |
| Multiple maximum matchings | Different optimal path covers may be reconstructed. | Add tie-breaking or weights only if the particular cover matters. |
| Transitive closure added silently | The result may shrink by linking merely reachable vertices. | State that the goal is a reachability chain cover. |
| Paths may share vertices | The matching model no longer represents the problem. | Use a formulation designed for overlap or flow multiplicity. |
Complexity and Algorithm Choice
The split graph has $2n$ vertices and $m$ bipartite edges. Building it costs $O(n+m)$. Hopcroft–Karp finds a maximum matching in $O(m\sqrt{n})$ time and $O(n+m)$ memory; reconstruction adds $O(n)$. A topological-sort validation also costs $O(n+m)$.
| Situation | Good starting point | Tradeoff |
|---|---|---|
| Small graph or simplest implementation | DFS augmenting paths | Easy to code; worst case $O(nm)$. |
| Large sparse DAG | Hopcroft–Karp | Better asymptotic matching time. |
| Reachability-chain decomposition | Transitive closure + matching | Correct semantics, but closure can be dense and expensive. |
| Preferred or weighted transitions | Weighted matching or min-cost flow | Optimizes which minimum cover is chosen. |
| General directed graph | Different formulation | The DAG reduction no longer guarantees paths and the general problem is much harder. |
Mental model to keep
Start with one path per vertex. A bipartite matching chooses the largest set of conflict-free successor links. Each link removes exactly one path, so the minimum number remaining is $n-|M_{\max}|$.