Académique Documents
Professionnel Documents
Culture Documents
Bipartite Graph
Recall: A graph is bipartite if the nodes V can be partitioned into two sets A and B such that all edges go only between A and B (no edges go from A to A or from B to B)
Perfect Matchings
A matching is a set of edges, no two of which share a vertex. The matching is perfect if it includes every vertex. Regular Bipartite Matching Theorem: Iff every node in a bipartite graph has the same degree d ! 1, then the graph has a perfect matching.
Augmenting a Matching
Suppose M is a matching, and M is a bigger one. M M M + M Consider the graph with the edges from M and M The degree of all the nodes is 0, 1 or 2. The components of this graph look like.?
M + M
The components of this graph of edges from M and M could be: Isolated nodes Isolated edges Alternating Cycles (of even length) Alternating Paths
M + M The only type of component which has a different number of red and blue edges is an alternating path. So, because M>M there must be at least one alternating path that begins with a blue edge and ends with a blue edge.
Is M maximum? M + M M > M implies Look for augmenting path in G for M. If none, we know M is maximum, otherwise swap even and odd edges to make M with 1 edge more than M.
G has an augmenting path p beginning and ending with blue edges. M is either maximum already, or there is an augmenting path of G for M (starting and ending with a blue edge).
Given an undirected or directed graph G, and a start vertex s, the algorithm finds everything that can be reached from s, and computes the shortest path length to it.
Proof: We prove by induction the following statement: At the beginning of the loop, Li-1 is the set of vertices at distance i-1 from s, and all vertices at distance i-1 or less have been marked. Clearly the statement is true for i=1 (base case). Lets assume its true for i-1 and prove it for i. Consider a vertex v at distance i. At the beginning of the loop for i we know v is unmarked (cause only vertices at distance < i are marked). We also know that it must be a neighbor of a vertex at distance i-1, otherwise it cannot be at distance i. Therefore the algorithm will put v into Li and mark it. QED.
Augmenting BFS algorithm. Let L0 be the set of unmatched vertices on the left. Let Ri be the vertices that have not yet been visited, which are neighbors of Li-1 via edges not in the matching. Let Li+1 be the vertices that have not yet been visited which are neighbors of Ri via edges in the matching. We can define the alternating path of a vertex v to be the length of the shortest alternating path starting from L0 and ending at v The inductive property that is maintained is that Li (for even i) or Ri (for odd i) is the set of vertices reachable from L0 via an alternating path of length i. The following algorithm starts with a matching M and either (1) determines that it is a maximum matching, or (2) constructs an alternating path to make the matching bigger.
Let L0 be the set of unmatched vertices on the left. For i=1,3,5 do: Let Ri be the vertices that have not yet been visited, which are neighbors of Li-1 via edges not in the matching. If any vertex of Ri is not matched, weve found an alternating path. HALT Let Li+1 be the vertices that have not yet been visited which are neighbors of Ri via edges in the matching. If Li+1 is empty then our matching is maximum. HALT
The Mathematics Of 1950s Dating: Who wins the battle of the sexes?
3,2,5,1,4 1 1,2,5,3,4 WARNING: This lecture contains mathematical content that may be shocking to some students. 2 4,3,2,1,5 3 1,3,4,2,5 4 1,2,4,5,3 5
Steven Rudich: www.discretemath.com www.rudich.net
Dating Scenario
! There are n boys and n girls ! Each girl has her own ranked preference list of all the boys ! Each boy has his own ranked preference list of the girls ! The lists have no ties Question: How do we pair them off? What criteria come to mind?
Steven Rudich: www.discretemath.com www.rudich.net
3,5,2,1,4
5,2,1,4,3
4,3,5,1,2
1,2,3,4,5
2,3,4,1,5
! Maximizing the number of people who get their first choice ! Disney Land
Steven Rudich: www.discretemath.com www.rudich.net
Rogue Couples
Suppose we pair off all the boys and girls. Now suppose that some boy and some girl prefer each other to the people to whom they are paired. They will be called a rogue couple.
Stable Pairings
A pairing of boys and girls is called stable if it contains no rogue couples.
3,2,5,1,4 1 1,2,5,3,4 2 4,3,2,1,5 3 1,3,4,2,5 4 1,2,4,5,3 5 5 4 2,3,4,1,5
Steven Rudich: www.discretemath.com www.rudich.net
Idea: Allow the pairs to keep breaking up and reforming until they become stable.
Can you argue that the couples will not continue breaking up and reforming forever?
2,3,4
3,1,4
2,3,4
3,1,4
1,2,4
*,*,*
1,2,4
*,*,*
2,3,4
3,1,4
2,3,4
3,1,4
1,2,4
*,*,*
1,2,4
*,*,*
2,3,4
3,1,4
Insight
1,2,4
*,*,*
Any proof that heterosexual couples do not break up and reform forever must contain a step that fails in the bisexual case
Steven Rudich: www.discretemath.com www.rudich.net
Female
String
Improvement Lemma: If a girl has a boy on a string, then she will always have someone at least as good on a string, (or for a husband).
! She would only let go of him in order to maybe someone better ! She would only let go of that guy for someone even better ! She would only let go of that guy for someone even better ! AND SO ON . . . . . . . . . . . . .
Steven Rudich: www.discretemath.com Informal Induction www.rudich.net
Improvement Lemma: If a girl has a boy on a string, then she will always have someone at least as good on a string, (or for a husband).
PROOF: Let q be the day she first gets b on a string. If the lemma is false, there must be a smallest k such that the girl has some b* inferior to b on day q+k. One day earlier, she has someone as good as b. Hence, a better suitor than b* returns the next day. She will choose the better suitor contradicting the assumption that her prospects went below b on day q+k.
Corollary: Each girl will marry her absolute favorite of the boys who visit her during the TMA
Contradict ion
Theorem: Let T be the pairing produced by TMA. T is stable. Great! We know that TMA will terminate and produce a pairing. But is it stable?
g*
g*
Opinion Poll
of f er l t t be na o is ditio oys h b W ra in t g, the ls? ir in dat the g r o
How should we define what we mean when we say the optimal girl for boy b? Flawed Attempt: The girl at the top of bs list
Steven Rudich: www.discretemath.com www.rudich.net
10
11
Some boy b got rejected by his optimal girl g because she said maybe to a preferred b*. b* likes g at least as much as his optimal girl.
Some boy b got rejected by his optimal girl g because she said maybe to a preferred b*. b* likes g at least as much as his optimal girl.
We know it is male-optimal. Suppose there is a stable pairing S where some girl g does worse than in T. Let b be her mate in T. Let b* be her mate in S. ! By assumption, g likes b better than her mate in S ! b likes g better than his mate in S
! We already know that g is his optimal girl
Contradict ion
12
Advice to females
The largest, most successful dating service in the world uses a computer to run TMA !
Learn to make the first move.
Steven Rudich: www.discretemath.com www.rudich.net
History
1900 ! Idea of hospitals having residents (then called interns) Over the next few decades ! Intense competition among hospitals for an inadequate supply of residents
! Each hospital makes offers independently ! Process degenerates into a race. Hospitals steadily advancing date at which they finalize binding contracts
Steven Rudich: www.discretemath.com www.rudich.net
History
1944 Absurd Situation. Appointments being made 2 years ahead of time! ! All parties were unhappy ! Medical schools stop releasing any information about students before some reasonable date ! Did this fix the situation?
Steven Rudich: www.discretemath.com www.rudich.net
History
1944 Absurd Situation. Appointments being made 2 years ahead of time! ! All parties were unhappy ! Medical schools stop releasing any information about students before some reasonable date ! Offers were made at a more reasonable date, but new problems developed
Steven Rudich: www.discretemath.com www.rudich.net
13
History
1945-1949 Just As Competitive ! Hospitals started putting time limits on offers ! Time limit gets down to 12 hours ! Lots of unhappy people ! Many instabilities resulting from lack of cooperation
Steven Rudich: www.discretemath.com www.rudich.net
History
1950 Centralized System ! Each hospital ranks residents ! Each resident ranks hospitals ! National Resident Matching Program produces a pairing
Whoops! The pairings were not always stable. By 1952 the algorithm was the TMA (hospital-optimal) and therefore stable.
Steven Rudich: www.discretemath.com www.rudich.net
NY TIMES
! Law of the jungle reigns . . ! The association of American Law Schools agreed not to hire before September of the third year . . . ! Some extend offers from only a few hours, a practice known in the clerkship vernacular as a short fuse or a hold up. ! Judge Winter offered a Yale student a clerkship at 11:35 and gave her until noon to accept . . . At 11:55 . . he withdrew his offer
Steven Rudich: www.discretemath.com www.rudich.net
Marry Well!
REFERENCES
D. Gale and L. S. Shapley, College admissions and the stability of marriage, American Mathematical Monthly 69 (1962), 9-15 Dan Gusfield and Robert W. Irving, The Stable Marriage Problem: Structures and Algorithms, MIT Press, 1989
14
You have n men and n women. Each one has a complete ordered preference list for those of the other sex. EG: Mens preferences
12413 23142 32314 44132
Note: Bipartite graph again But now its a complete bipartite graph every man-woman edge is present
Womens preferences
12143 24312 31432 42143
The goal is to pair the men with the women. What criteria to use?
Rogue Couples
Suppose we pair off all the men and women. Now suppose that some man and some woman prefer each other to the people to whom they are paired They will be called a rogue couple
15
Womens preferences
12143 24312 31432 42143
Stable matchings: (1,4) (2,3) (3,2) (4,1) (1,4) (2,1) (3,2) (4,3)
Not stable: (1,1) (2,3) (3,2) (4,4) Find the rogue couple (1,4)
Given a set of preference lists, how do we find a stable pairing? Wait! We dont even know that such a pairing always exists!
Better Question:
Does every set of preference lists have a stable pairing?
Idea: Allow the pairs to keep breaking up and reforming until they become stable
16
2,3,4
3,1,4
Can you argue that the couples will not continue breaking up and reforming forever?
1,2,4
*,*,*
Everybody is initially free. While some man m is free do: Let w = the first woman on ms list to whom he has not yet proposed. Now m proposes to w. Now there are three cases: (1) If w is free then engage (m,w) (2) If w is not free and w prefers m to her finace m then engage(m,w) and m is now free (3) If w is not free and prefers her finace m to m then w rejects m (m remains free)
Theorem: For any given instance of the stable marriage problem, the Gale-Shapley algorithm terminates, and, on termination, the engaged pairs constitute a stable matching. Proof: First we make the following simple observations: (1) The engagement always forms a matching. (2) Once a woman is engaged, she remains engaged. (3) Each new engagement is to a better man for her. A man cannot be rejected by all women. Because if he is, then all women must be engaged. This is impossible since the number of men equals the number of women. The algorithm must terminate, because on each iteration a man progresses down his list. Therefore there are at most n2 iterations. On termination the engagements form a perfect matching.
17
Proof Contd. Why is it stable? Let M denote the matching computed. If a man m prefers w to M(w) then w must have rejected m at some point. Therefore the man she is paired with is better for her than m.
Therefore the pair (m,w) is not a rogue couple for M. Therefore there is no rogue couple for M.
QED
Answer: The algorithm is better for the men. In fact its the best possible.
Define a mans best women to be his highest ranking woman from among all stable matchings. This algorithm matches every man with his best woman! Even though the algorithm, as described seems like it might be able to give more than one answer! (Its non-deterministic.) Thus, this is the man-optimal algorithm.
Theorem: All possible executions of the algorithm (with men as proposers) yield the same stable matching, and in this matching, each man has the best partner that he can have in any stable matching. Proof: See the notes posted on the course web site Theorem: In the man-optimal stable matching, each woman has the worst partner that she can have in any stable matching. Proof: See the notes posted on the course web site
Applictions
A real world appliction (of a slightly modified version of this problem) is in matching residents to hospitals.
Bipartite Matching Algorithm ! Augmenting Paths ! Breadth First Search Stable Matchings ! Criterion ! Gale-Shapley Algorithm ! Proof that it produces a stable matching ! It produces the unique male-optimal stable matching
It is also a key component in the design of a data structure called History Independent Hash Table. Critical use of the fact that the matching is independent of the order of execution.
18