Design and Analysis of Algorithms
Lecture 6
Stable Matching Algorithm and Applications
1
CS345
Recap from the last Lecture
2
Interpolation
There is a polynomial
with ’s unknown.
Given: the following (point, value) representation of :
Aim: To compute ’s .
3
{}
4
Interpolation
Polynomial Interpolation = Polynomial evaluation
Can you guess the polynomial whose evaluation
will help solve polynomial interpolation ?
Make an obvious guess.
Interpolation
Solution:
Define a polynomial
, where .
Evaluate on .
What is ?
5
Homework:
Can you guess what is relation
between and ?
• It was very disheartening to see that only a handful of students attempted
the homework.
• Please attempt each homework sincerely. It is for your own benefit.
• If you are not able to do the homework, you may send email to the
instructor 1 day in advance for a short meeting (avoid holidays and week-
ends).
6
Real challenge
of multiple merit lists
7
Fairness
8
Merit list
q
p q p
Ram
Mohan
Choice list of Mohan
of programme q
Ram Mohan
How to tackle Multiple Merit Lists using
“Single Merit list algorithm”
9
A common man’s algorithm
 Allocation_IIT();
 Allocation_NIT();
;
While ( )
{ For each do
{ is asked to choose between the two choices;
The preference list of is trimmed accordingly;
}
 Allocation_IIT();
 Allocation_NIT();
;
}
10
Round 
Round  Round +
Round
and )
Homework (not for exam): Prove that the algorithm outputs a fair seat allocation.
Multiple merit lists
IIT
NIT
ARCH
11
Merit Lists
A
B
C
Choice Lists
IIT
NIT
ARCH
IIT
NIT
ARCH
IIT
NIT
ARCH
Allocation Allocation Allocation
IIT NIT
ARCH
NIT
NIT
IIT ARCH
ARCH IIT
C B A
A C B
B A C
C
A
B
A
B
C
B
C
A
A B C
Candidate Optimal
Candidate Pessimal
The Stable Marriage Problem
12
Stable Marriage Problem
• prefers to
• prefers to
Definition:
A marriage is said to be stable if there is no unstable pair in the society.
13
𝑤𝑙
𝑤𝑖
𝑚𝑘
𝑚𝑗
divorce
divorce
(, ) : an unstable pair
Meaning of unstability
Stable Marriage Problem
• : set of men
• : set of women
For each man ,
: a preference list of all women
For each woman ,
: a preference list of all men
Aim: To compute a stable marriage.
14
Algorithm for Stable Marriage
Man proposes, God disposes
15
1962, David Gale and Lloyd Shapley
Woman
Nobel Prize in Economic Sciences, 2012
We designed an iterative algorithm in the last class
based on these rules.
• A man proposes in the decreasing order of preference.
• Once rejected by a woman, the man never proposes to her again.
• A woman, if single, accepts a proposal.
• A woman, if engaged, accepts a proposal from a man if she prefers him to
her current partner.
16
Rule for Men
Rule for Women
GaleShapley(, )
(Proof of stability)
Lemma :
If prefers to
 prefers to .
17
𝑤𝑙
𝑤𝑖
𝑚𝑘
𝑚𝑗
Each new engagement gives a woman a better partner (mate).
There is no unstable pair in the marriage.
The key observation :
How to restate it so that
we can prove it easily ?
Consider the pair (, )
If prefers to , nothing to be done 
Lemma :
If prefers to
 prefers to .
Proof: (a sketch (the details emerged from the interaction in the class))
must have proposed to .
At the moment of the proposal, was either engaged or single.
If was single, would have accepted the offer at that time but rejected later.
But a woman rejects her present mate only when she gets a better mate.
So would have surely got a better mate than .
Since the mate of a woman only improves in future rounds, would indeed be preferred to .
If was engaged, …fill in the details along similar lines as stated above…
18
𝑤𝑙
𝑤𝑖
𝑚𝑘
𝑚𝑗
GaleShapley(, )
(Proof of stability)
The following slide gives
the steps of the analysis.
19
𝑤𝑙
𝑤𝑖
𝑚𝑘
𝑚𝑗
𝑚𝑡
𝑚𝑝
GaleShapley(, )
(Proof of stability)
Lemma : If prefers to
 prefers to .
20
𝑤𝑙
𝑤𝑖
𝑚𝑘
𝑚𝑗
GaleShapley(, )
Theorem:
GaleShapley(, ) indeed computes a stable marriage.
Question : Does there exist a unique stable marriage ?
Answer: No.
Homework:
Give an example graph with multiple stable matchings.
Gale Shapley Algorithm
Theorem:
There cannot exist any other stable matching
22
Man Optimal
Woman pessimal
Man
proposing
that matches a man to a better woman.
Gale Shapley Algorithm
23
Man Pessimal
Woman Optimal
Woman
proposing
Gale Shapley Algorithm
24
Women Men
𝑤1
𝑤2
𝑤3
𝑤𝑛
𝑤𝑖
𝑚1
𝑚2
𝑚3
𝑚𝑗
𝑚𝑛
Can you think of using this algorithm to solve the
problem of joint seat allocation ?
Gale Shapley Algorithm
25
Programs Men
𝑃1
𝑃2
𝑃3
𝑃𝑛
𝑃𝑖
𝑚1
𝑚2
𝑚3
𝑚𝑗
𝑚𝑛
Gale Shapley Algorithm
26
Programs Candidates
𝑃1
𝑃2
𝑃3
𝑃𝑛
𝑃𝑖
𝑐1
𝑐2
𝑐3
𝑐 𝑗
𝑐𝑚
Deferred Acceptance Algorithm
Preference lists
Merit lists
Unstability
Unfairness
27
Programs Candidates
𝑃1
𝑃2
𝑃3
𝑃𝑛
𝑃𝑖
𝑐1
𝑐2
𝑐3
𝑐 𝑗
𝑐𝑚
Deferred Acceptance Algorithm
Algorithms
28
Common man’s algorithm Software Industry’s algorithm Deferred Acceptance algorithm
Gale Shapley
algorithm
Candidate proposing
Programme proposing
Programme proposing
Limited rounds
Candidate Optimal
Candidate Pessimal
Candidate Pessimal
Merits of
Deferred Acceptance Algorithm
• Any number of merit lists
• Candidate optimality guaranteed
• Efficient Algorithm
29
Joint Seat Allocation
Deferred Acceptance
Algorithm
Many complex Business rules
of admissions
• Affirmative action rules
• Freeze/Float/Slide/withdraw
• Supernumerary Seats for Female Candidates [’18 - ]
– No increase in male seats
– No adverse affect on chances for the male candidates
– Create supernumerary seats (not reservation at all !)
Impact of Joint Seat Allocation
No. of Seats Vacancies
Vacancies in IITs
𝟓𝟖𝟕
𝟑𝟎𝟖
𝟏𝟗𝟎
𝟏𝟗𝟖
Impact of Joint Seat Allocation
• A single vacancy removed 
many candidates getting better program (due to cascading effect)
No. of Candidates getting better Seats
𝟏𝟖𝟗𝟎
𝟏𝟕𝟔𝟕
𝟑𝟔𝟕𝟐 𝟏↔𝟑𝟎𝟎
Algorithms do have great impact in real world …
33
Impact of Joint Seat Allocation
• INFORMS J. Appl. Anal., 49(5) 338-354 (2019)
The above research paper is available on the homepage of the
instructor.
Read it to see the role of algorithms in your journey to IITK 
Not meant for exam or quizzes 
Centralized Admissions for Engineering Colleges in India
S. Baswana, P. P. Chakrabarti, S. Chandran, Y. Kanoria, U. Patange
Gayle Shapley Algorithm
Proof of Man optimality
35
Man-Proposing version
Gale Shapley Algorithm
36
Women Men
𝑤1
𝑤2
𝑤3
𝑤𝑛
𝑤𝑖
𝑚1
𝑚2
𝑚3
𝑚𝑗
𝑚𝑛
Let be the matching produced by GS algorithm.
Let be any other stable matching.
Theorem (Man Optimality):
There does not exist any man such that
precedes in the preference list of .
37
At the end of the th iteration,
the set of men matched by GS algorithm.
38
Theorem (Man Optimality):
There does not exist any man such that
precedes in the preference list of .
Theorem (Man Optimality): At the end of the th iteration,
There does not exist any man such that
precedes in the preference list of .
39
Theorem (Man Optimality): At the end of the th iteration,
There does not exist any man such that
precedes in the preference list of .
𝒈
𝒇 𝒊
1st Iteration
40
Theorem (Man Optimality): At the end of the th iteration,
There does not exist any man such that
precedes in the preference list of .
𝒈
𝒇 𝟏
th iteration:
41
Theorem (Man Optimality): At the end of the th iteration,
There does not exist any man such that
precedes in the preference list of .
𝒇 𝒊 −𝟏
𝑚 𝑗
Execution of th iteration:
𝒈
42
Theorem (Man Optimality): At the end of the th iteration,
There does not exist any man such that
precedes in the preference list of .
𝒇 𝒊
𝑚 𝑗
Execution of th iteration:
𝑤 𝑗
𝑤 𝑗′ 𝑚𝑗
𝒈
Homework:
Prove that if prefers to , must be unstable.

OPERATING SYSTEMS AND LINUX1OPERATING SYSTEMS AND LINUX1

  • 1.
    Design and Analysisof Algorithms Lecture 6 Stable Matching Algorithm and Applications 1 CS345
  • 2.
    Recap from thelast Lecture 2
  • 3.
    Interpolation There is apolynomial with ’s unknown. Given: the following (point, value) representation of : Aim: To compute ’s . 3 {}
  • 4.
    4 Interpolation Polynomial Interpolation =Polynomial evaluation Can you guess the polynomial whose evaluation will help solve polynomial interpolation ? Make an obvious guess.
  • 5.
    Interpolation Solution: Define a polynomial ,where . Evaluate on . What is ? 5 Homework: Can you guess what is relation between and ?
  • 6.
    • It wasvery disheartening to see that only a handful of students attempted the homework. • Please attempt each homework sincerely. It is for your own benefit. • If you are not able to do the homework, you may send email to the instructor 1 day in advance for a short meeting (avoid holidays and week- ends). 6
  • 7.
  • 8.
    Fairness 8 Merit list q p qp Ram Mohan Choice list of Mohan of programme q Ram Mohan
  • 9.
    How to tackleMultiple Merit Lists using “Single Merit list algorithm” 9
  • 10.
    A common man’salgorithm  Allocation_IIT();  Allocation_NIT(); ; While ( ) { For each do { is asked to choose between the two choices; The preference list of is trimmed accordingly; }  Allocation_IIT();  Allocation_NIT(); ; } 10 Round  Round  Round + Round and ) Homework (not for exam): Prove that the algorithm outputs a fair seat allocation.
  • 11.
    Multiple merit lists IIT NIT ARCH 11 MeritLists A B C Choice Lists IIT NIT ARCH IIT NIT ARCH IIT NIT ARCH Allocation Allocation Allocation IIT NIT ARCH NIT NIT IIT ARCH ARCH IIT C B A A C B B A C C A B A B C B C A A B C Candidate Optimal Candidate Pessimal
  • 12.
  • 13.
    Stable Marriage Problem •prefers to • prefers to Definition: A marriage is said to be stable if there is no unstable pair in the society. 13 𝑤𝑙 𝑤𝑖 𝑚𝑘 𝑚𝑗 divorce divorce (, ) : an unstable pair Meaning of unstability
  • 14.
    Stable Marriage Problem •: set of men • : set of women For each man , : a preference list of all women For each woman , : a preference list of all men Aim: To compute a stable marriage. 14
  • 15.
    Algorithm for StableMarriage Man proposes, God disposes 15 1962, David Gale and Lloyd Shapley Woman Nobel Prize in Economic Sciences, 2012
  • 16.
    We designed aniterative algorithm in the last class based on these rules. • A man proposes in the decreasing order of preference. • Once rejected by a woman, the man never proposes to her again. • A woman, if single, accepts a proposal. • A woman, if engaged, accepts a proposal from a man if she prefers him to her current partner. 16 Rule for Men Rule for Women
  • 17.
    GaleShapley(, ) (Proof ofstability) Lemma : If prefers to  prefers to . 17 𝑤𝑙 𝑤𝑖 𝑚𝑘 𝑚𝑗 Each new engagement gives a woman a better partner (mate). There is no unstable pair in the marriage. The key observation : How to restate it so that we can prove it easily ? Consider the pair (, ) If prefers to , nothing to be done 
  • 18.
    Lemma : If prefersto  prefers to . Proof: (a sketch (the details emerged from the interaction in the class)) must have proposed to . At the moment of the proposal, was either engaged or single. If was single, would have accepted the offer at that time but rejected later. But a woman rejects her present mate only when she gets a better mate. So would have surely got a better mate than . Since the mate of a woman only improves in future rounds, would indeed be preferred to . If was engaged, …fill in the details along similar lines as stated above… 18 𝑤𝑙 𝑤𝑖 𝑚𝑘 𝑚𝑗 GaleShapley(, ) (Proof of stability) The following slide gives the steps of the analysis.
  • 19.
  • 20.
    GaleShapley(, ) (Proof ofstability) Lemma : If prefers to  prefers to . 20 𝑤𝑙 𝑤𝑖 𝑚𝑘 𝑚𝑗
  • 21.
    GaleShapley(, ) Theorem: GaleShapley(, )indeed computes a stable marriage. Question : Does there exist a unique stable marriage ? Answer: No. Homework: Give an example graph with multiple stable matchings.
  • 22.
    Gale Shapley Algorithm Theorem: Therecannot exist any other stable matching 22 Man Optimal Woman pessimal Man proposing that matches a man to a better woman.
  • 23.
    Gale Shapley Algorithm 23 ManPessimal Woman Optimal Woman proposing
  • 24.
    Gale Shapley Algorithm 24 WomenMen 𝑤1 𝑤2 𝑤3 𝑤𝑛 𝑤𝑖 𝑚1 𝑚2 𝑚3 𝑚𝑗 𝑚𝑛 Can you think of using this algorithm to solve the problem of joint seat allocation ?
  • 25.
    Gale Shapley Algorithm 25 ProgramsMen 𝑃1 𝑃2 𝑃3 𝑃𝑛 𝑃𝑖 𝑚1 𝑚2 𝑚3 𝑚𝑗 𝑚𝑛
  • 26.
    Gale Shapley Algorithm 26 ProgramsCandidates 𝑃1 𝑃2 𝑃3 𝑃𝑛 𝑃𝑖 𝑐1 𝑐2 𝑐3 𝑐 𝑗 𝑐𝑚 Deferred Acceptance Algorithm Preference lists Merit lists Unstability Unfairness
  • 27.
  • 28.
    Algorithms 28 Common man’s algorithmSoftware Industry’s algorithm Deferred Acceptance algorithm Gale Shapley algorithm Candidate proposing Programme proposing Programme proposing Limited rounds Candidate Optimal Candidate Pessimal Candidate Pessimal
  • 29.
    Merits of Deferred AcceptanceAlgorithm • Any number of merit lists • Candidate optimality guaranteed • Efficient Algorithm 29 Joint Seat Allocation Deferred Acceptance Algorithm
  • 30.
    Many complex Businessrules of admissions • Affirmative action rules • Freeze/Float/Slide/withdraw • Supernumerary Seats for Female Candidates [’18 - ] – No increase in male seats – No adverse affect on chances for the male candidates – Create supernumerary seats (not reservation at all !)
  • 31.
    Impact of JointSeat Allocation No. of Seats Vacancies Vacancies in IITs 𝟓𝟖𝟕 𝟑𝟎𝟖 𝟏𝟗𝟎 𝟏𝟗𝟖
  • 32.
    Impact of JointSeat Allocation • A single vacancy removed  many candidates getting better program (due to cascading effect) No. of Candidates getting better Seats 𝟏𝟖𝟗𝟎 𝟏𝟕𝟔𝟕 𝟑𝟔𝟕𝟐 𝟏↔𝟑𝟎𝟎
  • 33.
    Algorithms do havegreat impact in real world … 33
  • 34.
    Impact of JointSeat Allocation • INFORMS J. Appl. Anal., 49(5) 338-354 (2019) The above research paper is available on the homepage of the instructor. Read it to see the role of algorithms in your journey to IITK  Not meant for exam or quizzes  Centralized Admissions for Engineering Colleges in India S. Baswana, P. P. Chakrabarti, S. Chandran, Y. Kanoria, U. Patange
  • 35.
    Gayle Shapley Algorithm Proofof Man optimality 35 Man-Proposing version
  • 36.
    Gale Shapley Algorithm 36 WomenMen 𝑤1 𝑤2 𝑤3 𝑤𝑛 𝑤𝑖 𝑚1 𝑚2 𝑚3 𝑚𝑗 𝑚𝑛
  • 37.
    Let be thematching produced by GS algorithm. Let be any other stable matching. Theorem (Man Optimality): There does not exist any man such that precedes in the preference list of . 37
  • 38.
    At the endof the th iteration, the set of men matched by GS algorithm. 38 Theorem (Man Optimality): There does not exist any man such that precedes in the preference list of . Theorem (Man Optimality): At the end of the th iteration, There does not exist any man such that precedes in the preference list of .
  • 39.
    39 Theorem (Man Optimality):At the end of the th iteration, There does not exist any man such that precedes in the preference list of . 𝒈 𝒇 𝒊
  • 40.
    1st Iteration 40 Theorem (ManOptimality): At the end of the th iteration, There does not exist any man such that precedes in the preference list of . 𝒈 𝒇 𝟏
  • 41.
    th iteration: 41 Theorem (ManOptimality): At the end of the th iteration, There does not exist any man such that precedes in the preference list of . 𝒇 𝒊 −𝟏 𝑚 𝑗 Execution of th iteration: 𝒈
  • 42.
    42 Theorem (Man Optimality):At the end of the th iteration, There does not exist any man such that precedes in the preference list of . 𝒇 𝒊 𝑚 𝑗 Execution of th iteration: 𝑤 𝑗 𝑤 𝑗′ 𝑚𝑗 𝒈 Homework: Prove that if prefers to , must be unstable.