Ravi is an armchair futurist and an aspiring mad scientist. His mission is to create simplicity out of complexity and order out of chaos.

## Friday, September 14, 2012

### Gale-Shapley algorithm as a picture

Here is a pictorial depiction of the Gale-Shapley algorithm:

• Each man $M_i$ is drawn as a square and each woman $W_j$ as a circle.
• Each person's choices are arranged clockwise, in ascending order of desirability - i.e. the bottom choice first, followed by better and better choices and eventually the top choice in a clockwise manner.
• According to the algorithm
• Man proposes to his highest choice woman that he has not proposed to. So, in the diagram above, he goes through his choices anti-clockwise.
• Woman accepts a proposal if the man is better than her current fiance.  So, in the diagram above, she goes through her choices clockwise.
The following is apparent from the picture:
1. As the algorithm progresses, every woman can only improve her situation. In other words, the worst she can do is her current fiance - it only gets better for her!
2. As the algorithm progresses, every man's position can only get worse. In other words, "it is all downhill" for him.
3. The reason for rejecting a man's proposal is always that the woman's current choice is better than him (for her) and it can only get better for her, implying that he cannot introduce instability for those women who have rejected him.
4. Since a woman can be proposed to only once by each man, she can get no more than $|M|$ proposals. Since there are $|W|$ women and some woman is proposed to at each step, the algorithm has to terminate in $O(|M|\times|W|)$ time.
5. When we have an equal number of men and women, each woman will be proposed to (eventually). This means that each woman will have a fiance (she must accept a proposal if she has no fiance). Since $|M|=|W|$ in this case, this algorithm runs in $O(n^2)$ time.
References

#### 1 comment:

1. And I thought someone's proposal getting accepted was based on capricious, irrrational and impetuous feelings.