Dripto Bakshi - Lecture Slides - Stable Matching Algorithm
Dripto Bakshi - Lecture Slides - Stable Matching Algorithm
Examples:
i. Marriage / Dating market (X women, Y men)
The Matching Problem
Two heterogenous populations (X and Y )
Every x ∈ X has a preference ordering over the elements of Y.
Every y ∈ Y has a preference ordering over the elements of X.
Questions: Who should be matched with whom?
Examples:
i. Marriage / Dating market (X women, Y men)
ii. Labor contract (X CEOs, Y firms; ...)
The Matching Problem
Two heterogenous populations (X and Y )
Every x ∈ X has a preference ordering over the elements of Y.
Every y ∈ Y has a preference ordering over the elements of X.
Questions: Who should be matched with whom?
Examples:
i. Marriage / Dating market (X women, Y men)
ii. Labor contract (X CEOs, Y firms; ...)
iii. Credit (X firms, Y banks)
iv. (X buyers, Y sellers, Z products), etc.
The Matching Problem
Two heterogenous populations (X and Y )
Every x ∈ X has a preference ordering over the elements of Y.
Every y ∈ Y has a preference ordering over the elements of X.
Questions: Who should be matched with whom?
Examples:
i. Marriage / Dating market (X women, Y men)
ii. Labor contract (X CEOs, Y firms; ...)
iii. Credit (X firms, Y banks)
iv. (X buyers, Y sellers, Z products), etc.
Extensions:
Many to many: s (x1, ..., xn, y1, ..., yk ): Campus Placements.
The Matching Problem: Marriage
This presentation: marriage market.
Assume Monogamy: One to One Matching
Assume n(X) = n(Y): equal sized population.
How to “optimally” match?
What do we mean by “optimal” ?
Let’s look at an example.
Example
1
HRITHIK
2
SUZANNE Preferences:
1 2
Hrithik: Kangana , Suzanne
2 1
JOHN KANGANA
John: Kangana , Suzanne
1 2
Kangana: Hrithik , John
Suzanne: Hrithik , John
Possible Matchings
Matching 1: {Hrithik – Suzanne , John – Kangana}
Matching 2: {Hrithik – Kangana , John – Suzanne}
Possible Matchings
Matching 1: {Hrithik – Suzanne , John – Kangana}
Matching 2: {Hrithik – Kangana , John – Suzanne}
In Matching 1: Hrithik prefers Kangana over Suzanne. Kangana too prefers Hrithik
over John. So both prefer each other over their mates.
So they’ll cheat !
Rogue Couple: Given a matching M, two individuals X & Y form a rogue couple if
they prefer each other over their mates.
SRK
2 1
1 1
3
1
1
1 2
2 1
1
SALMAN 1 1 AAMIR
3 3
1 1
JOHN
Preferences:
Proof by contradiction:
Assume that there exists a stable match M.
Theorem 1
There does NOT exist a stable match.
Proof by contradiction:
Assume that there exists a stable match M.
⇒John will be matched with someone. (WLOG by symmetry let’s say
John matches with SRK)
Theorem 1
There does NOT exist a stable match.
Proof by contradiction:
Assume that there exists a stable match M.
⇒John will be matched with someone. (WLOG by symmetry let’s say
John matches with SRK)
⇒ Salman is matched with Aamir.
Theorem 1
There does NOT exist a stable match.
Proof by contradiction:
Assume that there exists a stable match M.
⇒John will be matched with someone. (WLOG by symmetry let’s say
John matches with SRK)
⇒ Salman is matched with Aamir.
⇒ Salman & SRK form a “rogue couple”.
Theorem 1
There does NOT exist a stable match.
Proof by contradiction:
Assume that there exists a stable match M.
⇒John will be matched with someone. (WLOG by symmetry let’s say
John matches with SRK)
⇒ Salman is matched with Aamir.
⇒ Salman & SRK form a “rogue couple”.
⇒ M is NOT stable.
Theorem 2
First we’ll propose the algorithm & then claim that it leads to a stable
match.
Example:
Five Girls: A,B,C,D,E
Five Boys: 1,2,3,4,5
Example:
Five Girls: A,B,C,D,E
Five Boys: 1,2,3,4,5
Preference of Boys: Preference of Girls:
1: C , B , E , A , D A: 3 , 5 , 2 , 1 , 4
2: A , B , E , C , D B: 5 , 2 , 1 , 4 , 3
3: D , C , B , A , E C: 4 , 3 , 5 , 1 , 2
4: A , C , D , B , E D: 1 , 2 , 3 , 4 , 5
5: A , B , D , E , C E: 2 , 3 , 4 , 1 , 5
The Greedy Algorithm
Start with Boy 1 and allocate him the “best” possible girl (i.e highest
in his list)
Now allocate to Boy 2 the “best available” girl.
The Greedy Algorithm
Start with Boy 1 and allocate him the “best” possible girl (i.e highest
in his list)
Now allocate to Boy 2 the “best available” girl.
A: 3 , 5 , 2 , 1 , 4
Preference List, E
C: 4 , 3 , 5 , 1 , 2
1: C , B , E , A , D A: 3 , 5 , 2 , 1 , 4
2: A , B , E , C , D B: 5 , 2 , 1 , 4 , 3
3: D , C , B , A , E C: 4 , 3 , 5 , 1 , 2
4: A , C , D , B , E D: 1 , 2 , 3 , 4 , 5
5: A , B , D , E , C E: 2 , 3 , 4 , 1 , 5
A,B,E,C,D B: 5 , 2 , 1 , 4 , 3
3: D , C , B , A , E C: 4 , 3 , 5 , 1 , 2
4: A , C , D , B , E D: 1 , 2 , 3 , 4 , 5
The Greedy Algorithm
Start with Boy 1 and allocate him the “best” possible girl (i.e highest in his
list)
Now allocate to Boy 2 the “best available” girl.
….. Preference List, E
C: 4 , 3 , 5 , 1 , 2
1 -> C 1: C , B , E , A , D A: 3 , 5 , 2 , 1 , 4
2: A , B , E , C , D B: 5 , 2 , 1 , 4 , 3
3: D , C , B , A , E C: 4 , 3 , 5 , 1 , 2
4: A , C , D , B , E D: 1 , 2 , 3 , 4 , 5
5: A , B , D , E , C E: 2 , 3 , 4 , 1 , 5
A,B,E,C,D B: 5 , 2 , 1 , 4 , 3
3: D , C , B , A , E C: 4 , 3 , 5 , 1 , 2
4: A , C , D , B , E D: 1 , 2 , 3 , 4 , 5
The Greedy Algorithm
Start with Boy 1 and allocate him the “best” possible girl (i.e highest in his
list)
Now allocate to Boy 2 the “best available” girl.
….. Preference List, E
C: 4 , 3 , 5 , 1 , 2
1 -> C 1: C , B , E , A , D A: 3 , 5 , 2 , 1 , 4
2 -> A 2: A , B , E , C , D
3: D , C , B , A , E
B: 5 , 2 , 1 , 4 , 3
C: 4 , 3 , 5 , 1 , 2
4: A , C , D , B , E D: 1 , 2 , 3 , 4 , 5
5: A , B , D , E , C E: 2 , 3 , 4 , 1 , 5
A,B,E,C,D B: 5 , 2 , 1 , 4 , 3
3: D , C , B , A , E C: 4 , 3 , 5 , 1 , 2
4: A , C , D , B , E D: 1 , 2 , 3 , 4 , 5
The Greedy Algorithm
Start with Boy 1 and allocate him the “best” possible girl (i.e highest in his
list)
Now allocate to Boy 2 the “best available” girl.
….. Preference List, E
C: 4 , 3 , 5 , 1 , 2
1 -> C 1: C , B , E , A , D A: 3 , 5 , 2 , 1 , 4
2 -> A 2: A , B , E , C , D
3: D , C , B , A , E
B: 5 , 2 , 1 , 4 , 3
C: 4 , 3 , 5 , 1 , 2
3 -> D 4: A , C , D , B , E D: 1 , 2 , 3 , 4 , 5
5: A , B , D , E , C E: 2 , 3 , 4 , 1 , 5
A,B,E,C,D B: 5 , 2 , 1 , 4 , 3
3: D , C , B , A , E C: 4 , 3 , 5 , 1 , 2
4: A , C , D , B , E D: 1 , 2 , 3 , 4 , 5
The Greedy Algorithm
Start with Boy 1 and allocate him the “best” possible girl (i.e highest in his
list)
Now allocate to Boy 2 the “best available” girl.
….. Preference List, E
C: 4 , 3 , 5 , 1 , 2
1 -> C 1: C , B , E , A , D A: 3 , 5 , 2 , 1 , 4
2 -> A 2: A , B , E , C , D
3: D , C , B , A , E
B: 5 , 2 , 1 , 4 , 3
C: 4 , 3 , 5 , 1 , 2
3 -> D 4: A , C , D , B , E D: 1 , 2 , 3 , 4 , 5
5: A , B , D , E , C E: 2 , 3 , 4 , 1 , 5
4 -> B A,B,E,C,D B: 5 , 2 , 1 , 4 , 3
3: D , C , B , A , E C: 4 , 3 , 5 , 1 , 2
4: A , C , D , B , E D: 1 , 2 , 3 , 4 , 5
The Greedy Algorithm
Start with Boy 1 and allocate him the “best” possible girl (i.e highest in his
list)
Now allocate to Boy 2 the “best available” girl.
…..
Preference List, E
1 -> C C: 4 , 3 , 5 , 1 , 2
1: C , B , E , A , D A: 3 , 5 , 2 , 1 , 4
2 -> A 2: A , B , E , C , D B: 5 , 2 , 1 , 4 , 3
3 -> D 3: D , C , B , A , E C: 4 , 3 , 5 , 1 , 2
4: A , C , D , B , E D: 1 , 2 , 3 , 4 , 5
4 -> B 5: A , B , D , E , C E: 2 , 3 , 4 , 1 , 5
A,B,E,C,D B: 5 , 2 , 1 , 4 , 3
5 -> E 3: D , C , B , A , E C: 4 , 3 , 5 , 1 , 2
4: A , C , D , B , E D: 1 , 2 , 3 , 4 , 5
The Greedy Algorithm
Start with Boy 1 and allocate him the “best” possible girl (i.e highest in his list)
Now allocate to Boy 2 the “best available” girl.
…..
Preference List, E
1 -> C C: 4 , 3 , 5 , 1 , 2
2 -> A 1: C , B , E , A , D A: 3 , 5 , 2 , 1 , 4
2: A , B , E , C , D B: 5 , 2 , 1 , 4 , 3
3 -> D 3: D , C , B , A , E C: 4 , 3 , 5 , 1 , 2
4: A , C , D , B , E D: 1 , 2 , 3 , 4 , 5
4 -> B 5: A , B , D , E , C E: 2 , 3 , 4 , 1 , 5
5 -> E A,B,E,C,D B: 5 , 2 , 1 , 4 , 3
3: D , C , B , A , E C: 4 , 3 , 5 , 1 , 2
Is this match stable? 4: A , C , D , B , E D: 1 , 2 , 3 , 4 , 5
The Greedy Algorithm
Start with Boy 1 and allocate him the “best” possible girl (i.e highest in his list)
Now allocate to Boy 2 the “best available” girl.
…..
Preference List, E
1 -> C C: 4 , 3 , 5 , 1 , 2
2 -> A 1: C , B , E , A , D A: 3 , 5 , 2 , 1 , 4
2: A , B , E , C , D B: 5 , 2 , 1 , 4 , 3
3 -> D 3: D , C , B , A , E C: 4 , 3 , 5 , 1 , 2
4: A , C , D , B , E D: 1 , 2 , 3 , 4 , 5
4 -> B 5: A , B , D , E , C E: 2 , 3 , 4 , 1 , 5
5 -> E A,B,E,C,D B: 5 , 2 , 1 , 4 , 3
3: D , C , B , A , E C: 4 , 3 , 5 , 1 , 2
Is this match stable? 4: A , C , D , B , E D: 1 , 2 , 3 , 4 , 5
(Boy 4 , Girl C) form a “rogue couple”.
The Stable Matching Algorithm
Everyday a boy will go and stand in front of the balcony of the girl he likes the most.
Each day a girl will either tell a boy waiting near her balcony to “come back next
day” or “reject”.
Once the girl has “rejected” a boy, the boy crosses the girl off his list of
possibilities.
This continues till all the girls have exactly one boy standing under her balcony.
1: C , B , E , A , D Preference List, E
C: 4 , 3 , 5 , 1 , 2
2: A , B , E , C , D 1: C , B , E , A , D A: 3 , 5 , 2 , 1 , 4
2: A , B , E , C , D B: 5 , 2 , 1 , 4 , 3
3: D , C , B , A , E 3: D , C , B , A , E C: 4 , 3 , 5 , 1 , 2
4: A , C , D , B , E D: 1 , 2 , 3 , 4 , 5
4: A , C , D , B , E 5: A , B , D , E , C E: 2 , 3 , 4 , 1 , 5
A,B,E,C,D B: 5 , 2 , 1 , 4 , 3
5: A , B , D , E , C 3: D , C , B , A , E C: 4 , 3 , 5 , 1 , 2
4: A , C , D , B , E D: 1 , 2 , 3 , 4 , 5
DAY - 2
1: C , B , E , A , D Preference List, E
C: 4 , 3 , 5 , 1 , 2
2: A , B , E , C , D 1: C , B , E , A , D A: 3 , 5 , 2 , 1 , 4
2: A , B , E , C , D B: 5 , 2 , 1 , 4 , 3
3: D , C , B , A , E 3: D , C , B , A , E C: 4 , 3 , 5 , 1 , 2
4: A , C , D , B , E D: 1 , 2 , 3 , 4 , 5
4: A , C , D , B , E 5: A , B , D , E , C E: 2 , 3 , 4 , 1 , 5
A,B,E,C,D B: 5 , 2 , 1 , 4 , 3
5: A , B , D , E , C 3: D , C , B , A , E C: 4 , 3 , 5 , 1 , 2
4: A , C , D , B , E D: 1 , 2 , 3 , 4 , 5
DAY - 3
1: C , B , E , A , D Preference List, E
C: 4 , 3 , 5 , 1 , 2
2: A , B , E , C , D 1: C , B , E , A , D A: 3 , 5 , 2 , 1 , 4
2: A , B , E , C , D B: 5 , 2 , 1 , 4 , 3
3: D , C , B , A , E 3: D , C , B , A , E C: 4 , 3 , 5 , 1 , 2
4: A , C , D , B , E D: 1 , 2 , 3 , 4 , 5
4: A , C , D , B , E 5: A , B , D , E , C E: 2 , 3 , 4 , 1 , 5
A,B,E,C,D B: 5 , 2 , 1 , 4 , 3
5: A , B , D , E , C 3: D , C , B , A , E C: 4 , 3 , 5 , 1 , 2
4: A , C , D , B , E D: 1 , 2 , 3 , 4 , 5
DAY - 4
Preference List, E
A -> 5 C: 4 , 3 , 5 , 1 , 2
1: C , B , E , A , D A: 3 , 5 , 2 , 1 , 4
B -> 2 2: A , B , E , C , D B: 5 , 2 , 1 , 4 , 3
3: D , C , B , A , E C: 4 , 3 , 5 , 1 , 2
C -> 4 4: A , C , D , B , E D: 1 , 2 , 3 , 4 , 5
D -> 3 5: A , B , D , E , C
A,B,E,C,D
E: 2 , 3 , 4 , 1 , 5
B: 5 , 2 , 1 , 4 , 3
E -> 1 3: D , C , B , A , E C: 4 , 3 , 5 , 1 , 2
4: A , C , D , B , E D: 1 , 2 , 3 , 4 , 5
i. SMA terminates.
ii. Terminates quickly.
iii. Everybody gets married / paired.
iv. No rogue couple (stability).
Theorem 3
SMA terminates is ≤ 𝑵𝑵𝟐𝟐 + 1 days.
Proof:
Every day (i.e in every iteration of the algorithm) at least one boy crosses out one girl from his list.
Since there are N girls & N boys (thereby N lists), so there are at max 𝑁𝑁 2 cross outs.
Proof:
Assume that there is a boy B who is NOT married at the end.
⇒B has been rejected by every girl.
⇒ Every girl is married.
⇒ Every boy is married (since we have equal number of boys & girls)
⇒ B is married (contradiction)
Theorem 5
SMA produces Stable matching.