# 随机算法 (Fall 2011)/Stable Marriage

### Stable marriage

Suppose that there are ${\displaystyle n}$ men and ${\displaystyle n}$ women. Every man has a preference list of women, which can be represented as a permutation of ${\displaystyle [n]}$. Similarly, every women has a preference list of men, which is also a permutation of ${\displaystyle [n]}$. A marriage is a 1-1 correspondence between men and women. The stable marriage problem or stable matching problem (SMP) is to find a marriage which is stable in the following sense:

There is no such a man and a woman who are not married to each other but prefer each other to their current partners.

The famous proposal algorithm (求婚算法) solves this problem by finding a stable marriage. The algorithm is described as follows:

Each round (called a proposal)
• An unmarried man proposes to the most desirable woman according to his preference list who has not already rejected him.
• Upon receiving his proposal, the woman accepts the proposal if:
1. she's not married; or
2. her current partner is less desirable than the proposing man according to her preference list. (Her current partner then becomes available again.)

The algorithm terminates when the last available woman receives a proposal. The algorithm returns a marriage, because it is easy to see that:

once a woman is proposed to, she gets married and stays as married (and will only switch to more desirable men.)

It can be seen that this algorithm always finds a stable marriage:

If to the contrary, there is a man ${\displaystyle A}$ and a woman ${\displaystyle b}$ prefer each other than their current partners ${\displaystyle a}$ (${\displaystyle A}$'s wife) and ${\displaystyle B}$ (${\displaystyle b}$'s husband), then ${\displaystyle A}$ must have proposed to ${\displaystyle b}$ before he proposed to ${\displaystyle a}$, by which time ${\displaystyle b}$ must either be available or be with a worse man (because her current partner ${\displaystyle B}$ is worse than ${\displaystyle A}$), which means ${\displaystyle b}$ must have accepted ${\displaystyle A}$'s proposal.

Our interest is the average-case performance of this algorithm, which is measured by the expected number of proposals, assuming that each man/woman has a uniformly random permutation as his/her preference list.

Apply the principle of deferred decisions, each man can be seen as that at each time, sampling a uniformly random woman from the ones who have not already rejected him, and proposing to her. This can only be more efficient than sampling a uniformly and independently random woman to propose. All ${\displaystyle n}$ men are proposing to uniformly and independently random woman, thus it can be seen as proposals (regardless which men they are from) are sent to women uniformly and independently at random. The algorithm ends when all ${\displaystyle n}$ women have received a proposal. Due to our analysis of the coupon collector problem, the expected number of proposals is ${\displaystyle O(n\ln n)}$.