CPSC 320 Sample Solution, Reductions and Resident Matching: A Residentectomy

Similar documents
CPSC 320 Sample Solution, The Stable Marriage Problem

CPSC W1: Midterm #1 Sample Solution

MITOCW MITRES_18-007_Part5_lec3_300k.mp4

MITOCW ocw f99-lec09_300k

MITOCW ocw f99-lec01_300k

MITOCW Lec 11 MIT 6.042J Mathematics for Computer Science, Fall 2010

Matching Theory and the Allocation of Kidney Transplantations

MITOCW ocw f99-lec05_300k

The key is that there are two disjoint populations, and everyone in the market is on either one side or the other

MITOCW ocw f99-lec16_300k

The Inductive Proof Template

MITOCW ocw f99-lec30_300k

MITOCW ocw f99-lec23_300k

MITOCW watch?v=y6ma-zn4olk

We set up the basic model of two-sided, one-to-one matching

Omega notation. Transitivity etc.

MITOCW ocw f99-lec17_300k

Ma/CS 6b Class 3: Stable Matchings

Note: Please use the actual date you accessed this material in your citation.

3: Linear Systems. Examples. [1.] Solve. The first equation is in blue; the second is in red. Here's the graph: The solution is ( 0.8,3.4 ).

Energy is always partitioned into the maximum number of states possible.

MITOCW watch?v=ed_xr1bzuqs

0. Introduction 1 0. INTRODUCTION

Instructor (Brad Osgood)

Asymptotic Analysis Cont'd

MITOCW watch?v=poho4pztw78

COMP 355 Advanced Algorithms

MITOCW MITRES18_006F10_26_0602_300k-mp4

MITOCW ocw feb k

Ma/CS 6b Class 3: Stable Matchings

Uncertainty: A Reading Guide and Self-Paced Tutorial

But, there is always a certain amount of mystery that hangs around it. People scratch their heads and can't figure

MITOCW MITRES18_006F10_26_0501_300k-mp4

COMP 355 Advanced Algorithms Algorithm Design Review: Mathematical Background

Algebra. Here are a couple of warnings to my students who may be here to get a copy of what happened on a day that you missed.

Contents. 2.1 Vectors in R n. Linear Algebra (part 2) : Vector Spaces (by Evan Dummit, 2017, v. 2.50) 2 Vector Spaces

MITOCW watch?v=ko0vmalkgj8

MITOCW MITRES_18-007_Part1_lec5_300k.mp4

Science Literacy: Reading and Writing Diagrams Video Transcript

This is particularly true if you see long tails in your data. What are you testing? That the two distributions are the same!

Consider a complete bipartite graph with sets A and B, each with n vertices.

MITOCW MIT18_01SCF10Rec_24_300k

MITOCW MIT20_020S09_06_inverter

MITOCW watch?v=rf5sefhttwo

MITOCW MITRES18_006F10_26_0101_300k-mp4

1 Definitions and Things You Know

Mathematical Proofs. e x2. log k. a+b a + b. Carlos Moreno uwaterloo.ca EIT e π i 1 = 0.

Instructor (Brad Osgood)

Math 301: Matchings in Graphs

CS 6901 (Applied Algorithms) Lecture 2

Algorithms: COMP3121/3821/9101/9801

MITOCW MITRES18_005S10_DiffEqnsMotion_300k_512kb-mp4

Discrete Mathematics and Probability Theory Fall 2014 Anant Sahai Midterm 1

Algorithm Design and Analysis

Lesson 8: Velocity. Displacement & Time

MITOCW watch?v=pqkyqu11eta

MITOCW MIT18_02SCF10Rec_50_300k

Note: Please use the actual date you accessed this material in your citation.

MATH 22 FUNCTIONS: ORDER OF GROWTH. Lecture O: 10/21/2003. The old order changeth, yielding place to new. Tennyson, Idylls of the King

MITOCW MITRES18_005S10_DerivOfSinXCosX_300k_512kb-mp4

Violating the normal distribution assumption. So what do you do if the data are not normal and you still need to perform a test?

Lab Exercise 03: Gauss Law

MITOCW ocw f07-lec39_300k

Nondeterministic finite automata

Quadratic Equations Part I

ACCUPLACER MATH 0311 OR MATH 0120

Recommended Reading. A Brief History of Infinity The Mystery of the Aleph Everything and More

Lesson 29: Newton's Law of Universal Gravitation

MITOCW 6. Standing Waves Part I

Connectedness. Proposition 2.2. The following are equivalent for a topological space (X, T ).

MITOCW ocw nov2005-pt1-220k_512kb.mp4

MITOCW MITRES_6-007S11lec09_300k.mp4

18.02SC Multivariable Calculus, Fall 2010 Transcript Recitation 34, Integration in Polar Coordinates

EQ: How do I identify exponential growth? Bellwork:

MITOCW 18. Quiz Review From Optional Problem Set 8

More on Asymptotic Running Time Analysis CMPSC 122

Hypothesis testing I. - In particular, we are talking about statistical hypotheses. [get everyone s finger length!] n =

Mathematical Proofs. e x2. log k. a+b a + b. Carlos Moreno uwaterloo.ca EIT e π i 1 = 0.

MITOCW watch?v=4q0t9c7jotw

MITOCW ocw-5_60-s08-lec07_300k

Checkpoint Questions Due Monday, October 1 at 2:15 PM Remaining Questions Due Friday, October 5 at 2:15 PM

MITOCW 2. Harmonic Oscillators with Damping

Instructor (Brad Osgood)

Module 3 Study Guide. GCF Method: Notice that a polynomial like 2x 2 8 xy+9 y 2 can't be factored by this method.

Algorithm Design and Analysis

Lecture 5: The Principle of Deferred Decisions. Chernoff Bounds

Conditional probabilities and graphical models

PROFESSOR: WELCOME BACK TO THE LAST LECTURE OF THE SEMESTER. PLANNING TO DO TODAY WAS FINISH THE BOOK. FINISH SECTION 6.5

MITOCW R11. Double Pendulum System

The general topic for today is going to be oscillations, which are extremely important in the applications and in

Dialog on Simple Derivatives

MITOCW ocw f08-lec08_300k

Module 2 Study Guide. The second module covers the following sections of the textbook: , 4.1, 4.2, 4.5, and

1 / 9. Due Friday, May 11 th at 2:30PM. There is no checkpoint problem. CS103 Handout 30 Spring 2018 May 4, 2018 Problem Set 5

5 + 9(10) + 3(100) + 0(1000) + 2(10000) =

Ordinary Least Squares (OLS): Multiple Linear Regression (MLR) Assessment I What s New? & Goodness-of-Fit

15-451/651: Design & Analysis of Algorithms September 13, 2018 Lecture #6: Streaming Algorithms last changed: August 30, 2018

MITOCW MIT6_041F11_lec17_300k.mp4

e π i 1 = 0 Proofs and Mathematical Induction Carlos Moreno uwaterloo.ca EIT-4103 e x2 log k a+b a + b

PHYSICS 107. Lecture 3 Numbers and Units

Transcription:

CPSC 320 Sample Solution, Reductions and Resident Matching: A Residentectomy August 25, 2017 A group of residents each needs a residency in some hospital. A group of hospitals each need some number (one or more) of residents, with some hospitals needing more and some fewer. Each group has preferences over which member of the other group they'd like to end up with. The total number of slots in hospitals is exactly equal to the total number of residents. We want to ll the hospitals slots with residents in such a way that no resident and hospital that weren't matched up will collude to get around our suggestion (and give the resident a position at that hospital instead). Denitions: An instance of a problem is a particular input drawn from the space of possible inputs the problem allows. For example, the 4-element array [5, 1, 4, 3] is an instance of the problem of sorting arrays of integers. A reduction from problem P 1 to problem P 2 is an algorithm that solves P 1 using (but without needing to dene) an algorithm A P2 that solves P 2. Often, we put some restriction on the number of calls to A P2 (e.g., a polynomial number). We'll call a simple reduction a reduction in which only one call is made to A P2. This is the most common case we'll run into, and it's often easiest to think about this case by proceeding through these steps: 1. Change an instance of P 1 into an instance of P 2 by hand. 2. Change the corresponding solution to P 2 into a solution to P 1 by hand. 3. Design an algorithm to change instances of P 1 into instances of P 2. 4. Design an algorithm to change corresponding solutions to P 2 into solutions to P 1. 5. Prove that if the solution to the P 2 instance is correct, so too is the solution your algorithm creates for the original P 1 instance. (Or equivalently, if the P 1 solution generated is incorrect, then the P 2 solution must have been incorrect as well.) 1 Trivial and Small Instances 1. Write down all the trivial instances of RHP. We think of an instance as "trivial" roughly if its solution requires no real reasoning about the problem. SOLUTION: Certainly instances with 0 hospitals and 0 residents are trivial (solution: no matchings). Additionally, any time we have one hospital, no matter how big it is (and therefore how many residents there are), the solution will be trivial: place all residents with that one hospital. 2. Write down two small instances of RHP. Here's your rst: SOLUTION: Here's one, but it could as well be an SMP instance.

r1: h1 h2 h1: r2 r1 r2: h2 h1 h2: r1 r2 The other can be even smaller, but not trivial: SOLUTION: So, it's a good idea to make an instance that actually illustrates what's unique to our problem. (Otherwise, how will we know what to specify??) Here, the number in parentheses after a hospital indicates how many slots it has. r1: h1 h2 h1 (1): r2 r1 r3 r2: h2 h1 h2 (2): r1 r2 r3 r3: h1 h2 3. Hold this space for another instance, in case we need more. 2 Represent the Problem 1. What are the quantities that matter in this problem? Give them short, usable names. SOLUTION: Generally speaking, these will be the same as in the SMP problem. A few dierences: we'll let n = R (the size of the set of residents). Note that H R, but H may be much smaller. We need to know, for each hospital how, big it is. We'll say that s(h) is the number of slots in hospital h. 2. Go back up to your trivial and small instances and rewrite them using these names. SOLUTION: Not really necessary here, but that parenthetical after each hospital certainly was necessary to give its number of slots! 3. Use at least one visual/graphical/sketched representation of the problem to draw out the largest instance you've designed so far: SOLUTION: We'll do the same thing we did for SMP, move the preferences to the outside so there's a "gutter" down the middle to draw lines for possible solutions: h1 h2 :r1 h2 h1 :r2 h1 h2 :r3 h1 (1): r2 r1 r3 h2 (2): r1 r2 r3 4. Describe using your representational choices above what a valid instance looks like: SOLUTION: Again, this is much like SMP with some extra constraints, mostly focused on the s function that tells us how many slots a hospital has. In particular, for all h H, s(h) > 0. Further, n = h H s(h). That is, there are exactly enough slots for the residents. 3 Represent the Solution 1. What are the quantities that matter in the solution to the problem? Give them short, usable names. SOLUTION: Much like with SMP, the pairings between hospitals and residents matter. There are at least two ways to handle the fact that every hospital can match with multiple residents. (1) Use the same format as SMP but changed from man/woman to hospital/resident (a set of tuples of hospital and resident) but allow each hospital to appear multiple times. (2) Use tuples of a hospital and a set of residents. We'll use (1).

2. Describe using these quantities makes a solution valid and good: SOLUTION: Crucially, each resident must appear in exactly one tuple (be paired with one hospital), while each hospital h must appear in exactly s(h) tuples (be paired with as many residents as it has slots). Otherwise, this isn't a matching of residents with hospitals at all. BUT, what makes this matching stable? It's not quite the same as SMP. In particular, a resident will still want to get out of her matching if she can match with a hospital she prefers, but under what circumstances will a hospital agree to give up one of its current residents for her? Clearly, it has to prefer her to someone it was assigned. And, if it prefers her to anyone it was assigned, it prefers her to the resident it was assigned that it least prefers. So, a good denition of an instability is "a hospital h matched with residents H h = {r 1, r 2,... r s(h) } and resident r matched with h such that r prefers h to h and h prefers r to the member of H h it least prefers (the 'worst' member)." 3. Go back up to your trivial and small instances and write out one or more solutions to each using these names. SOLUTION: Let's actually write this here and just bring down the example: h1 h2 :r1 h2 h1 :r2 h1 h2 :r3 h1 (1): r2 r1 r3 h2 (2): r1 r2 r3 Using our notation, a solution might be {(h 1, r 1 ), (h 2, r 2 ), (h 2, r 3 )}. (This happens to be the only stable solution to this instance.) 4. Go back up to your drawn representation of an instance and draw at least one solution. SOLUTION: Working on the same repeated instance, here's that solution: r 1 r 2 h 1 h 2 r 3 4 Similar Problems Give at least one problem you've seen before that seems related in terms of its surface features ("story"), problem or solution structure, or representation to this one: SOLUTION: Obviously this is similar to SMP. It also has some similarities to USMP. (Perhaps adding fake entities to the hospital side will balance things out??) 5 Brute Force? We have a way to test if something that looks like a solution but may have an instability is stable. (From the "3" step.) That is, given a "valid" solution, we can check whether it's "good". 1. Sketch an algorithm to produce every valid solution. (It will help to give a name to your algorithm and its parameters, especially if your algorithm is recursive.) This will be similar to the brute force algorithm for SMP (from the challenge problems). SOLUTION: A bit less formally than last time, here's a solution sketch for an algorithm All- Solns(H, R, s):

(a) If H = 0, return { }. (b) Otherwise, let r be the rst element of R. (c) And, let M be an empty set (of solutions). (d) And, for each h H: i. Produce new set R = R {r}. ii. Produce new function s = s except that s (h) = s(h) 1. iii. Produce new set H as follows: if s (h) = 0, then H = H {h}; otherwise, H = H. (In other words, strip out r and one slot from h, removing h if it gets to 0 slots.) iv. For every solution m AllSolns(H, R, s ), add {(h, r)} m to M. (e) Finally, return M 2. Choose an appropriate variable to represent the "size" of an instance. SOLUTION: n seems appropriate. 3. Exactly or asymptotically, how many such "valid solutions" are there? (It will help to give a name to the number of solutions as a function of instance size.) SOLUTION: This is pretty messy. In particular, the rst hospital can be grouped with any subset of the residents of size s(h 1 ), and subsequent hospitals have that many fewer residents to "choose n! from". Overall, this looks something like h H (s(h))!. The point here is that the larger the hospitals are, the fewer solutions there are. Indeed, if there's one hospital taking almost all the residents, we actually have a small solution space to explore. However, if there are even two roughly-equal sized n! hospitals, we're looking at, which is super-exponentially huge. (n/2)! 2 4. Exactly or asymptotically, how long will it take to test whether a solution form is valid and good with a na\"ive approach? (Write out the na\"ive algorithm if it's not simple!) SOLUTION: Since we need to know the "worst" resident matched to each hospital, we might as well start by picking out that worst resident for each hospital. That takes O(n) = O( R ) time. Then, for each hospital/resident pair (of which there are H R ), if they're not matched, we check whether they prefer each other to their partners (in the hospital's case, its "worst" partner). With ecient solutions to each step (see 2.3 of the textbook!), we should be able to do this in O( H R ) time, or if hospitals take only a reasonable (constant, actually) number of residents, about O(n 2 ) time. 5. Will brute force be sucient for this problem for the domains we're interested in? SOLUTION: Not unless some hospital is taking almost everyone! 6 Promising Approach Unless brute force is good enough, describein as much detail as you canan approach that looks promising. THIS TIME, we use reduction: 1. Choose a problem P to reduce to. SOLUTION: Let's reduce to SMP. 2. Change an instance of RHP into an instance of P. SOLUTION: Here's our running example again:

h1 h2 :r1 h2 h1 :r2 h1 h2 :r3 h1 (1): r2 r1 r3 h2 (2): r1 r2 r3 We need to put one more item on the right. We also need to make sure h 2 gets matched with two residents. It seems like we can solve both these problems at once by "splitting up" h 2 : h1 h2 :r1 h1: r2 r1 r3 h2 h1 :r2 h2_1: r1 r2 r3 h1 h2 :r3 h2_2: r1 r2 r3 Now, each "half" of h 2 is its own "woman" (or "man", if you prefer). This isn't an SMP instance yet, however. The residents don't have enough preferences! Well, each resident will want the two h 2 slots essentially the same, but we don't allow ties. So, we'll just order them arbitrarily. (Why not in numerical order?) h1 h2_1 h2_2 :r1 h1: r2 r1 r3 h2_1 h2_2 h1 :r2 h2_1: r1 r2 r3 h1 h2_1 h2_2 :r3 h2_2: r1 r2 r3 Now that looks like an SMP instance. 3. Change the solution to P into a solution to RHP. SOLUTION: Running Gale-Shapley gives this solution: {(h 1, r 1 ), (h 21, r 2 ), (h 22, r 3 )}. That's already very close to the solution we found by hand of {(h 1, r 1 ), (h 2, r 2 ), (h 2, r 3 )}. It looks like we just need to erase the subscripts on the hospitals, since hospital-slots are no longer separate. 4. Design an algorithm to change any valid RHP instance into an instance of P. SOLUTION: This is probably the trickiest part. We need to eliminate the s function that tells us the size of hospitals. It also seems likely (as in USMP) that we'll want to make the two sets (residents and hospitals) have the same size. One way to accomplish both of those would be to make "clone" hospitals for every hospital that takes more than one resident. Actually, to make it easier to describe, let's say that will split every hospital h into s(h) "hospital-slots". Since we know h H s(h) is exactly the number of residents, this will give us a set of hospital-slots of the same size as the number of residents. However, we're not done. Each of these hospital-slots needs a preference list. And, the residents' preference lists must be augmented to include all these hospital slots instead of (as well as?) the original hospital. Well, we said "clone" for hospitals; so, let's try having each hospital-slot have the same preference list as the hospital it came from. There's no reason to think one "clone" is better than another, but we may as well have each resident replace a hospital h in their preference list with h 1, h 2,..., h k for k = s(h). That is, where they had hospital h, they now have one entry in order for each hospital-slot broken o of h (but all are worse than the hospital-slots coming from hospitals the resident preferred and better than those from hospitals the resident liked less). At that point, we can name "residents" to be "men" and "hospitals" to be "women" (or vice versa), and we have an SMP instance.

5. Design an algorithm to change the P instance's solution into the RHP instance's solution. SOLUTION: SMP will give us back a stable, perfect matching. With the solution representation we used, the only thing dierent about the SMP solution from a possibly-stable RHP solution would be the subscripts on the hospital-slots. If we erase those, then since each hospital-slot had one partner and each hospital had s(h) hospital-slots, each hospital in the RHP solution will now have s(h) partners, as we expect. (The residents will still each have exactly one partner, since we haven't changed them!) 6. Prove that the solution you get to the RHP instance is guaranteed to be correct. (Depending on your chosen reduction, you likely have a stable solution to an instance of P and need to show that you get a correct solution to the RHP instance, i.e., that the solution is "valid" (has the right form) and "good" (is stable). So, you'll prove either if P 's solution is correct, RHP's solution is correct or the contrapositive, if RHP's solution is incorrect, then P 's is incorrect as well.) SOLUTION: I'll do a bit of both. First, we already showed that SMP's perfect matching gives us a matching that follows the basic rules of RHP, i.e., each hospital is partnered with exactly the right number of residents (and each resident with exactly one hospital). Now, for the second constraint (stability), let's prove the contrapositive. So, assuming RHP's solution is unstable, we'll show that SMP's is unstable. Since RHP's solution is unstable, there must be some pair h and r that cause the instability. (Maybe multiple, but we don't care about that.) In particular: h is matched with residents H h = {r 1, r 2,... r s(h) } and resident r is matched with h such that r prefers h to h and h prefers r to the member of H h it least prefers (the 'worst' member). The pairing of r with h must have come from SMP's pairing of r with one of h 's slots, say h k. Let's also look at SMP's pairing of h with its least-preferred partner r. We don't know which slot of h's that is, but we'll say it's h j. We'd like to see that just as r and h form an instability in RHP, r and h j form an instability in SMP. Do they form an instability? Well, r prefers h to h in RHP. The "cloning" we did to split hospitals into hospital-slots keeps all the slots of a hospital together so they all still go before the same hospitals they used to go before. Thus, r must prefer all slots of h to all slots of h and so prefer h j to h k. Similarly, all of h's slots have the same preferences as h. So, just as h prefers r to r, h j must prefer r to r. Thus, r and h j do indeed constitute an instability. Why did we do all that again? Since the SMP solution is unstable if the RHP solution is unstable, that shows that the RHP solution is stable if the SMP solution is stable. We know the SMP solution is stable, which means the RHP one is as well! 7 Challenge Your Approach 1. Carefully run your algorithm on your instances above. (Don't skip steps or make assumptions; you're debugging!) Analyse its correctness and performance on these instances: SOLUTION: I'll leave this to you! (I cheated and jumped straight to a correct solution; so, this part is not as important for me.) 2. Design an instance that specically challenges the correctness (or performance) of your algorithm: SOLUTION: I'll leave this to you for the same reasons!