graph algorithms
Matching Theory
You should know: bipartite graphs
Overview
A matching in a graph is a set of edges with no two sharing a vertex — every vertex touches at most one matching edge. A maximum matching has the largest possible number of edges, and a perfect matching covers every vertex. For bipartite graphs, Hall's marriage theorem gives a clean existence criterion for a perfect matching: one exists (saturating one side) if and only if every subset S of that side has at least |S| neighbors on the other side (the 'marriage condition'). The Hungarian algorithm finds a maximum matching (or minimum-cost perfect matching) in bipartite graphs in polynomial time, and matching problems reduce directly to network flow problems, connecting the two areas.
Intuition
Picture pairing up dance partners at a formal, where each person can dance with at most one partner at a time — a matching is exactly such a set of non-overlapping pairs. Hall's marriage theorem formalizes when a full pairing is possible: if any group of k people on one side collectively knows fewer than k people on the other side, that group can never all be matched — a bottleneck. This exact logic underlies assigning residents to hospitals, workers to shifts, and kidney donors to recipients.
Formal Definition
For a graph G = (V, E), a matching M ⊆ E has no shared endpoints:
Worked Examples
Try matching 1-a: this uses vertex 1 and vertex a. Vertex 2 can then only match with b (since a is taken), via edge 2-b.
Both vertices in X (1 and 2) and both in Y (a and b) are covered, with no shared endpoints between the two edges. This is a perfect matching of size 2.
Answer: Maximum matching = {1-a, 2-b}, size 2 (a perfect matching).
Practice Problems
A matching in a graph has 4 edges. How many vertices does it cover (assuming no two edges share an endpoint, by definition of matching)?
A medical residency matching program pairs 100 graduating students with 100 hospital residency slots (one student per slot). If Hall's condition holds for every subset of students, what does that guarantee?
Explain how finding a maximum bipartite matching can be reduced to a maximum flow problem.
Quiz
Summary
- A matching pairs up vertices via edges with no shared endpoints; a perfect matching covers every vertex.
- Hall's marriage theorem gives an exact existence criterion for bipartite matchings via the 'every subset has enough neighbors' condition.
- Maximum bipartite matching reduces to a unit-capacity max-flow problem, linking matching theory directly to network flow algorithms.
Mathematics