Bipartite Graphs and Matching
A bipartite graph has two sides, like applicants and jobs, with edges only going across. A matching pairs people up along those edges with nobody used twice, and Hall's theorem says everyone on one side can be matched exactly when no group of them is competing for too few partners.
What the symbols mean
- Neighborhood
Every vertex on the other side joined to someone in S.
- A group
Any set of vertices on side A.
- One side
The side we want to match completely, such as the applicants.
Explanation
A bipartite graph is simply one whose dots split into two teams, with lines only between the teams, never inside one. "Bi-partite" means "two parts." A matching pairs dots from one team with dots from the other along those lines, with nobody paired twice, and it's good for any assignment problem: applicants to jobs, students to dorm rooms, donors to patients. Hall's condition looks cryptic, but it's just this: pick any group of applicants, look at (all the jobs at least one of them qualifies for), and check that there are at least as many jobs as people, . If that holds for every group, everyone can be hired. It's a bottleneck check, nothing more.
Bipartite test. You've seen this idea already in the last lesson: splitting into two teams with no edges inside a team is the same as coloring the vertices with 2 colors. And a 2-coloring exists exactly when there's no odd cycle, since going around an odd cycle you'd have to alternate teams and land back on the wrong one. Breadth-first search checks this in one pass.
Matchings. A matching is a set of edges with no shared vertices. It's perfect if it covers every vertex. So how do you find a big one? Greedily grabbing pairs can get stuck, with someone left over even though a better arrangement exists. The fix is an augmenting path: a path that alternates between unused and used edges and starts and ends at unmatched vertices. Notice it has one more unused edge than used ones, since it starts and ends on unused edges. So flipping it, swapping used for unused all along the path, adds one edge to the matching while keeping it a matching. And a matching is maximum exactly when no augmenting path exists. There's an animation further down that does exactly this.
Hall's theorem. Side can be matched completely if and only if every group of -vertices is, collectively, joined to at least vertices, so there's no bottleneck. One direction is the pigeonhole principle from the counting unit: if three applicants all qualify for only the same two jobs, some two of them would have to share a job, so matching fails. The surprising part is the other direction: if no group is ever short, a complete matching always exists.
Stable matching. When both sides have preferences, the Gale–Shapley algorithm finds a matching where no two people would both rather be with each other. It earned Lloyd Shapley and Alvin Roth the 2012 Nobel Prize in Economics.
A common mistake. It's tempting to check Hall's condition one applicant at a time: everyone qualifies for at least one job, so we're fine. That isn't enough. In the example below, Ana and Ben each qualify for a job, but together they only have one between them. The condition has to hold for every group.
See it
Worked examples
Applicants Ana, Ben and Cal; jobs X and Y. Ana and Ben qualify only for X; Cal qualifies for X and Y. Can everyone be hired?
- 1
Look for a group that's competing for too few jobs. Ana and Ben both want only X, so take . Their neighborhood is just .
Practice
Type your answer and check it. Solve them all to complete the lesson.
Is a cycle with 6 vertices bipartite?
Is a triangle bipartite?
What is the largest possible matching in ?
How many perfect matchings does have?
Three applicants are each qualified only for the jobs X and Y. Can all three be hired into different jobs?
How many perfect matchings does the complete graph have (pairing up 6 people)?
The hardest one here. Get it, and you've got this lesson.
A domino tiling of a board is a perfect matching of its squares, pairing neighbors. How many ways can a 2 × 6 board be tiled with 1 × 2 dominoes?
Where it's used
The U.S. medical residency match and kidney exchange programs run matching algorithms, the work honored by the 2012 Nobel Prize in Economics.