Professional Documents
Culture Documents
favorite
least favorite
1st
2nd
3rd
Xavier
Amy
Bertha
Clare
Yancey
Bertha
Amy
Zeus
Amy
Bertha
favorite
least favorite
1st
2nd
3rd
Amy
Yancey
Xavier
Zeus
Clare
Bertha
Xavier
Yancey
Zeus
Clare
Clare
Xavier
Yancey
Zeus
favorite
least favorite
1st
2nd
3rd
Xavier
Amy
Bertha
Clare
Yancey
Bertha
Amy
Zeus
Amy
Bertha
least favorite
favorite
1st
2nd
3rd
Amy
Yancey
Xavier
Zeus
Clare
Bertha
Xavier
Yancey
Clare
Clare
Xavier
Yancey
favorite
least favorite
1st
2nd
3rd
Xavier
Amy
Bertha
Clare
Zeus
Yancey
Bertha
Amy
Zeus
Zeus
Amy
Bertha
least favorite
favorite
1st
2nd
3rd
Amy
Yancey
Xavier
Zeus
Clare
Bertha
Xavier
Yancey
Zeus
Clare
Clare
Xavier
Yancey
Zeus
favorite
1st
least favorite
2nd
least favorite
favorite
3rd
1st
2nd
2nd
3rd
3rd
Adam
Bob
Chris
Doofus
Xavier
Amy
Bertha
Clare
Amy
Yancey
Xavier
Zeus
Yancey
Bertha
Amy
Clare
Bertha
Xavier
Yancey
Zeus
Zeus
Amy
Bertha
Clare
Clare
Xavier
Yancey
Zeus
1st
A-B, C-D
A-C, B-D
A-D, B-C
! B-C unstable
! A-B unstable
! A-C unstable
Propose-And-Reject Algorithm
1 st
2nd
3rd
4th
5th
1 st
2nd
3rd
4th
Vi ctor
Amy
5th
V
Wyatt
Bertha
Xavi er
Clare
Yancey
Di ane
Zeus
Eri ka
10
11
Case 2: Z proposed to A.
! A rejected Z (right away or later)
! A prefers her GS partner to Z.
! A-Z is stable.
S*
Amy-Yancey
Bertha-Zeus
...
12
Summary
Efficient Implementation
Engagements.
Maintain a list of free men, e.g., in a queue.
Maintain two arrays wife[m], and husband[w].
set entry to 0 if unmatched
if m matched to w then wife[m]=w and husband[w]=m
!
Men proposing.
For each man, maintain a list of women, ordered by preference.
Maintain an array count[m] that counts the number of proposals
made by man m.
!
13
14
Efficient Implementation
Women rejecting/accepting.
Does woman w prefer man m to man m'?
For each woman, create inverse of preference list of men.
Constant time access for each query after O(n) preprocessing.
Amy
1st
2nd
3rd
4th
5th
6th
7th
8th
Pref
Amy
Inverse
4th
8th
2nd
5th
6th
7th
3rd
1st
for i = 1 to n
inverse[pref[i]] = i
1st
2nd
3rd
1st
2nd
3rd
Xavier
Amy
Yancey
Bertha
Zeus
Clare
15
16
Man Optimality
17
18
Woman Pessimality
no man and woman prefer to be with each other than assigned partner
Pf.
Gale-Shapley algorithm. Finds a stable matching in O(n2) time.
Suppose A-Z matched in S*, but Z is not worst valid partner for A.
There exists stable matching S in which A is paired with a man, say
Y, whom she likes less than Z.
S
Let B be Z's partner in S.
man-optimality
Z prefers A to B.
Amy-Yancey
Thus, A-Z is an unstable in S. !
Bertha-Zeus
...
19
20
21
22
Lessons Learned
23
Interval Scheduling
Input. Set of jobs with start times, finish times, and weights.
Goal. Find maximum weight subset of mutually compatible jobs.
23
12
c
20
d
26
13
f
20
g
11
h
10
11
16
Time
10
11
25
Time
26
Bipartite Matching
Independent Set
Input. Graph.
Goal. Find maximum cardinality independent set.
subset of nodes such that no two
joined by an edge
3
D
27
28
10
15
15
10
29
30