Section 3.4 The Stable Marriage Problem
Suppose that there are \(n\) companies and \(n\) interns and every company wants to hire exactly one intern. In other words, we are looking for a matching in the complete bipartite graph between the set of companies and interns. Of course, we want to find the best matching, under some definition of “best.”
At first, one may think that the maximum weight matching algorithm presented in
Section 3.3 is perfectly suited for this job. However, in a free society, the maximum weight perfect matching may lead to poor outcomes. For example, if there is an intern who prefers another company over the one that they have been matched to, and that company simultaneously prefers that intern over the one that they were assigned, then that company may fire their current intern and send a job offer to the other one. If we are trying to assign interns to jobs in practice, it might be nice to avoid such a situation.
This leads us to the topic of this section, the Stable Marriage Problem. In this problem, each intern has a ranking of all \(n\) companies based on their preferences and each company has a ranking of all \(n\) candidates. All of these rankings are strict (there are no ties). A perfect matching of interns to companies is unstable if there exists an intern \(i\) and a company \(c\) such that \(i\) prefers \(c\) over the company that they are matched to and, simultaneously, \(c\) prefers \(i\) over the intern that they are matched to. Otherwise, it is stable. As it turns out, stable matchings always exists and, moreover, they can be found in polynomial time.
Algorithm 3.4.1. Gale–Shapley Algorithm.
The algorithm proceeds in rounds as follows: In each round, each company that has had all of its offers rejected so far during the process makes a job offer to the highest intern in their ranking that they have not previously made an offer to. All of these job offers are made simultaneously. After this, every intern (including those who already had a pending offer from previous rounds) reviews all of the offers that they have received so far which they have not yet rejected and rejects all of them except for the one from the highest employer in their ranking among all that they’ve received an offer from.
We stop when either (a) every company has made an offer that has not yet been rejected or (b) some company has been rejected from every intern. At that point, then each intern with a pending offer accepts that offer and we output the resulting matching.Now, let us show that this algorithm always outputs a stable perfect matching. First, let us show that this algorithm reaches a perfect matching. If it does not, then there must be a company \(c\) that gets rejected from all \(n\) interns. However, this implies that every intern receives at least one offer (since they received one from \(c\)). However, every intern that receives an offer eventually gets matched with a company, because they never reject all of their offers. So, this means that, at the end of the algorithm, every intern has a pending offer. No company ever has two pending offers because, in each round, the only companies that make offers are the ones that do not already have a pending offer. So, all interns get matched to a company and no two companies are matched to the same intern. This implies that all companies must get matched as well because there are the same number of companies as interns. To see that the matching is stable, we observe that, for any company, they have already made offers to each intern that they would prefer over the one that they are matched to which were rejected because that intern had a better offer at the time. Moreover, that intern will only reject this better offer if they get an even better one later on. So, the matching is stable. The running time is clearly \(O(n^2)\) because no company makes an offer to the same candidate twice.
The correctness of the above algorithm implies the following.
Theorem 3.4.2. The Stable Marriage Theorem.
Suppose that every vertex of a complete bipartite graph has a ranking of all of the vertices on the other side of the bipartition. A stable perfect matching always exists.For general bipartite graphs (i.e. bipartite graphs that are not necessarily complete or balanced) one can always obtain a stable matching, but it may not be perfect. In this setting, a matching \(M\) is stable if, for every edge \(xy\in E(G)\setminus M\text{,}\) either \(M\) matches \(x\) to a vertex that it prefers over \(y\text{,}\) or it matches \(y\) to a vertex that it prefers over \(x\text{.}\)
Corollary 3.4.3.
Suppose that every vertex of a bipartite graph has a ranking of its neighbours. A stable matching always exists.Here is a YouTube video related to this section:
Here are two nice
Numberphile videos on the Stable Marriage Problem.