Finding maximum matchings for graphs in general is difficult, but it's much easier for bipartite graphs:
- Add a new source vertex s with an edge to each vertex in L.
- Add a new target vertex t with an edge from each vertex in R.
- Give every edge a capacity of 1.
Claim:
flows of
value k on this new extended graph are in 1-1 correspondence with valid matchings of size
k in the original graph.
- A valid flow of value k must have k units of flow going from L to R; since the edges all have capacity 1 there must therefore be k edges with flow on them. Moreover, none of them can share an endpoint since then two units of flow would have to enter or exit the same vertex, but this is impossible since the edges from s and the edges to t all have capacity 1 as well.
- Conversely, given any k edges which share no endpoints, simply put one unit of flow along each edge, and continue the flow to s and t. This will be a valid flow for the same reasons.
Hence, a maximum flow must correspond to a maximum matching, and vice versa. So if we had an algorithm to find maximum flows, we could use it to compute maximum matchings in bipartite graphs.