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=L∪RV = L \cup R with L∩R=∅L \cap R = \emptyset and every edge crossing between LL and RR: E⊆L×RE \subseteq L \times R.

A matching M⊆EM \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 (L∪R,E)(L \cup R, E), construct a flow network G′G':

  1. Add source ss and sink tt
  2. For each u∈Lu \in L, add directed edge (s,u)(s, u) with capacity 1
  3. For each v∈Rv \in R, add directed edge (v,t)(v, t) with capacity 1
  4. For each (u,v)∈E(u, v) \in E (with u∈Lu \in L, v∈Rv \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 G′G'. 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 u∈Lu \in L sends flow to at most one v∈Rv \in R. Symmetrically, each v∈Rv \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 ∣L∣≤∣V∣/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(∣V∣⋅∣E∣)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 (L→RL \to R, not in matching) corresponds to residual forward capacity
  • Backward edge (R→LR \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: s→a,b,cs \to a, b, c (all capacity 1), a→x,ya \to x, y, b→y,zb \to y, z, c→xc \to x (all capacity 1), x,y,z→tx, y, z \to t (all capacity 1).

Run Edmonds-Karp:

  1. Path s→a→x→ts \to a \to x \to t: match (a,x)(a, x)
  2. Path s→b→y→ts \to b \to y \to t: match (b,y)(b, y)
  3. Path s→c→x→a→y→b→z→ts \to c \to x \to a \to y \to b \to z \to t? No, residual: x→tx \to t is saturated, so x→ax \to a exists (reverse). Path s→c→xs \to c \to x then reverse x→ax \to a (not valid, aa has no outgoing residual to tt directly…).

Actually: s→c→x→as \to c \to x \to a (reverse, cancels existing match) →y→t\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 s→b→z→ts \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(∣E∣⋅∣V∣)O(|E| \cdot \sqrt{|V|}). This is examinable but less commonly examined than the basic reduction.

Summary

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

Past Tripos: y2024p1q9, y2023p2q7.