CS252 Algorithms Friday, 5 April 2024 + Today - Gale-Shapley proof - the proof itself - what their proof style says for your proofs - Your questions about homework - How to approach using G-S in varied contexts - Later today - Zoom office hours, same link, usual time (3A 12-1) - grader feedback for PS#1 - solutions for PS#1 - PS#3 - Monday: moving on to graphs + Gale-Shapely correctness proof [variation: #m < #w] - Terminates after at most n^2 iterations [#m * #w] (when do you need a termination proof?) one proposal per iteration; no repeated proposals; n^2 possible proposals - S is a matching - def of "matching"? 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. - why can't one women be engaged to > 1 man? - why can't one man be engaged to > 1 woman? analyze the two locations in the algorithm where a (m,w) pair can get added to S - S is a perfect matching [variation #m < #w; replace this with "all men are engaged"] - def of "perfect"? 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' - is this one obvious? - Only case to consider there's a free m who has already made all n of his proposals but this means all women are still engaged (since they've all received at least one proposal, from m) who are all those w's engaged to? n-1 men? ... contradiction - S is stable - review the definition of "stable" - by contradiction, with two cases assume there's (m1, w1) and (m2, w2) in S where m1 prefers w2 to w1, and w2 prefers m1 to w2 case 1: m1 proposed to w2 in the past then m2 proposed to w2 later but then m2 and w2 wouldn't have gotten engaged because w2 only switches engagements when she hears a proposal from somebody she prefers, so this couldn't happen this way. case 2: m1 never proposed to w2 but m1 proposed to w1, who he dis-prefers to w2, but that's not the order in which men are proposing, so that couldn't happen either so our assumption must be false, so S is stable ---- + Questions ---- + Variants - what if there are more women than men, and men are still the proposers - can you change the theorem statement and proof yes--this isn't too bad for this scenario - can you modify the input data and output data instead? we start #w with #m-length pref lists #m with #w-length pref lists k = #w - #m, add k fake men fake men's preference lists? randomize women's pref lists need to include the fake men: stick them at the bottom of each woman's list run G-S the women engaged to fake men are now just unmarried at the - same, but more men than women - modify the proof? - modify input and output to use regular G-S - #m == #w, but preference lists can have ties - CS Match (# students != # classes; classes have multiple slots; etc.) - use the "transform the input" approach - a class with a 28-person cap becomes 28 distinct classes - preference list from each student is supplemented by adding all the courses they didn't list in a lowest-priority tie at the bottom - do whatever you did to deal with preference ties in the previous scenario - who proposes? (I'm pretty sure the students are the proposers; I'll ask) - what do the classes' preference lists look like? - etc.