## Section 16.4 The Stable Matching Theorem

Now we present a light hearted optimization problem with a quite clever solution, called the *Stable Matching Theorem*. There are \(n\) eligible males \(b_1\text{,}\) \(b_2,\dots,b_n\) and \(n\) eligible females \(g_1\text{,}\) \(g_2,\dots,g_n\text{.}\) (The theorem dates back many years, hence the heteronormative statement.) We will arrange \(n\) marriages, each involving one male and one female. In the process, we will try to make everyone happy—or at least we will try to keep things stable.

Each female linearly orders the males in the order of her preference, i.e., for each \(i=1,2,\dots,n\text{,}\) there is a permutation \(\sigma_i\) of \([n]\) so that if \(g_i\) prefers \(b_j\) to \(b_k\text{,}\) then \(\sigma_i(j)> \sigma_i(k)\text{.}\) Different females may have quite different preference orders. Also, each male linearly orders the females in order of his preference, i.e., for each \(i=1,2,\dots,n\text{,}\) there is a permutation \(\tau_i\) of \([n]\) so that if \(b_i\) prefers \(g_j\) to \(g_k\text{,}\) then \(\tau_i(j)>\tau(k)\text{.}\)

A \(1\)–\(1\) matching of the \(n\) males to the \(n\) females is stable if there do not exist two males \(b\) and \(b'\) and two females \(g\) and \(g'\) so that

\(b\) is matched to \(g\text{;}\)

\(b\) prefers \(g'\) to \(g\text{;}\) and

\(g\) prefers \(b'\) to \(b\text{.}\)

The idea is that given these preferences, \(b\) and \(g\) may be mutually inclined to dissolve their relationship and initiate dalliances with other partners.

So the question is whether, regardless of their respective preferences, we can always generate a stable matching. The answer is yes and there is a quite clever argument. In fact, it is one that yields a quite efficient algorithm. At Stage 1, all males go knock on the front door of the female which is tops on their list. It may happen that some females have more than one caller while others have none. However, if a female has one or more males at her door, she reaches out and grabs the one among the group which she prefers most by the collar and tells the others, if there are any, to go away. Any male rejected at this step proceeds to the front door of the female who is second on their list. Again, a female with one or more suitors at her door chooses the best among then and sends the others away. This process continues until eventually, each female is holding onto exactly one male.

It is interesting to note that each female's prospects improve over time, i.e., once she has a suitor, things only get better. Conversely, each male's prospects deteriorate over time. Regardless, we assert that the resulting matching is stable. To see this, suppose that it is unstable and choose males \(b\) and \(b'\text{,}\) females \(g\) and \(g'\) so that \(b\) is matched to \(g\text{,}\) but \(b\) prefers \(g'\) to \(g\) while \(g\) prefers \(b'\) to \(b\text{.}\) The algorithm requires that male \(b\) start at the top of his list and work his way down. Since he eventually lands on \(g\)'s door step, and he prefers \(g'\) to \(g\text{,}\) it implies that once upon a time, he was actually at \(g'\)'s door, and she sent him away. This means that at that exact moment, she had a male in hand that she prefers to \(b\text{.}\) Since her holdings only improve with time, it means that when the matching is finalized, female \(g\) has a mate \(b\) that she prefers to \(b'\text{.}\)