A Bit of History
John Hopcroft and Richard Karp (Edmonds-Karp's Karp, once again) published this algorithm in 1973 in a paper titled, with refreshing directness, "An \(n^{5/2}\) Algorithm for Maximum Matchings in Bipartite Graphs." Hopcroft would go on to share the 1986 Turing Award with Robert Tarjan (already a recurring figure in this series, from Parts 6, 8, and the SCC deep dives) — recognized jointly for foundational contributions to algorithm and data structure design, with this matching algorithm standing as one of the concrete highlights of that body of work.
Working Principle
Recall Berge's theorem from Part 16: a matching is maximum exactly when no augmenting path exists. A naive algorithm finds one augmenting path at a time (via BFS or DFS) and augments, requiring up to \(O(V)\) augmentations, each costing \(O(E)\) to find — giving \(O(VE)\) overall, no better than generic max-flow. Hopcroft-Karp's insight: in a single phase, find the shortest augmenting-path length \(k\) via one BFS from all unmatched left-side vertices simultaneously, then use DFS to greedily extract a maximal set of vertex-disjoint augmenting paths, all of length exactly \(k\), and augment along all of them at once. Repeat phases until no augmenting path remains.
Analogy: Filling Many Seats in One Coordinated Pass
Instead of seating one person into one dinner-party arrangement at a time and re-shuffling the whole table each time (a new BFS/DFS per augmentation), Hopcroft-Karp finds the shortest possible "chain of swaps" needed, then simultaneously seats as many people as possible using disjoint chains of exactly that length — before moving on to consider longer chains in the next round. Doing many independent improvements per pass, rather than one improvement per pass, is exactly what shrinks the total number of passes needed.
Why O(√V) Phases Suffice
The key counting argument: after \(k\) phases, the shortest remaining augmenting path has length at least \(k+1\) (each phase exhausts all augmenting paths of the current shortest length, forcing the next phase's shortest path strictly longer — a direct extension of the "distances are non-decreasing" idea from Edmonds-Karp). Since a matching can differ from a maximum matching by at most \(\sqrt{V}\) vertex-disjoint augmenting paths whenever the shortest augmenting path already exceeds \(\sqrt{V}\) in length (a counting argument bounding how many disjoint paths of a given minimum length can fit in a graph of size \(V\)), at most \(O(\sqrt{V})\) phases are ever needed before the matching is provably maximum.
Complexity Analysis
\(O(\sqrt{V})\) phases, each costing \(O(E)\) for the BFS layering plus \(O(E)\) for the DFS-based disjoint-path extraction:
$$\text{Time: } O(E\sqrt{V}) \qquad \text{Space: } O(V + E)$$
This is a substantial improvement over generic Edmonds-Karp's \(O(VE)\) applied to the same unit-capacity bipartite-matching flow network from Part 16 — exploiting the very specific structure (unit capacities, bipartite layout) that a fully general max-flow algorithm can't assume.
Implementation
Real-World Applications
Large-Scale Task-to-Worker Assignment
Systems that must assign a large number of tasks to eligible workers (or jobs to machines, or ads to ad slots) at scale — where each side numbers in the hundreds of thousands — benefit directly from Hopcroft-Karp's asymptotic edge over generic max-flow, since the \(\sqrt{V}\) factor becomes a real, measurable performance difference at that size. It remains the standard textbook algorithm for unweighted bipartite matching precisely because of this favorable scaling.
Exercises
- Trace Hopcroft-Karp by hand on a small bipartite graph, identifying the shortest augmenting path length at each phase and confirming it strictly increases phase over phase.
- Explain why finding a maximal (not necessarily maximum) set of vertex-disjoint shortest augmenting paths per phase is enough for the overall algorithm to remain correct.
- Compare Hopcroft-Karp's matching result on a bipartite graph against the matching-via-max-flow reduction from Part 16 (using Edmonds-Karp), confirming both find matchings of the same maximum size.
- Challenge: Implement Hopcroft-Karp and measure the actual number of phases used on bipartite graphs of increasing size, verifying the count grows roughly like \(\sqrt{V}\) rather than \(V\).
Limitations
Bipartite and Unweighted Only
Hopcroft-Karp's speed comes specifically from exploiting bipartite structure and unit capacities — it does not extend to general (non-bipartite) graph matching, which requires the substantially more intricate Blossom algorithm (an upcoming deep dive), nor to weighted bipartite matching (the assignment problem), which the Hungarian Algorithm handles instead.