You are on page 1of 61

Advanced Algorithm Analysis

CSC683

Instructor
Nadir Shah
Associate Professor
COMSATS University Islamabad, Wah Campus
nadir@ciitwah.edu.pk

1
Note
 Syllabus given to the CR, will be updated
 Rules and Regulation
 CR is responsible for
• class arrangement
• Class Makeup
• Any other activity
 Attendance 80%
 Strong programming and mathematics background
is desired
 Students have attended a fundamental course
related to Algorithms, Data Structure, and one
major course

2
Course Assessment
 Quizzes, Assignments, mid exam and final exam , class project
 Class project has 20 marks will be accommodated in the final paper
• Simulation
• Development *
• Mathematical analysis

3
Performance Evaluation
 Mathematical analysis (prefered)
• Algorithmic analysis
• Probability and statistics
• Formal Methods
 Simulation(Recommended)
• For Networking, (NS-3, Mininet, Opnet++)
 Test bed
• For Networking (SDN with ODL available)
 Experiments
• In production network(if you can afford)

4
Importance of Algorithm Studies
An example of Algorithm
• List of values are A={20, 30, 31, 33, 45, 100, 500, 5001, 1000, 1001}
• Find the value of 1001? 10th step,
• Binary search
• Length 10, mid 5, A[5]=45
• Length 5, mid 8, A[8]= 5001
• Length 2, mid 8, A [9]= 1000
• A[10]=1001

Network Layer 4-6


Another Example
Graph abstraction of the network
5

v 3 w
2 5
u 2 1 z
3
1 2
x 1
y
graph: G = (N,E)

N = set of routers = { u, v, w, x, y, z }

E = set of links ={ (u,v), (u,x), (v,x), (v,w), (x,w), (x,y), (w,y), (w,z), (y,z) }

aside: graph abstraction is useful in other network contexts, e.g.,


P2P, where N is set of peers and E is set of TCP connections

Network Layer: Control Plane 5-8


Graph abstraction: costs
5
c(x,x’) = cost of link (x,x’)
3 e.g., c(w,z) = 5
v w 5
2
u cost could always be 1, or
2
3
1 z inversely related to bandwidth,
1 2 or inversely related to
x 1
y
congestion

cost of path (x1, x2, x3,…, xp) = c(x1,x2) + c(x2,x3) + … + c(xp-1,xp)

• key question: what is the least-cost path between u and z ?


• Brute-force algorithm….
• Many steps
• Not correct
Network Layer: Control Plane 5-9
Dijkstra’s algorithm: example
D(v) D(w) D(x) D(y) D(z)
Step N' p(v) p(w) p(x) p(y) p(z)
0 u 7,u 3,u 5,u ∞ ∞ D(w)=3
1 uw 6,w 5,u 11, w ∞
2 uwx 6,w 11,w 14,x
3 uwxv 10,v 14,x
4 uwxvy 12,y
5 uwxvyz x
9

notes: 5
4
7
 Step5, construct forwarding
table 8
Destination| next hope| distance 3 w z
u y
w | w |3 2
x |x |5 3
V | w |6 7 4
Y |w | 10 v
z |w | 12 Network Layer: Control Plane 5-10
Dijsktra’s algorithm
1 Initialization:
2 N' = {u}
3 for all nodes v
4 if v adjacent to u
5 then D(v) = c(u,v)
6 else D(v) = ∞
7
8 Loop
9 find w not in N' such that D(w) is a minimum
10 add w to N'
11 update D(v) for all v adjacent to w and not in N' :
12 D(v) = min( D(v), D(w) + c(w,v) )
13 /* new cost to v is either old cost to v or known
14 shortest path cost to w plus cost from w to v */
15 until all nodes in N'

Network Layer: Control Plane 5-11


Dijkstra’s algorithm: another example
Step N' D(v),p(v) D(w),p(w) D(x),p(x) D(y),p(y) D(z),p(z)
0 u 2,u 5,u 1,u ∞ ∞
1 ux 2,u 4,x 2,x ∞
2 uxy 2,u 3,y 4,y
3 uxyv 3,y 4,y
4 uxyvw 4,y
5 uxyvwz
5
3
v w 5
2
u 2 1 z
3
1 2
x 1
y

* Check out the online interactive exercises for more


examples: http://gaia.cs.umass.edu/kurose_ross/interactive/ Network Layer: Control Plane 5-12
1.
STABLE

Mstable matching
ATCHING
problem
‣ Gale–Shapley
algorithm
‣ hospital optimality
‣ context

Lecture slides by Kevin Wayne


Copyright © 2005 Pearson-Addison Wesley
h t tp:// www.cs . p r i n c e t o n . e d u / ~w a yn e /
klein b e rg - t ardos

Last updated on 2/5/18 3:54 PM


1.
STABLE

Mstable matching
ATCHING
problem
‣ Gale–Shapley
algorithm
‣ hospital optimality
‣ context

SECTION 1.1
The STABLE MATCHING Problem
• originated, in part, in 1962, by David Gale and Lloyd Shapley,
• “Could one design a college admissions process, or a job recruiting process, that was self-enforcing?”
• Suppose, Job recruiting process for summer internship
• Companies and applicants
• Its crux is the interplay between two different types of parties: companies (the employers) and students (the
applicants).
• Preference ordering …
• What could be wrong????
• Raj accepted a job from ClueNet
• Then WebExodux offers Raj the job, and Raj prefers WebExodus to ClueNet…
• What will Raj do???
• Raj retracts ClueNet offer and joins WebExodus, so
• ClueNet offers to another applicant, Shah, and Shah retracts Bablesoft’s offer to join ClueNet,
• So on….. And situation gets out of control…..
• Chelsa, Raj’s friend, comes to know about this, and destined to Bablesoft, says that Chelsa will join Bablesoft
• Bablesoft will find some way to hire Chelsa instead of Shah
• generate a lot of chaos, and many people— both applicants and employers—can end up unhappy with the process
as well as the outcome.
• Why??
• Self-interest…
The STABLE MATCHING Problem

• Solution
• Self-enforcing
• Self-interest itself prevents offers from being retracted and redirected
• Another student, Asad, accepted the ClueNet offer, and calls up WebExodus, and reveals its interest and the job.
• What should be the case?
• WebExodus does not accept it
• Asad does not join it
Formal STABLE MATCHING Problem
• Given a set of preferences among employers and applicants, can we assign applicants to employers so
• that for every employer E, and every applicant A who is not scheduled to work for E, at least one of the following two
things is the case? Is stable
• (i) E prefers every one of its accepted applicants to A; or
• (ii) A prefers her current situation over working for employer E.
• Gale and Shapley proceeded to develop a striking algorithmic solution to this problem
• Formulating the Problem
• Designing the Algorithm
• Analyzing the Algorithm
Formulating the Research Problem
• Formulating the Research Problem
• make the problem as clean as possible
• For example,
• A simple, each of n applicants applies to each of n companies, and each company wants to accept a single applicant
• A company hires more than 01 applicant, An applicant gets job in a single company
• No. of applicant >> No. of available jobs
• An applicant does not apply to every company
• a system by which each of n men and n women can end up getting married: our problem naturally has the analogue
• of two “genders”—the applicants and the companies
• set M = {m1, . . . ,mn} of n men, set W = {w1, . . . , wn} of n women.
• M ×W = {(m, w)| m ∈ M and w ∈W}
• A matching S is a set of ordered pairs, each from M ×W, with the property that each member of M and each member of
W appears in at most one pair in S.
• A perfect matching S’ is a matching with the property that each member of M and each member of W appears in exactly
one pair in S’
• add the notion of preferences
• Each man m ∈M ranks all the women; we will say that m prefers w to w’ if m ranks w higher than w’
• What can be wrong, as per the Recruiting process
Formulating the Research Problem

Our goal, then, is a set of marriages


with no instabilities. We’ll say that
a matching S is stable if (i) it is perfect,
and (ii) there is no instability with
respect to S. Two questions spring
immediately to mind:
. Does there exist a stable matching for
every set of preference lists?
. Given a set of preference lists, can we
efficiently construct a stable
matching if there is one?
Formulating the Research Problem

• Some examples
• First, preference list
• m prefers w to w’.
• m’ prefers w to w’.  Complete agreement,
• w prefers m to m’.  (m, w) and (m’ w’), unique stable
• w’ prefers m to m’. matching
 (m’, w) and (m, w’) unstable because
both m and w wants to leave and join
each other

 Second preference list  Contradiction between male and female


 m prefers w to w’.  Two stable matching
 m’ prefers w’ to w.  (m, w) and (m’, w’), both men are
 w prefers m’ to m. happy
 w’ prefers m to m’.  (m’, w) and (m, w’)
Formal STABLE MATCHING Problem
• Given a set of preferences among employers and applicants, can we assign applicants to employers so
• that for every employer E, and every applicant A who is not scheduled to work for E, at least one of the following two
things is the case? Is stable
• (i) E prefers every one of its accepted applicants to A; or
• (ii) A prefers her current situation over working for employer E.
• Gale and Shapley proceeded to develop a striking algorithmic solution to this problem
• Formulating the Problem
• Designing the Algorithm
• There exists a stable matching?
• Can we have an efficient algorithm to construct a stable matching
• Analyzing the Algorithm
Designing the Algorithm
• Some basic steps
• First, initially everyone is unmarried
• Suppose unmarried m chooses w
of highest ranks in his preference
list, and proposes (not
married)/engaged, why?
• Because m’ who is preferred by
w
• w also cannot reject m, because
later on may remain unsuccessful
• Second, intermediat, some engaged
and others are free
• A free m chooses w of highest
rank in his preference list (not
proposed yet) , so there are
either
• If w is free, (m, w) engaged,
• (m’, w) engaged,
• w prefers m over m’, then
(m, w) engaged and m’
free
• Otherwise,(m’, w)
engaged and m is free
• Third, the algorithm terminates if no
one is free
Formal STABLE MATCHING Problem
• Given a set of preferences among employers and applicants, can we assign applicants to employers so
• that for every employer E, and every applicant A who is not scheduled to work for E, at least one of the following two
things is the case? Is stable
• (i) E prefers every one of its accepted applicants to A; or
• (ii) A prefers her current situation over working for employer E.
• Gale and Shapley proceeded to develop a striking algorithmic solution to this problem
• Formulating the Problem
• Designing the Algorithm
• There exists a stable matching?
• Can we have an efficient algorithm to construct a stable matching
• Analyzing the Algorithm
• It returns a stable matching or even perfect matching
• Let us prove it
Analyzing the Algorithm

• First from w perspective


• (1.1) w remains engaged from
the point at which she receives
her first proposal; and the
sequence of partners to which
she is engaged gets better and
better (in terms of her
preference list).

• Second from m perspective


• (1.2) The sequence of women
to whom m proposes gets
worse and worse (in terms of
his preference list).
• Third, a bound on the maximum
number of iterations needed for
termination.
• (1.3) The G-S algorithm
terminates after at most n2
iterations of the While loop.
Analyzing the Algorithm

• Proof
• Third, a bound on the maximum
number of iterations needed for
termination.
• (1.3) The G-S algorithm
terminates after at most n2
iterations of the While loop.
• to find a measure of progress in
each iteration of While Loop
• if we let P(t) denote the set of
pairs (m, w) such that m has
proposed to w by the end of
iteration t, we see that for all t, the
size of P(t + 1) is strictly greater
than the size of P(t).
• only n2 possible pairs of men and
women in total, so the value of P(·)
can increase at most n2 times over
the course of the algorithm. It
follows that there can be at most
n2 iterations
Analyzing the Algorithm

• Proof
• Finds perfect matching
• (1.4) If m is free at some point in
the execution of the algorithm,
then there is a woman to whom he
has not yet proposed.
• Proof.
• Suppose there comes a point when
m is free but has already proposed
to every woman.
• Then by (1.1), each of the n
women is engaged at this point in
time. Since the set of engaged
pairs forms a matching, there must
also be n engaged men at this
point in time. But there are only n
men total, and m is not engaged,
so this is a contradiction.
Analyzing the Algorithm

• Proof
• Finds perfect matching
• (1.5) The set S returned at
termination is a perfect matching.
• Proof. The set of engaged pairs
always forms a matching. Let us
suppose that the algorithm
terminates with a free man m. At
termination, it must be the case
that m had already proposed to
every woman for, otherwise the
While loop would not have exited.
But this contradicts (1.4), which
says that there cannot be a free
man who has proposed to every
woman.
Analyzing the Algorithm
• Proof
• Finds stable matching
• (1.6) Consider an execution of the G-S
algorithm that returns a set of pairs S. The
set S is a stable matching
• in (1.5), that S is a perfect matching
• assume that there is an instability with
respect to S with a pair (m, w) and (m’,
w’), with the properties that
• m prefers w’ to w, and
• W’ prefers m to m’.
• m’s last proposal was, by definition,
to w
• m has proposed w’ before w?
• If not, then w is on higher rank in
m’s preference list than w’,
contradicting our assumption m
prefers w’ over w.
• If yes, then w’ rejected m for her
preference m’’,
• (m’’=m’, w’) it is ok
contradiction to w’ prefers
m to m’ or
• W’ prefers her final partner
m’ to m’’; contradicting to
w’ prefers m to m’
• Our assumption is wrong, which means
S is stable matching
Extension

 Second preference list


 m prefers w to w’.
 m’ prefers w’ to w.
 w prefers m’ to m.
 w’ prefers m to m’
 . Two stable matching
 (m, w) and (m’, w’), both men are
happy, is attainable
 (m’, w) and (m, w’) is not attainable
 because men proposes
 If women proposes, than women will be
happy attainable.
 Cumbersome situation of a large scale
problem
 Unfairness in G-S algorithm
 we are allowed to choose any free man to
make the next proposal
 Different choices leads to different
execution of the algorithm
 Do all executions of the G-S algorithm
yield the same matching? If G-S, yes, let
us prove it in next slides
 an algorithm that runs asynchronously,
with different independent components
performing actions that can be
interleaved in complex ways
• All Executions Yield the Same Matching
• First, suppose a woman w is a valid partner of a man m if there is a stable matching that contains the pair (m, w). We will
say that w is the best valid partner of m if w is a valid partner of m, and no woman whom m ranks higher than w is a
valid partner of his. We will use best(m) to denote the best valid partner of m.
• let S∗ denote the set of pairs {(m, best(m)) :m ∈ M}
• (1.7) Every execution of the G-S algorithm results in the set S∗.
• Proof.
• some execution E of the G-S algorithm results in a matching S in which some man is paired with a woman who is not his
best valid partner
• Since men propose in decreasing order of preference, this means that some man m is rejected by a valid partner w
for another men m’ during the execution E of the algorithm.
• either because m proposed and was turned down in favor of w’s existing engagement,
• or because w broke her engagement to m in favor of a better proposal.
• But either way, at this moment w forms or continues an engagement with a man m’ whom she prefers to m.
• Since w is a valid partner of m, there exists a stable matching S’ containing the pair (m, w).
• Who is m’ paired with in this matching?
• Suppose it is a woman w’ != w.
• Since the rejection of m by w was the first rejection of a man by a valid partner in the execution E, it must be
that m’ had not been rejected by any valid partner at the point in E when he became engaged to w. Since he
proposed in decreasing order of preference, and since w’ is clearly a valid partner of m’, it must be that m’
prefers w to w’. But we have already seen that w prefers m’ to m, for in execution E she rejected m in favor of
m’. Since (m’, w) ∈ Not S’, it follows that (m’, w) is an instability in S’.
• This contradicts our claim that S’ is stable and hence contradicts our initial assumption.
• (1.8) In the stable matching S∗, each woman is paired with her worst valid partner.
• Proof it by yourself

• Thus, we find that our simple example above, in which the men’s preferences clashed with the women’s, hinted at a very
general phenomenon: for any input, the side that does the proposing in the G-S algorithm ends up with the best
possible stable matching (from their perspective), while the side that does not do the proposing correspondingly ends
up with the worst possible stable matching.
Matching med-school students to hospitals

Goal. Given a set of preferences among hospitals and med-school


students, design a self-reinforcing admissions process.

Unstable pair. Hospital h and student s form an unstable pair if both:


• h prefers s to one of its admitted students.
• s prefers h to assigned hospital.

Stable assignment. Assignment with no unstable pairs.


独 Natural and desirable condition.
独 Individual self-interest prevents any hospital–student side deal.

3
2
Stable matching problem: input

Input. A set of n hospitals H and a set of n students S.


独 Each hospital h  H ranks
one student per hospital (for now)
students.
独 Each student s  S ranks hospitals.

favorite least favorite favorite least favorite

1st 2nd 3rd 1st 2nd 3rd

Atlanta Xavier Yolanda Zeus Xavier Boston Atlanta Chicago

Boston Yolanda Xavier Zeus Yolanda Atlanta Boston Chicago

Chicago Xavier Yolanda Zeus Zeus Atlanta Boston Chicago

hospitals’ preference lists students’ preference lists


3
3
Perfect matching

Def. A matching M is a set of ordered pairs h–s with h  H and s  S s.t.


独 Each hospital h  H appears in at most one pair of M.
独 Each student s  S appears in at most one pair of M.

Def. A matching M is perfect if | M | = | H | = | S | = n.

1st 2nd 3rd 1st 2nd 3rd

Atlanta Xavier Yolanda Zeus Xavier Boston Atlanta Chicago

Boston Yolanda Xavier Zeus Yolanda Atlanta Boston Chicago

Chicago Xavier Yolanda Zeus Zeus Atlanta Boston Chicago

a perfect matching M = { A–Z, B- Y, C- X


} 3
4
Unstable pair

Def. Given a perfect matching M, hospital h and student s form


an unstable pair if both:
独 h prefers s to matched student.
独 s prefers h to matched hospital.

Key point. An unstable pair h–s could each improve by joint


action.

1st 2nd 3rd 1st 2nd 3rd

Atlanta Xavier Yolanda Zeus Xavier Boston Atlanta Chicago

Boston Yolanda Xavier Zeus Yolanda Atlanta Boston Chicago

Chicago Xavier Yolanda Zeus Zeus Atlanta Boston Chicago

A - Y is an unstable pair for matching M = { A–Z, B- Y, C- X


} 3
5
Stable matching: quiz 1

Which pair is unstable in the matching { A–X, B–Z, C–


Y}?

A. A–Y.

B. B–X.

C. B–Z.

D. None of the above.

1 st 2 nd 3 rd 1 st 2 nd 3 rd
1st 2nd 3rd 1st 2nd 3rd

Atlanta Xavier Yolanda Zeus Xavier Boston Atlanta Chicago

Boston Yolanda Xavier Zeus Yolanda Atlanta Boston Chicago

Chicago Xavier Yolanda Zeus Zeus Atlanta Boston Chicago

7
Stable matching problem

Def. A stable matching is a perfect matching with no unstable pairs.

Stable matching problem. Given the preference lists of n hospitals and


n students, find a stable matching (if one exists).

1st 2nd 3rd 1st 2nd 3rd

Atlanta Xavier Yolanda Zeus Xavier Boston Atlanta Chicago

Boston Yolanda Xavier Zeus Yolanda Atlanta Boston Chicago

Chicago Xavier Yolanda Zeus Zeus Atlanta Boston Chicago

a stable matching M = { A–X, B–Y, C–Z


} 9
Stable roommate problem

Q. Do stable matchings always exist?


A. Not obvious a priori.

Stable roommate problem.


独 2 n people; each person ranks others from 1 to 2 n –
1.
独 Assign roommate pairs so that no unstable pairs.

1 st 2nd 3 rd
no perfect matching is stable
A B C D
A–B, C–D  B–C unstable
B C A D
A–C, B–D  A–B unstable
C A B D
A–D, B–C  A–C unstable
D A B C

Observation. Stable matchings need not exist.


10
1.
STABLE

Mstable matching
ATCHING
problem
‣ Gale–Shapley
algorithm
‣ hospital optimality
‣ context

SECTION 1.1
Gale–Shapley deferred acceptance algorithm

An intuitive method that guarantees to find a stable matching.

GALE–SHAPLEY (preference lists for hospitals and students)

INITIALIZE M to empty matching.


WHILE (some hospital h is unmatched and hasn’t
proposed to every student)
s  first student on h’s list to whom h has not yet
proposed.
IF (s is unmatched)
Add h–s to matching M.
ELSE IF (s prefers h to current partner
hʹ) Replace hʹ–s with h–s in matching
M.
ELSE

s rejects h.

12
Proof of correctness:
termination
Observation 1. Hospitals propose to students in decreasing order
of preference.

Observation 2. Once a student is matched, the student never


becomes unmatched; only “trades up.”

Claim. Algorithm terminates after at most n 2 iterations of WHILE loop.


Pf. Each time through the WHILE loop, a hospital proposes to a new
student. Thus, there are at most n 2 possible proposals. ▪

1 st 2 nd 3rd 4th 5th 1st 2 nd 3 rd 4th 5th

A V W X Y Z V B C D E A

B W X. Y V Z W C D E
A B
C X Y. V W Z X D E A

D X Y E A B
Z. W Z
Z A B C B C
Y
AA. X
E V Y
C D
n(n-1) + 1 proposals
Z
13
Proof of correctness: perfect matching

Claim. Gale–Shapley outputs a


matching. Pf.
独 Hospital proposes only if  matched to ≤ 1 student
unmatched.  matched to ≤ 1 hospital
独 Student keeps only best hospital.
Claim. In Gale–Shapley matching, all hospitals get
matched. Pf. [by contradiction]
独 Suppose, for sake of contradiction, that some hospital h  H
is unmatched upon termination of Gale–Shapley algorithm.
独 Then some student, say s  S, is unmatched upon termination.
独 By Observation 2, s was never proposed to.
独 But, h proposes to every student, since h ends up unmatched.

Claim. In Gale–Shapley matching, all students get


matched. Pf. [by counting] 14
Proof of correctness: stability

Claim. In Gale–Shapley matching M*, there are no unstable pairs.


Pf. Consider any pair h–s that is not in M*.

h never proposed to s.
独 Case
 h prefers its Gale–Shapley partner sʹ to s.
hospitals propose in
decreasing order
1: of preference
 h–s is not unstable.

h proposed to s.
独 Case
 s rejected h (either right away or later)
2:
 s prefers Gale–Shapley partner hʹ to h.
h – sʹ
 h–s is not unstable.
students only trade up
hʹ–s

独 In either case, the pair h–s is not unstable.

Gale–Shapley matching M*

15
Summar
y
Stable matching problem. Given n hospitals and n students, and their
preference lists, find a stable matching if one exists.

Theorem. [Gale–Shapley 1962] The Gale–Shapley algorithm guarantees


to find a stable matching for any problem instance.

16
Stable matching: quiz 2

Do all executions of Gale–Shapley lead to the same stable matching?

A. No, because the algorithm is nondeterministic.

B. No, because an instance can have several stable matchings.

C. Yes, because each instance has a unique stable matching.

D. Yes, even though an instance can have several stable matchings


and the algorithm is nondeterministic.

17
1.
STABLE

Mstable matching
ATCHING
problem
‣ Gale–Shapley
algorithm
‣ hospital optimality
‣ context

SECTION 1.1
Understanding the solution

For a given problem instance, there may be several stable matchings.

11 22 33 11 22 33
1st
stst 2nd
ndn 3rd
rdr 1st
stst 2nd
ndn 3rd
rdr
d d d d
A X Y Z X B A C
A X Y Z X B A C
B Y X Z Y A B C
B Y X Z Y A B C
C X Y Z Z A B C
C X Y Z Z
an instance with two stable matchings: S = { A- X, B- Y, C- Z } and S′ = { A- Y, B- X, C-
Z} 19
Understanding the solution

Def. Student s is a valid partner for hospital h if there exists any stable
matching in which h and s are matched.

Ex.
独 Both X and Y are valid partners for
A. 独 Both X and Y are valid partners
for B. 独 Z is the only valid partner for
C.

1st 2nd 3rd 1st 2nd 3rd

A X Y Z X B A C

B Y X Z Y A B C

C X Y Z Z A B C

an instance with two stable matchings: S = { A- X, B- Y, C- Z } and S′ = { A- Y, B- X, C-


Z} 20
Stable matching: quiz 3

Who is the best valid partner for W in the following


instance?

6 stable matchings
A.
{ A–W, B–X, C–Y, D–Z }
B. { A–X, B–W, C–Y, D–Z }

{ A–X, B–Y, C–W, D–Z }


C.
{ A–Z, B–W, C–Y, D–X }

D. { A–Z, B–Y, C–W, D–X }


{ A–Y, B–Z, C–W, D–X }

1st 2nd 3 rd 4th 1st 2nd 3rd 4th

A Y Z X W W D A B C

B Z Y W X X C B A D

C W Y X Z Y C B A D

D X Z W Y Z D A B C
21
Understanding the solution

Def. Student s is a valid partner for hospital h if there exists any


stable matching in which h and s are matched.

Hospital-optimal assignment. Each hospital receives best valid


partner.
独 Is it a perfect matching?
独 Is it stable?

Claim. All executions of Gale–Shapley yield hospital-optimal


assignment. Corollary. Hospital-optimal assignment is a stable
matching!

23
Hospital optimality

Claim. Gale–Shapley matching M* is hospital-


optimal. Pf. [by contradiction]
独 Suppose a hospital is matched with student
other than best valid partner.
独 Hospitals propose in decreasing order of
preference.
h–s
partner
 that rejects
some h. is rejected by a valid
hospital
hʹ – sʹ
独 partner during
Let M be Gale–Shapley
a stable matching where h and s are
独 Let h be first such hospital, and let s be the first
matched.


validWhen s rejects h in Gale–Shapley, s forms (or re-
stable matching M
 s prefers
affirms) hʹ to h. to a hospital, say hʹ.
commitment
独 Let sʹ be partner of hʹ in M.
独 hʹ had not been rejected by any valid
because this is the first
(including sʹ) at the point when h is rejected by s.
partner rejection by a valid partner

独 Thus, hʹ had not yet proposed to sʹ when hʹ proposed to


hʹ prefers s to sʹ.
s.
独 Thus, hʹ–s is unstable in M, a contradiction. 24
Student pessimality

Q. Does hospital-optimality come at the expense of the students?


A. Yes.

Student-pessimal assignment. Each student receives worst valid

partner. Claim. Gale–Shapley finds student-pessimal

stable matching M*.


Pf. [by contradiction]
独 Suppose h–s matched in M* but h is not the worst valid partner for s.
独 There existsh stable
s prefers to hʹ. matching M in which s is paired with a hhʹ–s– sʹ
独 hospital,
Let sʹ be the
say partner of shprefers
hʹ, whom in M. less than h.

独 By hospital-optimality, s is the best valid partner for
h.  h prefers s to sʹ.

独 Thus, h–s is an unstable pair in M, a contradiction. stable matching M


25
Stable matching: quiz 4

Suppose each agent knows the preference lists of every other agent
before the hospital propose-and-reject algorithm is executed.
Which is true?

A. No hospital can improve by falsifying its preference list.

B. No student can improve by falsifying their preference list.

C. Both A and B.

D. Neither A nor B.

26
1.
STABLE

Mstable matching
ATCHING
problem
‣ Gale–Shapley
algorithm
‣ hospital optimality
‣ context

SECTION 1.1
Extensions

Extension 1. Some agents declare others as unacceptable.


Extension 2. Some hospitals have more than one position. med-school student
unwilling to work
Extension 3. Unequal number of positions and students. in Cleveland

≥ 43K med-school students;


only 31K positions

Def. Matching M is unstable if there is a hospital h and student s such that:


独 h and s are acceptable to each other; and
独 Either s is unmatched, or s prefers h to assigned hospital; and
独 Either h does not have all its places filled, or h prefers s to at
least one of its assigned students.

Theorem. There exists a stable matching.


Pf. Straightforward generalization of Gale–Shapley algorithm.

29
Historical context

National resident matching program (NRMP).


独 Centralized clearinghouse to match med-school students to
hospitals.
独 Originally usedto
Began in 1952 the
fix“Boston Pool”of offer dates.
unraveling
hospitals began making
offers earlier and
earlier, up to 2 years in
algorithm. advance

独 -Algorithm
med-school student optimal
overhauled in 1998.
- deals with various side constraints
stable matching no longer
(e.g., allow couples to match together) guaranteed to exist

The Redesign of the Matching Market for American Physicians:


Some Engineering Aspects of Economic Design

By ALVIN E. ROTH AND ELLIOTT PERANSON*

We report on the design of the new clearinghouse adopted by the National Resident
Matching Program, which annually fills approximately 20,000 jobs for new physi-
cians. Because the market has complementarities between applicants and between
positions, the theory of simple matching markets does not apply directly. However,
computational experiments show the theory provides good approximations. Fur-
thermore, the set of stable matchings, and the opportunities for strategic manipu-
lation, are surprisingly small. A new kind of “core convergence” result explains
this; that each applicant interviews only a small fraction of available positions is
important. We also describe engineering aspects of the design process. (JEL C78,
B41, J44)

30
2012 Nobel Prize in Economics

Lloyd Shapley. Stable matching theory and Gale–Shapley algorithm.

original applications:
college admissions and
opposite-sex marriage

Alvin Roth. Applied Gale–Shapley to matching med-school students


with hospitals, students with schools, and organ donors with patients.

Lloyd Shapley Alvin Roth


31
New York City high school match

8th grader. Ranks top-5 high schools.


High school. Ranks students (and limit).
Goal. Match 90K students to 500 high
school programs.

32
Questbridge national college match

Low-income student. Ranks colleges.


College. Ranks students willing to admit (and limit).
Goal. Match students to colleges.

33
A modern application

Content delivery networks. Distribute much of world’s content on web.

User. Preferences based on latency and packet loss.


Web server. Preferences based on costs of bandwidth and co-location.
Goal. Assign billions of users to servers, every 10 seconds.

Algorithmic Nuggets in Content Delivery

Bruce M. Maggs Ramesh K. Sitaraman


Duke and Akamai UMass, Amherst and Akamai
bmm@cs.duke ramesh@cs.umass.edu
.edu
T his article is an editorial note submitted to C C R . It has N O T been peer reviewed.
The authors take full responsibility for this article’s technical content. Comments can be posted through C C R Online.

ABSTRACT
Edge Server
This paper “peeks under the covers” at the subsystems that Overlay
provide the basic functionality of a leading content deliv-
ery network. Based on our experiences in building one of Routing Client
the largest distributed systems in the world, we illustrate
how sophisticated algorithmic research has been adapted to
balance the load between and within server clusters, man-
age the caches on servers, select paths through an overlay
routing network, and elect leaders in various contexts. In
each instance, we first explain the theory underlying the Origin
algorithms, then introduce practical considerations not cap-
tured by the theoretical models, and finally describe what is Content
Authoritative Name Server
implemented in practice. Through these examples, we high-
DNS (Global and Local Load
light the role of algorithmic research in the design of com-
Balancing)
plex networked systems. The paper also illustrates the close
synergy that exists between research and industry where
research ideas cross over into products and product require-
ments drive future research.

34
Assignment#1

What is your field of research or favorite subject. Find a relevant research article that has used G-S algorithm. Write its
summary and your critical reviews.

You might also like