Skip to content
Part IA Lent Term

Maximum Bipartite Matching via Flow

A matching in a bipartite graph can be found by reduction to maximum flow. This is one of the cleanest applications of network flow theory and appears frequently on Tripos papers.

Bipartite Matching

A bipartite graph G=(V,E)G = (V, E) has V=LRV = L \cup R with LR=L \cap R = \emptyset and every edge crossing between LL and RR: EL×RE \subseteq L \times R.

A matching MEM \subseteq E is a set of edges such that no vertex is incident to more than one edge in MM. A vertex is matched if some edge in MM is incident on it; otherwise it is unmatched.

A maximum matching is a matching of maximum cardinality. A maximal matching is one that cannot be extended (not necessarily maximum).

Flow Network Construction

Given a bipartite graph (LR,E)(L \cup R, E), construct a flow network GG':

  1. Add source ss and sink tt
  2. For each uLu \in L, add directed edge (s,u)(s, u) with capacity 1
  3. For each vRv \in R, add directed edge (v,t)(v, t) with capacity 1
  4. For each (u,v)E(u, v) \in E (with uLu \in L, vRv \in R), direct from LL to RR with capacity 1

Bipartite to flow network reduction

Why This Works

Run Ford-Fulkerson or Edmonds-Karp on GG'. All capacities are 1 and integral, so the maximum flow assigns 0 or 1 to every edge. By the Integrality Theorem, there exists an integral maximum flow (all edge flows are integers). Since each vertex in LL receives at most 1 unit from ss, each uLu \in L sends flow to at most one vRv \in R. Symmetrically, each vRv \in R receives at most 1 unit. The edges with flow 1 form a valid matching.

The size of the maximum matching equals the value of the maximum flow: M=f|M| = |f|.

Running Time

Maximum flow value is at most LV/2|L| \le |V|/2, so at most V/2|V|/2 augmentations. Each BFS finds an augmenting path in O(E)O(|E|) time. Total: O(VE)O(|V| \cdot |E|).

Alternating Paths View

An alternating path (with respect to matching MM) alternates between edges not in MM and edges in MM. An augmenting path is an alternating path starting and ending at unmatched vertices. Augmenting along such a path (toggling matched/unmatched status of each edge) increases matching size by 1.

The flow-based BFS on the residual network corresponds exactly to finding augmenting paths in the alternating-paths view:

  • Forward edge (LRL \to R, not in matching) corresponds to residual forward capacity
  • Backward edge (RLR \to L, in matching) corresponds to residual reverse capacity (flow cancellation)

Worked Example

Bipartite graph: L={a,b,c}L = \{a, b, c\}, R={x,y,z}R = \{x, y, z\}.

Edges: (a,x)(a, x), (a,y)(a, y), (b,y)(b, y), (b,z)(b, z), (c,x)(c, x).

Flow network: sa,b,cs \to a, b, c (all capacity 1), ax,ya \to x, y, by,zb \to y, z, cxc \to x (all capacity 1), x,y,ztx, y, z \to t (all capacity 1).

Run Edmonds-Karp:

  1. Path saxts \to a \to x \to t: match (a,x)(a, x)
  2. Path sbyts \to b \to y \to t: match (b,y)(b, y)
  3. Path scxaybzts \to c \to x \to a \to y \to b \to z \to t? No, residual: xtx \to t is saturated, so xax \to a exists (reverse). Path scxs \to c \to x then reverse xax \to a (not valid, aa has no outgoing residual to tt directly…).

Actually: scxas \to c \to x \to a (reverse, cancels existing match) yt\to y \to t. This is the augmenting path: unmatch (a,x)(a, x), match (c,x)(c, x) and (a,y)(a, y). Now matching: (c,x)(c, x), (a,y)(a, y), (b,?)(b, ?).

  1. Path sbzts \to b \to z \to t: match (b,z)(b, z).

Maximum matching: (c,x)(c, x), (a,y)(a, y), (b,z)(b, z) with size 3. This is a perfect matching (all vertices matched).

Beyond BFS: Hopcroft-Karp

Hopcroft-Karp finds multiple vertex-disjoint shortest augmenting paths per BFS round using a layered graph and DFS. Running time improves to O(EV)O(|E| \cdot \sqrt{|V|}). This is examinable but less commonly examined than the basic reduction.

Summary

ConceptDetail
ReductionLRL \cup R bipartite \to flow network with ss, tt, unit capacities
Matching size=f= \lvert f \rvert
FF/EK running timeO(VE)O(\lvert V \rvert \cdot \lvert E \rvert)
Hopcroft-KarpO(EV)O(\lvert E \rvert \cdot \sqrt{\lvert V \rvert})
IntegralityUnit capacities + FF integral input     \implies integral output

Past Tripos: y2024p1q9, y2023p2q7.