Module 25 of 39

Bipartite matching: augmenting paths and assignments

Distinguish maximum matching, stable matching, and minimum-cost assignment in bipartite graphs.

Suppose volunteers can take certain tasks, but each volunteer can take at most one and each task needs at most one volunteer. Draw volunteers on one side, tasks on the other, and connect each allowed pair. This is a bipartite graph. A matching is a set of edges with no shared endpoint. A maximum matching pairs as many volunteers and tasks as possible.

Background for this page. A matching chooses edges with no shared endpoint. Bipartite means vertices divide into two groups and every edge joins the groups. Maximum refers to the largest possible number of pairs. Related explanations: Graph traversal: BFS, DFS, and topological order · Maximum flow: residual paths and minimum cuts.

A tempting method is to take the first available pair. It can fail. If A can do tasks 1 and 2, but B can do only task 1, pairing A with 1 leaves B unmatched. Pairing A with 2 and B with 1 gives two matches. A better method finds an augmenting path: a path that alternates between unused and used edges and begins and ends at unmatched vertices. Flipping the status of its edges increases the matching size by one.

Volunteer A can do tasks 1 or 2, and volunteer B can only do task 1. Reroute A to task 2 so both people can be matched.

We can also build a flow network: source to each volunteer with capacity 1, allowed volunteer-to-task edges with capacity 1, and each task to sink with capacity 1. An integer maximum flow then corresponds to a maximum matching. This gives a way to solve matching using maximum flow; specialized matching methods may be more efficient.

Not every matching question asks for the largest number of pairs. In stable matching, each side ranks possible partners. A matching is stable if there is no unmatched pair who would both prefer each other to their assigned partners. A deferred-acceptance method produces a stable result under its assumptions, but “stable” is a different objective from “maximum number matched.” Preferences must be part of the input.

In the assignment problem, every allowed pair may have a cost. The goal is to choose a complete assignment with the smallest total cost, or the largest total value. The Hungarian algorithm solves the standard weighted bipartite assignment problem in polynomial time. A maximum-cardinality matching alone does not tell us which full assignment is cheapest.

These models make hidden choices visible. Are some pairings forbidden? Must everyone be assigned? Are we maximizing the number of assignments, respecting preferences, or minimizing cost? A correct algorithm for one of these questions can be a wrong answer to another.

Count the gain on an augmenting path

Begin with A matched to task 1 and B unmatched. The alternating path B→1→A→2 starts and ends unmatched. Its first and last edges are unused; its middle edge is the current pair A–1. Flip their status. Remove A–1, add B–1 and A–2. Two selected edges replace one, so the matching grows by one.

No endpoint becomes assigned twice: internal vertices lose one selected edge and gain one, while the two endpoints gain their first. A maximal matching has no directly addable edge; a maximum matching has the greatest possible size. These are different conditions. The A–1 matching is maximal but not maximum.

Practice. A can take tasks 1 or 2; B can take only task 1. What maximum matching can you make? Why might a greedy first available pair fail?

Answer. Match A to 2 and B to 1. If a greedy method takes A to 1 first and refuses to revise that choice, it leaves B unmatched even though two matches are possible.

Try another case. If a matching cannot accept one more edge immediately, must it be maximum?

Reasoning. No. A longer alternating path may rearrange existing pairs and increase the size. Searching for augmenting paths detects that possibility.

View the full course and choose another topic.

Image preview

Fit