cmsc451-lects_2_2.pdf

Upload: harris-anches

Post on 04-Jun-2018

222 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/13/2019 cmsc451-lects_2_2.pdf

    1/2

    Decision: A woman who receives a proposal can either accept or reject it. If she is already engaged and acceptsa proposal, her existing engagement is broken off, and her old mate becomes unengaged.

    There is an obvious sexual bias here, since men do the proposing and women do the deciding. It is interestingto consider a more balanced system where either side can offer proposals. (Not surprisingly, it does make adifference whether men or women do the proposing, from the perspective of who tends to get assigned mates of

    higher preference. Well leave this question as an exercise.)It will make the algorithm a bit easier to analyze, if we view it as operating in the series of rounds . In eachround, each of the men who are currently unengaged offers a proposal to the highest woman on his preferenceto which hasnt previously proposed. The women receiving the proposal compares the offer to her current mate.If she prefers the new proposal, she accepts it, thus breaking off her old engagement. Otherwise, she rejects it.The rounds continue until no unengaged men remain.

    We present the code for the Gale-Shapley algorithm in the following code block. Our presentation is not basedon the above rounds-structure, but rather in the form that Kleinberg and Tardos present it, where in each iterationa single proposal is made and decided upon. (The round-based version differs only in that all unengaged menact at once, rather than individually.) An example of this algorithm on the preferences given above is shown inFig. 1.

    The Gale-Shapley Algorithm// Input: 2n preference lists, each consisting of n names.// Output: A matching that pairs each man with each woman.Initially all men and all women are unengagedwhile (there is an unengaged man who hasnt yet proposed to every woman) {

    Let m be any such manLet w be the highest woman on his list to whom he has not yet proposedif (w is unengaged) then (m, w) are now engagedelse {

    Let m be the man w is engaged to currentlyif (w prefers m to m) {

    Break the engagement (m, w)Create the new engagement (m, w)m is now unengaged

    }}

    }

    Round 1

    BTJ

    KAY

    BTJ

    Round 2

    KAY

    BTJ

    Round 3

    KAY

    BTJ

    Round 4

    KAY

    BTJ

    ProposalEngagementUnengaged man

    Fig. 1: Example of the round form version of the GS Algorithm on the preference lists given earlier.

    Correctness of the Gale-Shapley Algorithm: Here are some easy observations regarding the Gale-Shapley (GS) Al-gorithm. We wont bother to prove them, since they are essentially one-line proofs. But check that you believethem.

    Lemma 1: Once a woman becomes engaged, she remains engaged for the remainder of the algorithm, and her mate can only get better over time in terms of her preference list.

    Lemma 2: The mates assigned to each man decrease over time in terms of his preference list.

    Lecture Notes 5 CMSC 451

  • 8/13/2019 cmsc451-lects_2_2.pdf

    2/2

    Next we show that the algorithm terminates.

    Lemma 3: The GS Algorithm terminates after at most n 2 iterations of the while loop.

    Proof: Consider the pairs (m, w ) in which man m has not yet proposed to woman w . Initially there are n 2

    such pairs, but with each iteration of the while loop, at least one man proposes to one woman. Once aman proposes to a woman, he will never propose to her again. Thus, after n 2 iterations, no one is left to

    propose.

    The above lemma does not imply that the algorithm succeeds in nding a pairing between all the pairs (stableor not), and so we prove this next. By the way, such a 1-to-1 pairing is called a perfect matching .

    Lemma 4: On termination of the GS algorithm, the set of engagements form a perfect matching.

    Proof: Every time we create a new engagement we break an old one. Thus, at any time, each woman isengaged to exactly one man, and vice versa. The only thing that could go wrong is that, at the end of thealgorithm, some man, call him Mr. Lonelyheart, is unengaged after exhausting his list. Since there is a1-to-1 correspondence between engaged men and engaged women, this would imply that some woman,call her Ms. Desperate, is also unengaged. From Lemma 1 we know that once a woman is asked, she will become engaged and will remain engaged henceforth (although possibly to different mates). This impliesthat Ms. Desperate has never been asked. But she appears on Mr. Lonelyhearts list, and therefore she musthave been asked, a contradiction.

    Finally, we show that the resulting perfect matching is indeed stable. This establishes the correctness of the GSalgorithm formally.

    Lemma 5: The matching output by the GS algorithm is a stable matching.

    Proof: Suppose to the contrary that there is some instability in the nal output. This means that there are two pairs output (m, w ) and (m , w ) where

    m prefers w to his assigned mate w , and w

    prefers m to her assigned mate m ,

    (and hence m and w would be inclined to elope).Lets see why this cannot happen. Observe that since m prefers w he proposed to his dreamboat w before

    that plain-jane w . What went wrong with his plans? Either the lovely w

    was already engaged to somedreamy hunk and rejected the offer outright or she took his offer initially but later opted for someonewho she liked better and broke the engagement with m off. (Recall from Lemma 1 that once engaged, awomans mate only improves over time.) In either case, the lovely w winds up with a veritable Greek godof a mansomeone she prefers more than m , and denitely someone she prefers more than the dirty low-life scum m who she ranked even lower than m . Thus, the pair (m , w ) could never have been generated by the algorithm, a contradiction.

    Algorithm Efciency: Now that we have established the correctness of the GS Algorithm formally, we turn to thequestion of its execution time. Let us consider generally how can we evaluate the efciency of any algorithm.The fundamental measure of efciency that any user would care about is how fast does it run on my favorite inputon my own machine. Unfortunately, this is far too specic to be signicant value. As mentioned in the previousclass, a natural way to discuss the running time would be to consider the number of steps taken on some ideal

    computer. This necessitates ignoring constant factors, since presumably different implementations of essentiallythe same algorithm would involve slightly different (constant factor) differences. Furthermore, faster machineswould execute this program at different speeds, but the differences could be related by a constant scaling factor.

    The running time will depend on some measure of the problems size and complexity. A most natural way of measuring the complexity of a given problem instance is the size of its input. (Depending on the particular problem, there may be other factors that are involved. For example, some problems, even of the same size, are

    Lecture Notes 6 CMSC 451