0% found this document useful (0 votes)
88 views

Dripto Bakshi - Lecture Slides - Stable Matching Algorithm

The document discusses the stable matching problem, which involves matching two populations (X and Y) based on each member's preferences. It provides examples like marriage markets and labor markets. A stable matching is one without "rogue couples" who both prefer each other over their assigned matches. The document proposes a greedy algorithm to find a stable matching in bipartite graphs, where it sequentially assigns each member of X their highest remaining preference in Y. It demonstrates the algorithm on an example market with 5 boys and 5 girls.

Uploaded by

Rupinder Goyal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
88 views

Dripto Bakshi - Lecture Slides - Stable Matching Algorithm

The document discusses the stable matching problem, which involves matching two populations (X and Y) based on each member's preferences. It provides examples like marriage markets and labor markets. A stable matching is one without "rogue couples" who both prefer each other over their assigned matches. The document proposes a greedy algorithm to find a stable matching in bipartite graphs, where it sequentially assigns each member of X their highest remaining preference in Y. It demonstrates the algorithm on an example market with 5 boys and 5 girls.

Uploaded by

Rupinder Goyal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 47

THE STABLE MATCHING ALGORITHM

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?
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)
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 !
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.
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.

 In Matching 1: Hrithik & Kangana form a “rogue couple”


 Matching 2 has no rogue couples.
Stable Matching
 Perfect Matching: A matching where all individuals are paired is
called a perfect matching.

 Stable Matching: A perfect matching is said to be stable if there are


no “rogue couples”

 In the example: Matching 2 is “stable”.


Example

SRK
2 1
1 1
3
1
1
1 2
2 1
1
SALMAN 1 1 AAMIR

3 3
1 1
JOHN
Preferences:

SRK: Aamir , Salman , John


Salman: SRK , Aamir , John
Aamir: Salman , SRK , John
John’s preferences are inconsequential.
Theorem 1
There does NOT exist a stable match.
Theorem 1
There does NOT exist a stable match.

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

If we only allow opposite gender relationships


i.e the representative graph is bipartite (with the set of girls & the set
of boys being the two partitions) then a stable match necessarily exists.
What Next?

 Proof of Existence of a stable match.

 Algorithm to find the stable match.

 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.

 Initially all girls are present in every boy’s list.


DAY - 1

A -> 2 , 4 , 5 Preference List, E


C: 4 , 3 , 5 , 1 , 2
B -> 1: C , B , E , A , D A: 3 , 5 , 2 , 1 , 4
2: A , B , E , C , D B: 5 , 2 , 1 , 4 , 3
C -> 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
D -> 3 5: A , B , D , E , C E: 2 , 3 , 4 , 1 , 5
A,B,E,C,D B: 5 , 2 , 1 , 4 , 3
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 Updated List

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

A -> 5 Preference List, E


C: 4 , 3 , 5 , 1 , 2
B -> 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
C -> 1 , 4 3: D , C , B , A , E C: 4 , 3 , 5 , 1 , 2
4: A , C , D , B , E D: 1 , 2 , 3 , 4 , 5
D -> 3 5: A , B , D , E , C E: 2 , 3 , 4 , 1 , 5
A,B,E,C,D B: 5 , 2 , 1 , 4 , 3
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 Updated List

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

A -> 5 Preference List, E


C: 4 , 3 , 5 , 1 , 2
B -> 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
C -> 4 3: D , C , B , A , E C: 4 , 3 , 5 , 1 , 2
4: A , C , D , B , E D: 1 , 2 , 3 , 4 , 5
D -> 3 5: A , B , D , E , C E: 2 , 3 , 4 , 1 , 5
A,B,E,C,D B: 5 , 2 , 1 , 4 , 3
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 Updated List

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

 This is where the algorithm terminates.


 Is the match stable?
Stability Test

Preference of Boys: Preference of Girls: Matching


1: C , B , E , A , D A: 3 , 5 , 2 , 1 , 4 A -> 5
2: A , B , E , C , D B: 5 , 2 , 1 , 4 , 3 B -> 2
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 E: 2 , 3 , 4 , 1 , 5 E -> 1
Desirable Properties of SMA!!

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.

⇒ Every day is characterized by at least ONE cross out.

Since there are N girls & N boys (thereby N lists), so there are at max 𝑁𝑁 2 cross outs.

=> SMA NOT terminating in 𝑁𝑁 2 + 1 days is an impossibility.


Theorem 4
Everybody gets married / paired.

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.

Proof: Let’s say there exists a rogue couple (Johnny , Amber).

CASE –I: Amber rejected Johnny


⇒Amber must have had a more preferred suitor serenading her.
⇒ Amber prefers her husband over Johnny

CASE – II: Johnny never serenaded Amber


⇒Johnny never had to come down to Amber in his Pref. List.
⇒ Johnny prefers his wife over Amber

You might also like