1 00:00:00,500 --> 00:00:02,660 The following content is provided under a Creative 2 00:00:02,660 --> 00:00:04,170 Commons license. 3 00:00:04,170 --> 00:00:06,520 Your support will help MIT OpenCourseWare 4 00:00:06,520 --> 00:00:10,880 continue to offer high quality educational resources for free. 5 00:00:10,880 --> 00:00:13,500 To make a donation or view additional materials 6 00:00:13,500 --> 00:00:17,372 from hundreds of MIT courses, visit MIT OpenCourseWare 7 00:00:17,372 --> 00:00:17,997 at ocw.mit.edu. 8 00:00:23,530 --> 00:00:28,500 PROFESSOR: OK, on Tuesday we talked about sex, 9 00:00:28,500 --> 00:00:32,520 so today we're going to talk about marriage. 10 00:00:32,520 --> 00:00:35,770 Now, in terms of graph theory, marriage 11 00:00:35,770 --> 00:00:38,970 is expressed as a matching problem, 12 00:00:38,970 --> 00:00:44,070 and today we're going to talk about a matching algorithm that 13 00:00:44,070 --> 00:00:46,070 is used in all sorts of applications. 14 00:00:46,070 --> 00:00:49,000 It's used by online dating agencies 15 00:00:49,000 --> 00:00:51,720 to match compatible people together. 16 00:00:51,720 --> 00:00:54,830 It's used for assignment problems, 17 00:00:54,830 --> 00:00:58,900 for example, matching interns to hospitals on match day. 18 00:00:58,900 --> 00:01:01,630 It's used for resource allocation problems, 19 00:01:01,630 --> 00:01:05,019 for example, load balancing traffic on the internet. 20 00:01:05,019 --> 00:01:06,570 And we'll talk about the applications 21 00:01:06,570 --> 00:01:09,070 at the end of class. 22 00:01:09,070 --> 00:01:11,960 In its simplest form of a matching problem, 23 00:01:11,960 --> 00:01:15,690 you have a graph where the edges represent compatibility. 24 00:01:15,690 --> 00:01:19,290 Two nodes can be paired together, or married, 25 00:01:19,290 --> 00:01:22,140 and the goal is to create the maximum number 26 00:01:22,140 --> 00:01:24,470 of compatible pairs. 27 00:01:24,470 --> 00:01:36,090 So let's define a matching, given a graph, G, 28 00:01:36,090 --> 00:01:45,830 with nodes, V, and edges, E. In matching, 29 00:01:45,830 --> 00:01:47,900 you can think of it as a collection of edges, 30 00:01:47,900 --> 00:01:58,220 or a subgraph of G where every node has degree 1. 31 00:01:58,220 --> 00:02:00,710 So everybody can be married just to one person. 32 00:02:13,960 --> 00:02:36,575 So let's draw an example, maybe not put that edge in. 33 00:02:40,752 --> 00:02:54,170 And let's label these nodes x1, x2, x3, x4, x5, x6, x7, and x8. 34 00:02:54,170 --> 00:03:06,630 Now x1, x6 and x2, x5 is a matching, so x1, x6 and x2, 35 00:03:06,630 --> 00:03:13,560 x5 is a matching with two edges, so we say it has size two. 36 00:03:19,930 --> 00:03:24,990 All right, so I can pair these guys up and pair these guys up. 37 00:03:24,990 --> 00:03:26,890 Is there any bigger matching in this graph? 38 00:03:31,420 --> 00:03:34,270 So I found one with two marriages, here 39 00:03:34,270 --> 00:03:35,860 and here, two edges. 40 00:03:35,860 --> 00:03:36,844 Yeah? 41 00:03:36,844 --> 00:03:38,320 AUDIENCE: x1, x7. 42 00:03:38,320 --> 00:03:40,140 PROFESSOR: x1, x7. 43 00:03:40,140 --> 00:03:41,670 AUDIENCE: x2, x6. 44 00:03:41,670 --> 00:03:42,990 PROFESSOR: x2, x6. 45 00:03:42,990 --> 00:03:44,044 AUDIENCE: [INAUDIBLE]. 46 00:03:44,044 --> 00:03:44,710 PROFESSOR: Good. 47 00:03:44,710 --> 00:03:47,330 All right, that's a matching of size three. 48 00:03:47,330 --> 00:03:49,840 So I got three couples together. 49 00:03:49,840 --> 00:03:51,790 Good. 50 00:03:51,790 --> 00:03:58,168 Can I make a bigger matching, one with size four-- 51 00:03:58,168 --> 00:03:59,370 four marriages here? 52 00:04:03,000 --> 00:04:04,130 No. 53 00:04:04,130 --> 00:04:05,030 Why not? 54 00:04:05,030 --> 00:04:07,620 Can anybody give me a reason why it can't be done? 55 00:04:12,480 --> 00:04:14,074 Yeah? 56 00:04:14,074 --> 00:04:20,810 AUDIENCE: x8 and x7 would have to be matched with someone. 57 00:04:20,810 --> 00:04:22,457 PROFESSOR: Yeah, so if-- Yeah? 58 00:04:22,457 --> 00:04:24,290 AUDIENCE: They could only be paired with x1, 59 00:04:24,290 --> 00:04:25,824 but x1 can't be paired with both. 60 00:04:25,824 --> 00:04:26,490 PROFESSOR: Good. 61 00:04:26,490 --> 00:04:30,080 If I were to have a matching with four edges, 62 00:04:30,080 --> 00:04:32,250 well, there's only eight nodes, so I'd 63 00:04:32,250 --> 00:04:35,800 have to have all eight nodes involved in the matching. 64 00:04:35,800 --> 00:04:38,920 And that means x7 and x8 would have to be in the matching, 65 00:04:38,920 --> 00:04:41,930 but they could only be paired with x1, 66 00:04:41,930 --> 00:04:45,054 and so it's not possible to do that. 67 00:04:45,054 --> 00:04:46,470 All right, so there is no matching 68 00:04:46,470 --> 00:04:47,810 of size four in this graph. 69 00:04:47,810 --> 00:04:50,310 Three is the best I can do. 70 00:04:50,310 --> 00:04:53,690 Now, when you get every node in a matching, 71 00:04:53,690 --> 00:04:56,460 then it's called a perfect matching. 72 00:04:56,460 --> 00:04:59,500 And so in this case, it doesn't exist, but sometimes it does. 73 00:05:05,010 --> 00:05:15,460 So a matching is perfect if it has 74 00:05:15,460 --> 00:05:21,780 size half the number of nodes. 75 00:05:21,780 --> 00:05:24,050 In other words, if the number of edges is v over 2, 76 00:05:24,050 --> 00:05:25,650 then every node is in the matching. 77 00:05:29,389 --> 00:05:31,680 All right, so that one doesn't have a perfect matching. 78 00:05:31,680 --> 00:05:32,600 What about this graph? 79 00:05:36,270 --> 00:05:47,740 So I got b1, b2, b3, b4, g1, g2, g3, g4, 80 00:05:47,740 --> 00:05:49,635 and I'll put in the compatibility edges here. 81 00:06:04,510 --> 00:06:11,040 OK, Does that graph have a perfect matching? 82 00:06:11,040 --> 00:06:13,360 Can you pair up every boy with a girl 83 00:06:13,360 --> 00:06:17,610 here so that everybody is compatible with their mate, 84 00:06:17,610 --> 00:06:20,948 and you have just one spouse? 85 00:06:20,948 --> 00:06:21,995 Can you do that? 86 00:06:24,717 --> 00:06:25,300 AUDIENCE: Yes. 87 00:06:25,300 --> 00:06:25,966 PROFESSOR: Yeah? 88 00:06:25,966 --> 00:06:27,730 All right, who do I start pairing up? 89 00:06:27,730 --> 00:06:29,350 AUDIENCE: 1, 1. 90 00:06:29,350 --> 00:06:32,130 AUDIENCE: 1, 1. 91 00:06:32,130 --> 00:06:33,190 AUDIENCE: b2, g3. 92 00:06:33,190 --> 00:06:33,940 PROFESSOR: b2, g3. 93 00:06:36,762 --> 00:06:37,470 AUDIENCE: b3, g2. 94 00:06:37,470 --> 00:06:39,382 PROFESSOR: b3, g2 95 00:06:39,382 --> 00:06:40,090 AUDIENCE: b4, g4. 96 00:06:40,090 --> 00:06:41,048 PROFESSOR: There we go. 97 00:06:41,048 --> 00:06:44,100 All right, so there is a perfect matching in this graph. 98 00:06:44,100 --> 00:06:47,000 Very good. 99 00:06:47,000 --> 00:06:50,790 Now, in some cases, some pairings 100 00:06:50,790 --> 00:06:53,560 are more desirable than others, and this can 101 00:06:53,560 --> 00:06:55,347 be represented with a weight. 102 00:06:55,347 --> 00:06:57,180 And so you might have a weighted graph where 103 00:06:57,180 --> 00:07:00,400 every edge has a weight on it. 104 00:07:00,400 --> 00:07:07,510 For example, we might weight b1, g2 with 5, 105 00:07:07,510 --> 00:07:11,170 and b1, g1 gets a 10. 106 00:07:11,170 --> 00:07:13,290 And usually when you see weighted graphs 107 00:07:13,290 --> 00:07:15,910 in the matching context, a lower weight 108 00:07:15,910 --> 00:07:21,000 means it's more desirable, so that b1 and g2 would get along 109 00:07:21,000 --> 00:07:24,510 better than b1 and g1. 110 00:07:24,510 --> 00:07:27,740 And then the goal is to find a matching with minimum weight. 111 00:07:32,270 --> 00:07:44,740 Now, the weight of a matching, call it M, 112 00:07:44,740 --> 00:08:01,400 is the sum of the weights on the edges of M. Now, 113 00:08:01,400 --> 00:08:03,940 usually when you're looking at weighted matchings, 114 00:08:03,940 --> 00:08:08,130 you require yourself to have a perfect matching so 115 00:08:08,130 --> 00:08:09,930 that everybody gets paired up. 116 00:08:09,930 --> 00:08:13,830 And often in that case, you'll see all the edges present, 117 00:08:13,830 --> 00:08:16,920 some of them with very big weights, maybe even infinity 118 00:08:16,920 --> 00:08:18,860 if they just can't be put together. 119 00:08:18,860 --> 00:08:21,539 Because otherwise you just say, don't match anybody together, 120 00:08:21,539 --> 00:08:22,580 and you have weight zero. 121 00:08:22,580 --> 00:08:25,620 So for when you look at minimum weight matchings, 122 00:08:25,620 --> 00:08:28,120 you're looking for the perfect matching with minimum weight. 123 00:08:32,450 --> 00:08:47,180 So we say a min-weight matching for a graph, G, 124 00:08:47,180 --> 00:08:59,410 is a perfect matching for G with the minimum weight, 125 00:08:59,410 --> 00:09:00,545 overall perfect matchings. 126 00:09:08,560 --> 00:09:09,690 Let's try an example. 127 00:09:14,140 --> 00:09:21,780 Say I've got this graph, and call this node Brad, 128 00:09:21,780 --> 00:09:28,626 here's Billy Bob, here's Jennifer, and then Angelina. 129 00:09:32,320 --> 00:09:34,870 And the weights are as follows-- I put a 10 here, 130 00:09:34,870 --> 00:09:38,710 a 10 down here, a 5 here, because Brad really 131 00:09:38,710 --> 00:09:42,790 likes Angelina and vice versa, and a 16 between Jennifer 132 00:09:42,790 --> 00:09:45,070 and Billy Bob. 133 00:09:45,070 --> 00:09:50,980 What is the weight of the min weight matching in that graph? 134 00:09:50,980 --> 00:09:52,080 20. 135 00:09:52,080 --> 00:09:54,760 And who gets paired with who there? 136 00:09:57,680 --> 00:09:59,710 Who does Brad get hooked up with? 137 00:09:59,710 --> 00:10:01,210 AUDIENCE: Jan. 138 00:10:01,210 --> 00:10:08,480 PROFESSOR: Jan, and that leaves Billy Bob with Angelina, 139 00:10:08,480 --> 00:10:11,030 and the weight is 20. 140 00:10:11,030 --> 00:10:15,700 So even though Brad really likes Angelina, if I go that route, 141 00:10:15,700 --> 00:10:18,730 my weight is 21, which is not as good. 142 00:10:18,730 --> 00:10:21,240 So the min-weight matching would be this one. 143 00:10:24,121 --> 00:10:24,620 OK. 144 00:10:24,620 --> 00:10:28,890 Now, it turns out that finding the maximum matching-- 145 00:10:28,890 --> 00:10:31,580 the maximum number of edges you can put together-- 146 00:10:31,580 --> 00:10:35,580 or finding the minimum weight perfect matching, 147 00:10:35,580 --> 00:10:38,110 those are both solvable, tractable problems. 148 00:10:38,110 --> 00:10:41,910 You don't get a million dollar prize for solving that. 149 00:10:41,910 --> 00:10:45,440 The algorithm is run in quadratic to cubic time, 150 00:10:45,440 --> 00:10:49,330 so not terrible, but they're not NP-complete, 151 00:10:49,330 --> 00:10:50,720 so people know how to do it. 152 00:10:50,720 --> 00:10:52,790 Now, they are pretty complicated, 153 00:10:52,790 --> 00:10:55,310 so we're not going to cover them in 6042. 154 00:10:55,310 --> 00:10:58,180 What we're going to do is look at a slightly different version 155 00:10:58,180 --> 00:11:00,414 of the problem that actually turns out 156 00:11:00,414 --> 00:11:02,330 to be more useful in practice, because there's 157 00:11:02,330 --> 00:11:04,970 a very nice algorithm for it. 158 00:11:04,970 --> 00:11:06,980 Now, in the version of the problem that we're 159 00:11:06,980 --> 00:11:11,720 going to look at, everybody has preferences-- a preference 160 00:11:11,720 --> 00:11:12,560 list. 161 00:11:12,560 --> 00:11:15,490 It's not weighted, but it's a priority order 162 00:11:15,490 --> 00:11:19,540 of who they want to get mated to, or matched up with. 163 00:11:19,540 --> 00:11:21,654 So it would look not quite like that, 164 00:11:21,654 --> 00:11:22,820 but it would look like this. 165 00:11:28,630 --> 00:11:40,480 So Brad, Billy Bob, Jennifer, and Angelina-- same players, 166 00:11:40,480 --> 00:11:45,050 but what we do is we know that Brad really likes Angelina, 167 00:11:45,050 --> 00:11:48,440 and Angelina really likes Brad, so they are first choices, 168 00:11:48,440 --> 00:11:50,660 at least was. 169 00:11:50,660 --> 00:11:54,990 Number two for Brad is Jennifer, but Jennifer really likes Brad 170 00:11:54,990 --> 00:11:57,900 first, and Billy Bob second. 171 00:11:57,900 --> 00:12:02,200 Billy Bob likes Angelina first, then Jennifer. 172 00:12:02,200 --> 00:12:05,370 Angelina thinks Billy Bob is number two. 173 00:12:05,370 --> 00:12:08,740 So it's not necessarily symmetric. 174 00:12:08,740 --> 00:12:10,720 Jennifer has Brad as the first choice. 175 00:12:10,720 --> 00:12:13,350 Brad has Angelina as the first choice. 176 00:12:13,350 --> 00:12:13,850 All right? 177 00:12:13,850 --> 00:12:17,420 So it's an asymmetric situation. 178 00:12:17,420 --> 00:12:21,960 Now, what would happen if we set up our marriages so that Brad 179 00:12:21,960 --> 00:12:25,310 is married to Jen, and Billy Bob is married to Angelina? 180 00:12:28,280 --> 00:12:30,970 What might happen if we made those as our pairings, 181 00:12:30,970 --> 00:12:33,420 and we put them on a desert island, all four of them? 182 00:12:33,420 --> 00:12:36,469 What's likely to happen there? 183 00:12:36,469 --> 00:12:39,010 AUDIENCE: Brad and Angelina are going to cheat on each other. 184 00:12:39,010 --> 00:12:41,220 PROFESSOR: Yeah, we're going to have a problem. 185 00:12:41,220 --> 00:12:44,680 Because Brad and Angelina have the hots for each other here, 186 00:12:44,680 --> 00:12:47,860 and they like each other better than their spouse. 187 00:12:47,860 --> 00:12:49,360 So before you know it, they're going 188 00:12:49,360 --> 00:12:53,869 to be doing their 6042 homework together late at night. 189 00:12:53,869 --> 00:12:55,170 All right? 190 00:12:55,170 --> 00:12:58,330 Now, when this happens, we have what's called a rogue couple. 191 00:13:05,380 --> 00:13:14,880 Given a matching, x and y, a boy and a girl, 192 00:13:14,880 --> 00:13:39,640 say, form a rogue couple if they prefer each other 193 00:13:39,640 --> 00:13:53,470 over their mates in M. All right. 194 00:13:53,470 --> 00:13:56,140 So here, if we married Brad to Jennifer, 195 00:13:56,140 --> 00:13:58,860 and Billy Bob to Angelina, Brad and Angelina 196 00:13:58,860 --> 00:14:00,280 form a rogue couple, because they 197 00:14:00,280 --> 00:14:03,759 like each other better than who they were hooked up with. 198 00:14:03,759 --> 00:14:05,050 And that's sort of a bad thing. 199 00:14:05,050 --> 00:14:07,810 It creates instability if you were 200 00:14:07,810 --> 00:14:10,530 to make the matchings that way. 201 00:14:10,530 --> 00:14:25,240 In fact, we say that a matching is stable 202 00:14:25,240 --> 00:14:28,235 if there aren't any rogue couples. 203 00:14:38,890 --> 00:14:43,410 And now, one thing to make clear is that your preferences 204 00:14:43,410 --> 00:14:45,330 can't change over time. 205 00:14:45,330 --> 00:14:48,094 So it's not a situation where you get bored with your spouse, 206 00:14:48,094 --> 00:14:49,510 and you change your mind, and then 207 00:14:49,510 --> 00:14:51,730 you go off and create a rogue couple. 208 00:14:51,730 --> 00:14:54,840 You're fixed in your preferences over all time, 209 00:14:54,840 --> 00:14:57,150 no playing the field, none of that stuff here, OK? 210 00:14:57,150 --> 00:15:01,590 So it's fixed once and for all, and your goal, of course, 211 00:15:01,590 --> 00:15:06,720 is to create or find a perfect matching that's stable. 212 00:15:06,720 --> 00:15:07,410 That's the goal. 213 00:15:11,060 --> 00:15:14,070 So get everybody married up and make it stable. 214 00:15:26,820 --> 00:15:29,750 All right, is it doable in that example? 215 00:15:29,750 --> 00:15:31,890 If I put those four people on a desert island, 216 00:15:31,890 --> 00:15:37,250 could I make a stable matching? 217 00:15:37,250 --> 00:15:39,430 Yeah, who would I match Brad to? 218 00:15:39,430 --> 00:15:40,330 AUDIENCE: Angelina. 219 00:15:40,330 --> 00:15:41,204 PROFESSOR: All right. 220 00:15:41,204 --> 00:15:43,650 Good, and then Billy Bob gets Jennifer. 221 00:15:43,650 --> 00:15:48,250 Now, I'm not saying that you make everybody happy, 222 00:15:48,250 --> 00:15:51,820 because Billy Bob and Jennifer are probably not happy there. 223 00:15:51,820 --> 00:15:53,760 They each got their number two choice. 224 00:15:53,760 --> 00:15:57,150 But it's stable, because Brad and Angelina 225 00:15:57,150 --> 00:15:58,277 aren't going anywhere. 226 00:15:58,277 --> 00:16:00,110 They are going to stay together because they 227 00:16:00,110 --> 00:16:03,232 like each other best, and so there's no chance that Jennifer 228 00:16:03,232 --> 00:16:06,810 is going to-- that Angelina is going to sneak off, sorry, 229 00:16:06,810 --> 00:16:10,990 with Billy Bob, or that Brad's going 230 00:16:10,990 --> 00:16:12,500 to sneak off with Jennifer. 231 00:16:12,500 --> 00:16:13,000 All right? 232 00:16:13,000 --> 00:16:14,040 So it's stable. 233 00:16:14,040 --> 00:16:19,510 Not everybody's happy, but it's a stable set of marriages. 234 00:16:19,510 --> 00:16:22,020 OK. 235 00:16:22,020 --> 00:16:24,360 Any questions about what we're trying to do here now? 236 00:16:24,360 --> 00:16:25,212 Yeah? 237 00:16:25,212 --> 00:16:30,292 AUDIENCE: [INAUDIBLE] the edges? 238 00:16:30,292 --> 00:16:31,750 PROFESSOR: That's a great question. 239 00:16:31,750 --> 00:16:34,200 You'll see it referred to both ways. 240 00:16:34,200 --> 00:16:37,495 Technically, it's a subgraph, so it has nodes and edges, 241 00:16:37,495 --> 00:16:39,870 but you'll see me, and you'll see everybody say, oh, it's 242 00:16:39,870 --> 00:16:42,165 a bunch of edges that don't share any nodes, 243 00:16:42,165 --> 00:16:44,040 and you'll see them refer to it as the edges. 244 00:16:44,040 --> 00:16:48,320 But really, underlying that, it's a subgraph, technically. 245 00:16:48,320 --> 00:16:51,590 Any other questions about what we're 246 00:16:51,590 --> 00:16:55,100 trying to do here to find stable, perfect matching? 247 00:16:57,842 --> 00:16:58,760 All right. 248 00:16:58,760 --> 00:17:02,900 Well, in this example, there was a stable, perfect matching. 249 00:17:02,900 --> 00:17:04,288 But what about in general? 250 00:17:04,288 --> 00:17:05,829 If I have a lot more people, and they 251 00:17:05,829 --> 00:17:08,910 have arbitrary preferences, how many people 252 00:17:08,910 --> 00:17:14,099 think you can always find a stable perfect matching? 253 00:17:14,099 --> 00:17:15,774 There's one optimistic person. 254 00:17:15,774 --> 00:17:18,190 How many people think there's some cases where you're just 255 00:17:18,190 --> 00:17:20,790 not going to be able to do it? 256 00:17:20,790 --> 00:17:21,329 Wow. 257 00:17:21,329 --> 00:17:23,450 OK, it's a pessimistic view. 258 00:17:23,450 --> 00:17:27,099 Well, in some sense you're both right. 259 00:17:27,099 --> 00:17:33,820 If you allow boys to prefer boys and girls to prefer girls, 260 00:17:33,820 --> 00:17:36,600 then it is not possible, and I'll give you an example. 261 00:17:36,600 --> 00:17:39,560 You can find examples where there's always a rogue couple, 262 00:17:39,560 --> 00:17:44,000 but if you require boys to only get matched to girls and vice 263 00:17:44,000 --> 00:17:48,920 versa, then it is possible to always find stable marriages, 264 00:17:48,920 --> 00:17:50,294 stable matchings. 265 00:17:50,294 --> 00:17:52,460 And we're going to talk about an algorithm for that. 266 00:17:52,460 --> 00:17:54,870 But before I show you the algorithm, 267 00:17:54,870 --> 00:17:59,040 let me show you the bad case when boys can prefer boys, 268 00:17:59,040 --> 00:18:03,460 or what's sort of a unisex scenario. 269 00:18:03,460 --> 00:18:07,130 So here's a bad example with four people, 270 00:18:07,130 --> 00:18:10,900 and the idea is to create a love triangle. 271 00:18:10,900 --> 00:18:20,020 So we have Alex, who prefers Bobby Joe, Bobby Joe prefers 272 00:18:20,020 --> 00:18:25,620 Robin, and Robin prefers Alex. 273 00:18:25,620 --> 00:18:28,060 And their second choices go in the opposite order 274 00:18:28,060 --> 00:18:28,850 there, all right? 275 00:18:28,850 --> 00:18:31,100 So Alex wants to be with Bobby Joe. 276 00:18:31,100 --> 00:18:32,350 Bobby Joe wants be with Robin. 277 00:18:32,350 --> 00:18:33,750 Robin wants to be with Alex. 278 00:18:33,750 --> 00:18:35,417 And then there's Mergatoid-- 279 00:18:35,417 --> 00:18:35,916 [LAUGHTER] 280 00:18:38,260 --> 00:18:40,310 --and nobody likes Mergatoid. 281 00:18:40,310 --> 00:18:45,780 So that's choice three for all of them here. 282 00:18:45,780 --> 00:18:48,520 And Mergatoid's choices, preferences 283 00:18:48,520 --> 00:18:50,670 don't really matter in this case. 284 00:18:50,670 --> 00:18:51,170 [LAUGHTER] 285 00:18:53,420 --> 00:18:57,220 I hope nobody is named Mergatoid in the class. 286 00:18:57,220 --> 00:18:59,220 I would get complaints here. 287 00:18:59,220 --> 00:19:02,520 All right, so I want to claim and prove 288 00:19:02,520 --> 00:19:06,130 a theorem that says there is no stable matching 289 00:19:06,130 --> 00:19:08,960 for this group of preferences. 290 00:19:08,960 --> 00:19:11,336 So we'll state that as the theorem. 291 00:19:11,336 --> 00:19:18,060 There does not exist a stable matching for this graph. 292 00:19:23,030 --> 00:19:26,430 The proof is by contradiction-- assume there is one. 293 00:19:36,260 --> 00:19:40,212 All right, so assume there exists a stable matching. 294 00:19:40,212 --> 00:19:41,920 We're going to find a rogue couple in it. 295 00:19:44,570 --> 00:19:54,790 So call the stable matching M. Well, 296 00:19:54,790 --> 00:19:56,940 if there's a stable matching, Mergatoid's got 297 00:19:56,940 --> 00:19:58,065 to get married to somebody. 298 00:20:10,620 --> 00:20:12,635 Mergatoid will be matched with someone. 299 00:20:19,630 --> 00:20:20,130 All right. 300 00:20:20,130 --> 00:20:21,790 Now, here I'm going to do something 301 00:20:21,790 --> 00:20:23,540 that you can do in your proofs, but you've 302 00:20:23,540 --> 00:20:24,915 got to be careful when you do it. 303 00:20:24,915 --> 00:20:28,450 I'm going to say, without loss of generality, 304 00:20:28,450 --> 00:20:34,250 assume Mergatoid is matched to Alex, all right? 305 00:20:34,250 --> 00:20:35,610 And I can do that. 306 00:20:35,610 --> 00:20:37,340 So this is the abbreviation, without loss 307 00:20:37,340 --> 00:20:39,175 of generality by symmetry. 308 00:20:43,080 --> 00:20:46,265 And really, I should explain what I mean here in the proof. 309 00:20:46,265 --> 00:20:49,506 Well, that love triangle is symmetric. 310 00:20:49,506 --> 00:20:51,380 Each one has a preference for the next person 311 00:20:51,380 --> 00:20:53,670 around the triangle. 312 00:20:53,670 --> 00:20:56,610 In terms of graph isomorphism, with the weights on that, 313 00:20:56,610 --> 00:20:58,030 every node looks the same. 314 00:20:58,030 --> 00:20:59,880 So I can use symmetry. 315 00:20:59,880 --> 00:21:03,570 So we're going to say, without loss of generality, 316 00:21:03,570 --> 00:21:12,015 we're going to assume Mergatoid is matched to Alex. 317 00:21:16,410 --> 00:21:19,140 And I'm implying the argument is going to be the same. 318 00:21:19,140 --> 00:21:21,730 What I say next is the same no matter 319 00:21:21,730 --> 00:21:25,665 who Mergatoid is matched to, because it's symmetric. 320 00:21:25,665 --> 00:21:26,165 All right. 321 00:21:26,165 --> 00:21:28,510 If Mergatoid is matched to Alex, do you 322 00:21:28,510 --> 00:21:29,920 see a rogue couple up there? 323 00:21:36,410 --> 00:21:38,520 So you have Robin matched to Bobby Joe. 324 00:21:38,520 --> 00:21:41,476 Mergatoid is matched to Alex. 325 00:21:41,476 --> 00:21:43,330 AUDIENCE: Alex to Bobby Joe? 326 00:21:43,330 --> 00:21:46,756 PROFESSOR: Alex and Bobby Joe, no. 327 00:21:46,756 --> 00:21:48,130 AUDIENCE: Between Alex and Robin. 328 00:21:48,130 --> 00:21:49,800 PROFESSOR: Alex and Robin, yeah. 329 00:21:49,800 --> 00:21:56,560 Alex and Bobby Joe aren't rogue, because Bobby Joe likes Robin. 330 00:21:56,560 --> 00:22:00,040 He likes the person he or she is married to. 331 00:22:00,040 --> 00:22:02,570 All right, so they're not going to go off with Alex, 332 00:22:02,570 --> 00:22:04,450 but Alex and Robin are a rogue couple, 333 00:22:04,450 --> 00:22:08,060 because Robin likes Alex the best, and Alex for sure 334 00:22:08,060 --> 00:22:10,630 likes Robin better than Mergatoid. 335 00:22:10,630 --> 00:22:11,130 All right? 336 00:22:11,130 --> 00:22:14,730 So they both prefer each other to their mates, 337 00:22:14,730 --> 00:22:16,820 and so they form a rogue couple. 338 00:22:19,640 --> 00:22:31,080 All right, so Alex and Robin form a rogue couple, 339 00:22:31,080 --> 00:22:33,760 and that means that M was not stable. 340 00:22:37,540 --> 00:22:41,250 The matching was not stable. 341 00:22:41,250 --> 00:22:43,510 And that's a contradiction, because we assumed it was. 342 00:22:46,290 --> 00:22:49,535 So we have a contradiction, and the proof is done. 343 00:22:52,250 --> 00:22:55,210 Any questions about that? 344 00:22:55,210 --> 00:22:58,370 And I'm sort of implying here that you could match, 345 00:22:58,370 --> 00:23:01,840 you could have had Mergatoid matched to Bobby Joe, 346 00:23:01,840 --> 00:23:04,960 and then Bobby Joe and Alex would have been a rogue couple, 347 00:23:04,960 --> 00:23:09,490 or Mergatoid matched to Robin, and then Robin and Bobby Joe 348 00:23:09,490 --> 00:23:13,857 would be a rogue couple by the without loss of generality. 349 00:23:13,857 --> 00:23:15,940 So it's OK to use that, but you want to be careful 350 00:23:15,940 --> 00:23:18,925 that you're doing it OK. 351 00:23:18,925 --> 00:23:19,425 Questions? 352 00:23:22,241 --> 00:23:22,740 Yeah? 353 00:23:22,740 --> 00:23:25,030 AUDIENCE: So the without loss of generality only 354 00:23:25,030 --> 00:23:27,320 works if it's, like, perfectly symmetric? 355 00:23:27,320 --> 00:23:28,337 PROFESSOR: Yeah. 356 00:23:28,337 --> 00:23:30,170 Basically, the argument you're going to make 357 00:23:30,170 --> 00:23:32,710 is just going to be the same argument done in all three 358 00:23:32,710 --> 00:23:35,844 cases, and to save yourself some effort, you're saying, 359 00:23:35,844 --> 00:23:38,010 don't do the three cases, do one, the other two look 360 00:23:38,010 --> 00:23:38,990 the same. 361 00:23:38,990 --> 00:23:41,630 So technically, you could add case one, case two, case three, 362 00:23:41,630 --> 00:23:44,240 and they would've looked symmetric. 363 00:23:44,240 --> 00:23:46,300 OK? 364 00:23:46,300 --> 00:23:46,800 All right. 365 00:23:46,800 --> 00:23:50,300 Now, this is not very surprising, as you all voted. 366 00:23:50,300 --> 00:23:53,087 Almost all of you said it's hard to find stable matchings. 367 00:23:53,087 --> 00:23:54,670 You might not be able to do it always. 368 00:23:54,670 --> 00:23:57,880 And in fact, you can't in the unisex world. 369 00:23:57,880 --> 00:24:02,250 The surprising thing is, you can always find a stable matching 370 00:24:02,250 --> 00:24:05,410 in the world where boys could only be paired 371 00:24:05,410 --> 00:24:08,340 with girls and vice versa. 372 00:24:08,340 --> 00:24:12,750 Now, this statement, this result is pretty famous. 373 00:24:12,750 --> 00:24:19,300 The problem itself is known as the stable marriage problem. 374 00:24:19,300 --> 00:24:23,130 So let me just define it here, and then we'll 375 00:24:23,130 --> 00:24:27,360 talk about an algorithm to find the matching. 376 00:24:44,030 --> 00:24:47,785 So we have N boys and N girls. 377 00:24:51,110 --> 00:24:54,190 And it's important we have the same number of each. 378 00:24:54,190 --> 00:24:56,110 Now, actually, tomorrow, in recitation, you're 379 00:24:56,110 --> 00:24:59,540 going to look at the scenario where there's more 380 00:24:59,540 --> 00:25:02,010 girls than boys, or vice versa. 381 00:25:02,010 --> 00:25:04,330 And you'll be using a similar algorithm, 382 00:25:04,330 --> 00:25:05,750 but it'll be a different context, 383 00:25:05,750 --> 00:25:07,530 and that's the context that comes up 384 00:25:07,530 --> 00:25:11,077 in matching interns to hospitals, and stuff like that. 385 00:25:11,077 --> 00:25:13,535 But for our version it's an equal number of boys and girls. 386 00:25:17,690 --> 00:25:28,960 Each boy has his own ranked preference 387 00:25:28,960 --> 00:25:35,190 list of all the girls. 388 00:25:35,190 --> 00:25:37,850 So every boy sort of has his dance card 389 00:25:37,850 --> 00:25:40,781 of the girls that he likes in order. 390 00:25:40,781 --> 00:25:41,280 All right? 391 00:25:41,280 --> 00:25:43,580 The orders can be different for different boys. 392 00:25:43,580 --> 00:25:46,820 And each girl has the same thing. 393 00:25:46,820 --> 00:25:52,510 She has her own list, ranked 1 to n of all the boys. 394 00:25:55,670 --> 00:25:58,390 The lists are complete, and there's no ties, 395 00:25:58,390 --> 00:26:01,930 so all the ties have to be broken here. 396 00:26:01,930 --> 00:26:03,884 And the goal is to find a perfect matching 397 00:26:03,884 --> 00:26:04,800 without rogue couples. 398 00:26:25,840 --> 00:26:28,150 OK, so let's try an example. 399 00:26:28,150 --> 00:26:32,730 Before we do the algorithm, let me just do a bigger example 400 00:26:32,730 --> 00:26:36,530 with five boys and five girls, and we'll 401 00:26:36,530 --> 00:26:39,870 get some feel for, this is not completely obvious how 402 00:26:39,870 --> 00:26:40,760 to find it. 403 00:27:02,910 --> 00:27:08,360 OK, so let's put the boys over here. 404 00:27:08,360 --> 00:27:13,250 And here's boy 1, and his preference list 405 00:27:13,250 --> 00:27:23,140 is going to be-- the girls will be C, B, E, A, D, and boy 406 00:27:23,140 --> 00:27:28,460 2 is going to have the preference list 407 00:27:28,460 --> 00:27:47,720 A, B, E, C, D, and boy 3 is going to have D, C, B, A, E. 408 00:27:47,720 --> 00:27:57,345 Boy 4 is going to be A, C, D, B, E, and boy 5, 409 00:27:57,345 --> 00:28:04,100 I have to write his across like this, A, B, D, E, C. 410 00:28:04,100 --> 00:28:07,970 And the girls also have their lists, so let's put those up. 411 00:28:14,870 --> 00:28:25,480 So girl A likes the boys in order 3, 5, 2, 1, 4. 412 00:28:25,480 --> 00:28:32,590 Girl B likes them in order 5, 2, 1, 4, 3. 413 00:28:37,880 --> 00:28:45,000 Girl C has the order 4, 3, 5, 1, 2. 414 00:28:45,000 --> 00:28:55,200 Girl D, 1, 2, 3, 4, 5, and then the last girl, E, 415 00:28:55,200 --> 00:29:00,130 has 2, 3, 4, 1, 5. 416 00:29:00,130 --> 00:29:03,220 All right, so say that's our matching problem, 417 00:29:03,220 --> 00:29:06,580 and those are the preference lists. 418 00:29:06,580 --> 00:29:08,960 Any ideas for how we might try to make an algorithm 419 00:29:08,960 --> 00:29:09,460 to do this? 420 00:29:09,460 --> 00:29:11,665 Any thoughts about what you'd do? 421 00:29:11,665 --> 00:29:13,290 What are some approaches we could take? 422 00:29:13,290 --> 00:29:13,710 Yeah? 423 00:29:13,710 --> 00:29:15,110 AUDIENCE: Use the mating algorithm. 424 00:29:15,110 --> 00:29:16,170 PROFESSOR: Use the greedy algorithm? 425 00:29:16,170 --> 00:29:17,690 AUDIENCE: The mating algorithm. 426 00:29:17,690 --> 00:29:18,500 PROFESSOR: Oh, the mating algorithm. 427 00:29:18,500 --> 00:29:21,020 Well, yeah, the mating algorithm is going to do very well, 428 00:29:21,020 --> 00:29:22,520 but I haven't told you what that is, 429 00:29:22,520 --> 00:29:24,320 and it's a little complicated. 430 00:29:24,320 --> 00:29:26,880 So I sort of want to explore the things you might know 431 00:29:26,880 --> 00:29:30,000 from what we've done so far. 432 00:29:30,000 --> 00:29:34,830 What approaches have we seen so far for solving problems? 433 00:29:34,830 --> 00:29:35,605 Yeah? 434 00:29:35,605 --> 00:29:37,030 AUDIENCE: The greedy algorithm? 435 00:29:37,030 --> 00:29:38,910 PROFESSOR: The greedy algorithm-- yep. 436 00:29:38,910 --> 00:29:41,500 And let's try that. 437 00:29:41,500 --> 00:29:45,990 So let's choose the first boy, and we'll just 438 00:29:45,990 --> 00:29:48,855 go down and give each boy the best choice available 439 00:29:48,855 --> 00:29:49,730 and see what happens. 440 00:29:52,370 --> 00:29:54,540 First thing to try usually is the greedy algorithm, 441 00:29:54,540 --> 00:29:57,220 and about half the time it'll work in life, 442 00:29:57,220 --> 00:29:58,600 and half the time it won't. 443 00:30:02,620 --> 00:30:03,765 So let's try greedy. 444 00:30:07,530 --> 00:30:14,240 So boy 1 is going to get his first choice, girl C. Who 445 00:30:14,240 --> 00:30:15,310 does boy 2 get? 446 00:30:18,560 --> 00:30:22,990 A. Who does boy 3 get? 447 00:30:22,990 --> 00:30:25,340 D. Huh, this is going well. 448 00:30:25,340 --> 00:30:26,390 Who does boy 4 get? 449 00:30:29,460 --> 00:30:33,450 Boy 4, oh yeah, boy 4 has got to go all the way down to B, 450 00:30:33,450 --> 00:30:35,860 because A, C, and D got taken, so boy 4 451 00:30:35,860 --> 00:30:40,840 gets B. And boy 5-- who's left? 452 00:30:40,840 --> 00:30:43,790 E, fourth choice again. 453 00:30:43,790 --> 00:30:49,320 All right, well, maybe that's a stable matching. 454 00:30:49,320 --> 00:30:50,745 All right, well let's see. 455 00:30:50,745 --> 00:30:52,370 To see if it's stable, we've got to see 456 00:30:52,370 --> 00:30:55,400 are there any rogue couples. 457 00:30:55,400 --> 00:31:00,030 Well, is there any rogue couple involving boy 1? 458 00:31:00,030 --> 00:31:02,070 No, boy 1 got his first choice. 459 00:31:02,070 --> 00:31:04,000 You're not going anywhere. 460 00:31:04,000 --> 00:31:05,670 Boy 2? 461 00:31:05,670 --> 00:31:08,080 No-- first choice, same with boy 3. 462 00:31:08,080 --> 00:31:09,650 These boys are quite happy. 463 00:31:09,650 --> 00:31:11,770 They're not doing anything. 464 00:31:11,770 --> 00:31:14,550 Boy 4 may not be so happy though, 465 00:31:14,550 --> 00:31:18,510 because boy 4 got paired with B, so there's 466 00:31:18,510 --> 00:31:19,950 possible rogue couples. 467 00:31:19,950 --> 00:31:22,090 Let's see, is 4, A a rogue couple? 468 00:31:25,650 --> 00:31:26,920 No. 469 00:31:26,920 --> 00:31:29,660 A hates boy 4, all right? 470 00:31:29,660 --> 00:31:32,566 No chance she's running off with boy 4. 471 00:31:32,566 --> 00:31:33,542 AUDIENCE: 4, C? 472 00:31:33,542 --> 00:31:34,720 PROFESSOR: 4, C? 473 00:31:34,720 --> 00:31:36,330 All right, let's see that. 474 00:31:36,330 --> 00:31:39,570 Where's C-- whoa, yeah. 475 00:31:39,570 --> 00:31:43,510 C has the hots for boy 4, so she likes 476 00:31:43,510 --> 00:31:45,990 him better than whoever her mate was, 477 00:31:45,990 --> 00:31:49,380 and boy 4 likes C better than who he got matched with, 478 00:31:49,380 --> 00:31:51,840 boy B. That is now a rogue couple, 479 00:31:51,840 --> 00:31:54,550 so the greedy algorithm did not work. 480 00:31:54,550 --> 00:31:55,860 That's too bad. 481 00:31:55,860 --> 00:31:57,400 Well, it would be short lecture, I guess, if it worked. 482 00:31:57,400 --> 00:31:57,900 [LAUGHTER] 483 00:32:01,310 --> 00:32:06,850 Well, what would you do next, sort of, if you were-- I mean, 484 00:32:06,850 --> 00:32:11,760 you could try to match 4 with C, and then try to patch things 485 00:32:11,760 --> 00:32:14,070 up, and you could start doing that, 486 00:32:14,070 --> 00:32:16,300 but you might create other rogue couples. 487 00:32:16,300 --> 00:32:18,318 In fact, I don't know an approach-- yeah? 488 00:32:18,318 --> 00:32:20,026 AUDIENCE: You could let it evolve and see 489 00:32:20,026 --> 00:32:21,370 if it gets it more stable. 490 00:32:21,370 --> 00:32:22,370 PROFESSOR: Say it again. 491 00:32:22,370 --> 00:32:22,853 AUDIENCE: You could let it evolve, 492 00:32:22,853 --> 00:32:25,268 let all the rogue couples evolve and see 493 00:32:25,268 --> 00:32:26,717 if it ends up any more stable. 494 00:32:26,717 --> 00:32:29,080 PROFESSOR: Yes, you could start swapping around 495 00:32:29,080 --> 00:32:31,360 to get rid of rogue couples. 496 00:32:31,360 --> 00:32:34,570 In doing that, you might create other rogue couples. 497 00:32:34,570 --> 00:32:36,380 In fact, I don't know of an algorithm that 498 00:32:36,380 --> 00:32:38,650 works like this, that works, that's known to work, 499 00:32:38,650 --> 00:32:40,569 where you start patching things up, 500 00:32:40,569 --> 00:32:42,110 because as you're patching things up, 501 00:32:42,110 --> 00:32:45,610 you might make other things much worse by doing that. 502 00:32:45,610 --> 00:32:47,660 So I don't know of an approach that way. 503 00:32:50,040 --> 00:32:51,040 What's another approach? 504 00:32:51,040 --> 00:32:51,550 Yeah? 505 00:32:51,550 --> 00:32:57,490 AUDIENCE: [INAUDIBLE] pertaining to what order 506 00:32:57,490 --> 00:32:58,480 they have each other. 507 00:32:58,480 --> 00:32:59,965 PROFESSOR: And then do? 508 00:32:59,965 --> 00:33:02,440 AUDIENCE: And then do the highest ordered [INAUDIBLE] 509 00:33:02,440 --> 00:33:04,420 PROFESSOR: Min-weight matching kind of thing? 510 00:33:04,420 --> 00:33:04,915 AUDIENCE: Maybe. 511 00:33:04,915 --> 00:33:05,623 PROFESSOR: Maybe? 512 00:33:05,623 --> 00:33:09,200 I don't of an approach like that that works. 513 00:33:09,200 --> 00:33:11,190 Also, min-weight matching, that algorithm 514 00:33:11,190 --> 00:33:12,880 is going to be more complicated than the one I'm 515 00:33:12,880 --> 00:33:14,130 going to show you, in the end. 516 00:33:14,130 --> 00:33:16,344 It takes more time to run. 517 00:33:16,344 --> 00:33:17,760 And I don't even know if it works. 518 00:33:17,760 --> 00:33:19,770 Like, I don't know if you can take these numbers 519 00:33:19,770 --> 00:33:22,115 and make weights on the edges get a min-weight matching. 520 00:33:22,115 --> 00:33:25,072 AUDIENCE: Could you do like a merge sort [INAUDIBLE] 521 00:33:25,072 --> 00:33:27,660 PROFESSOR: Oh, a merge sort, so you take the minimum weight 522 00:33:27,660 --> 00:33:31,449 edge, put that in, and recurse on that kind of thing. 523 00:33:31,449 --> 00:33:31,990 I don't know. 524 00:33:31,990 --> 00:33:33,857 It's possible. 525 00:33:33,857 --> 00:33:35,690 In fact, you know what, a recursive approach 526 00:33:35,690 --> 00:33:37,180 is a good idea. 527 00:33:37,180 --> 00:33:40,210 I don't know of a nice recursive algorithm for this. 528 00:33:40,210 --> 00:33:42,450 It's true that if you found a boy and a girl who 529 00:33:42,450 --> 00:33:45,430 liked each other best, you could then 530 00:33:45,430 --> 00:33:47,989 match them safely and recurse, because you know they're not 531 00:33:47,989 --> 00:33:49,780 going to be in a rogue couple, because they 532 00:33:49,780 --> 00:33:50,990 like each other best. 533 00:33:50,990 --> 00:33:52,610 Then you could recurse. 534 00:33:52,610 --> 00:33:54,835 But that might not exist here. 535 00:33:54,835 --> 00:33:56,210 You might not have a boy and girl 536 00:33:56,210 --> 00:33:59,450 that like each other best, in which case it's hard to know. 537 00:33:59,450 --> 00:34:02,350 I don't know now if you pick the minimum weight in some sense, 538 00:34:02,350 --> 00:34:05,290 like add the preference list or something to make a min-weight 539 00:34:05,290 --> 00:34:07,240 and recurse on that, if that works. 540 00:34:07,240 --> 00:34:09,670 I don't know of an approach like that. 541 00:34:09,670 --> 00:34:11,638 But those are the kinds of things you try. 542 00:34:11,638 --> 00:34:13,429 And as far as I know, all the simple things 543 00:34:13,429 --> 00:34:15,199 fail for this problem. 544 00:34:15,199 --> 00:34:19,889 But there is something that's a little more involved, 545 00:34:19,889 --> 00:34:22,980 but does work, and that's the mating algorithm. 546 00:34:22,980 --> 00:34:25,437 And does everybody have the handout? 547 00:34:25,437 --> 00:34:26,520 There, it's back up there. 548 00:34:26,520 --> 00:34:30,237 I got some copies down here if you need it, but pull that out. 549 00:34:30,237 --> 00:34:32,559 So we're going to read this and talk 550 00:34:32,559 --> 00:34:34,100 about what the algorithm is, and then 551 00:34:34,100 --> 00:34:37,540 prove that it performs well. 552 00:34:37,540 --> 00:34:42,199 So the initial condition is you have each of the N boys 553 00:34:42,199 --> 00:34:47,110 has an ordered list of the N girls and vice versa, 554 00:34:47,110 --> 00:34:50,460 and the ritual, we're going to view this is a mating ritual, 555 00:34:50,460 --> 00:34:52,136 and really, the program is doing it. 556 00:34:52,136 --> 00:34:53,010 The code is doing it. 557 00:34:53,010 --> 00:34:55,060 But think of it as real life. 558 00:34:55,060 --> 00:34:58,130 It takes place over several days. 559 00:34:58,130 --> 00:35:01,260 Now, the day is broken up into three parts-- the morning, 560 00:35:01,260 --> 00:35:02,760 the afternoon, and the evening. 561 00:35:02,760 --> 00:35:05,850 In the morning, each girl comes out to her balcony 562 00:35:05,850 --> 00:35:08,290 and stands on the balcony. 563 00:35:08,290 --> 00:35:14,190 Each boy goes to the balcony of his favorite girl who 564 00:35:14,190 --> 00:35:16,800 is still on his list that hasn't been crossed off. 565 00:35:16,800 --> 00:35:18,550 Now, initially, every girl is on his list. 566 00:35:18,550 --> 00:35:21,830 So he goes to his favorite girl, goes under her balcony, 567 00:35:21,830 --> 00:35:24,070 and serenades her. 568 00:35:24,070 --> 00:35:25,990 Now, if, over the course of the algorithm, 569 00:35:25,990 --> 00:35:30,470 the boy has nobody left on his list, he's out of luck. 570 00:35:30,470 --> 00:35:32,330 He just stays home and does homework. 571 00:35:32,330 --> 00:35:32,830 All right? 572 00:35:32,830 --> 00:35:35,240 There's no serenade anymore for him. 573 00:35:35,240 --> 00:35:38,320 Now, in the afternoon, the girls who 574 00:35:38,320 --> 00:35:41,420 have at least one suitor-- a boy down there serenading 575 00:35:41,420 --> 00:35:46,130 her-- looks at all the suitors, picks her favorite, 576 00:35:46,130 --> 00:35:49,380 and to the favorite she says, maybe I'll marry you. 577 00:35:49,380 --> 00:35:51,810 Come back tomorrow. 578 00:35:51,810 --> 00:35:54,720 Girls don't want to make it too easy here for the boys. 579 00:35:54,720 --> 00:35:57,770 Now, to all the other boys who are lower priority she says, 580 00:35:57,770 --> 00:35:59,670 I will never marry you. 581 00:35:59,670 --> 00:36:01,060 Go away. 582 00:36:01,060 --> 00:36:04,390 So she writes them off for good. 583 00:36:04,390 --> 00:36:08,340 Now, that night, any boy who heard a no-- like the girl 584 00:36:08,340 --> 00:36:12,640 said no, I'll never marry you-- crosses that girl off his list. 585 00:36:12,640 --> 00:36:14,880 Because, you know, it's the only practical thing 586 00:36:14,880 --> 00:36:16,730 to do at that point. 587 00:36:16,730 --> 00:36:19,729 Now, if the boy heard the maybe I'll marry you, 588 00:36:19,729 --> 00:36:21,270 well, he's going to go back tomorrow, 589 00:36:21,270 --> 00:36:23,700 because that's still his favorite girl that's 590 00:36:23,700 --> 00:36:24,740 not crossed off. 591 00:36:24,740 --> 00:36:26,450 So he goes back and serenades her again 592 00:36:26,450 --> 00:36:30,650 the next day in the hopes that eventually, she'll say yes. 593 00:36:30,650 --> 00:36:34,150 Now, we keep doing this every day, OK? 594 00:36:34,150 --> 00:36:38,640 And if we ever encounter a day where every girl has, 595 00:36:38,640 --> 00:36:43,650 at most, one suitor, the algorithm stops, and then 596 00:36:43,650 --> 00:36:47,860 every girl who has a suitor says, yes, I will marry you. 597 00:36:47,860 --> 00:36:49,470 Now, if a girl doesn't have a suitor, 598 00:36:49,470 --> 00:36:51,050 there's no one to marry her. 599 00:36:51,050 --> 00:36:53,100 We're going to prove that doesn't happen, OK? 600 00:36:53,100 --> 00:36:55,880 But determination condition is, you no longer 601 00:36:55,880 --> 00:36:59,810 have a situation with two or more boys under one balcony. 602 00:36:59,810 --> 00:37:02,120 OK? 603 00:37:02,120 --> 00:37:11,097 All right, so let's run that algorithm on this example, 604 00:37:11,097 --> 00:37:12,680 just so we make sure we understand it, 605 00:37:12,680 --> 00:37:15,350 because I'm going to try to prove theorems about it. 606 00:37:15,350 --> 00:37:20,390 So here are the serenades that are going on, 607 00:37:20,390 --> 00:37:26,140 and here's the girls, and the days. 608 00:37:26,140 --> 00:37:28,840 It's going to work over four days in this case. 609 00:37:35,280 --> 00:37:40,450 And then we're also going to keep track of the boy's lists-- 610 00:37:40,450 --> 00:37:41,690 who's gotten crossed off. 611 00:37:52,180 --> 00:37:55,020 All right, so these will be the cross outs down here. 612 00:37:55,020 --> 00:37:56,982 Actually, maybe I'll fit it up here if I can. 613 00:38:02,390 --> 00:38:06,340 Girls, let's see, A, B-- no, I'm going to have to space it out. 614 00:38:15,900 --> 00:38:18,880 And the boys have their lists here, 615 00:38:18,880 --> 00:38:22,050 and we have boys 1, 2, 3, 4, 5. 616 00:38:22,050 --> 00:38:24,080 And here I'm going to record the cross outs. 617 00:38:28,980 --> 00:38:31,220 All right, so let's look at day one. 618 00:38:34,300 --> 00:38:39,878 Who is under girl A's balcony on day one? 619 00:38:39,878 --> 00:38:40,794 AUDIENCE: 2, 4, and 5? 620 00:38:40,794 --> 00:38:43,480 PROFESSOR: 2, 4, and 5-- each like girl A the best, 621 00:38:43,480 --> 00:38:45,800 so she's got a lot of activity. 622 00:38:45,800 --> 00:38:47,900 These three boys show up. 623 00:38:47,900 --> 00:38:51,470 Anybody under girl B's balcony? 624 00:38:51,470 --> 00:38:54,380 No, nope, no, nothing there. 625 00:38:54,380 --> 00:38:58,370 C, does C have anybody? 626 00:38:58,370 --> 00:38:59,450 Boy 1, yeah. 627 00:38:59,450 --> 00:39:01,600 D? 628 00:39:01,600 --> 00:39:06,850 3, and E, I don't think there's any action, right? 629 00:39:06,850 --> 00:39:07,966 Nope. 630 00:39:07,966 --> 00:39:12,220 All right, so that's the status on day one. 631 00:39:12,220 --> 00:39:15,732 So the action is all up here. 632 00:39:15,732 --> 00:39:19,670 All right, so what does girl A do? 633 00:39:19,670 --> 00:39:21,713 Who does she tell to hang around? 634 00:39:21,713 --> 00:39:22,879 AUDIENCE: Number 5. 635 00:39:22,879 --> 00:39:23,920 PROFESSOR: Number 5, yes. 636 00:39:23,920 --> 00:39:27,210 She's got 5, 4, and 2, and she likes 5 the best. 637 00:39:27,210 --> 00:39:30,330 She tells 5 to come back, and she says to these guys, 638 00:39:30,330 --> 00:39:32,180 we're not going to marry him. 639 00:39:32,180 --> 00:39:38,710 That means that boys 2 and 4 cross girl A off their list. 640 00:39:38,710 --> 00:39:43,445 So they say A is no longer possible for them. 641 00:39:43,445 --> 00:39:48,610 All right, now we go to day two, and 5 goes back 642 00:39:48,610 --> 00:39:51,760 to girl A, and, of course, boys 1 and 3 stay there. 643 00:39:51,760 --> 00:39:56,030 Where does boy 2 go on day two? 644 00:39:56,030 --> 00:39:57,330 B. 645 00:39:57,330 --> 00:40:01,462 All right, so boy 2 shows up here on day two, 646 00:40:01,462 --> 00:40:04,900 and, let's see, boy 5 is already there, 647 00:40:04,900 --> 00:40:06,545 and then we've got to get boy 4. 648 00:40:06,545 --> 00:40:08,860 Where does he go now? 649 00:40:08,860 --> 00:40:14,160 C. All right, boy 4 shows up here. 650 00:40:14,160 --> 00:40:18,580 All right, so now the action is with girl C. 651 00:40:18,580 --> 00:40:20,233 And what does she do? 652 00:40:20,233 --> 00:40:22,690 AUDIENCE: [INAUDIBLE] 653 00:40:22,690 --> 00:40:26,320 PROFESSOR: Yeah, she keeps 4, and she boots poor 1. 654 00:40:26,320 --> 00:40:28,180 You know, led him along for a day, 655 00:40:28,180 --> 00:40:31,520 and then he gets the boot because boy 4 showed up, right? 656 00:40:31,520 --> 00:40:36,400 Because girl C likes 4 better than 1, so bad 657 00:40:36,400 --> 00:40:38,450 luck for 1 there. 658 00:40:38,450 --> 00:40:46,370 So now one goes home that night and crosses off girl C. 659 00:40:46,370 --> 00:40:48,100 OK. 660 00:40:48,100 --> 00:40:52,340 All right, and where does 1 go on day three? 661 00:40:52,340 --> 00:40:57,020 All right, so he goes to-- he crossed off C-- he goes to B. 662 00:40:57,020 --> 00:40:58,500 All right, so this is left over. 663 00:40:58,500 --> 00:41:07,820 We have 5, 2, 4, 3-- boy 1 now goes to B, right? 664 00:41:07,820 --> 00:41:10,610 OK. 665 00:41:10,610 --> 00:41:13,090 And then what does girl B do? 666 00:41:13,090 --> 00:41:16,030 Who does she keep around? 667 00:41:16,030 --> 00:41:20,580 Keeps 2, boots poor 1. 668 00:41:20,580 --> 00:41:24,130 All right, so 1 says, all right, I'm crossing B off my list, 669 00:41:24,130 --> 00:41:26,370 got the message. 670 00:41:26,370 --> 00:41:28,670 And now where does boy 1 go on day four? 671 00:41:28,670 --> 00:41:30,080 AUDIENCE: Girl E? 672 00:41:30,080 --> 00:41:31,440 PROFESSOR: E-- third choice. 673 00:41:31,440 --> 00:41:32,470 OK. 674 00:41:32,470 --> 00:41:38,200 So 1 shows up down here, and these guys keep returning. 675 00:41:38,200 --> 00:41:42,660 Wow, so on day four there's no more fighting. 676 00:41:42,660 --> 00:41:44,700 Every girl has at most one. 677 00:41:44,700 --> 00:41:47,110 The termination condition is invoked, 678 00:41:47,110 --> 00:41:49,490 and these are the marriages that take place. 679 00:41:49,490 --> 00:41:50,550 The girls say yes. 680 00:41:53,712 --> 00:41:54,920 All right, now is everybody-- 681 00:41:54,920 --> 00:41:56,720 [LAUGHTER] 682 00:41:56,720 --> 00:42:00,140 --does everybody understand the algorithm we used? 683 00:42:00,140 --> 00:42:01,520 Any questions on the algorithm? 684 00:42:04,026 --> 00:42:04,525 Yeah? 685 00:42:04,525 --> 00:42:07,886 AUDIENCE: [INAUDIBLE] the first case [INAUDIBLE] or 686 00:42:07,886 --> 00:42:11,080 is that just in case the [INAUDIBLE] 687 00:42:11,080 --> 00:42:13,945 PROFESSOR: That's in case the algorithm doesn't work. 688 00:42:13,945 --> 00:42:15,570 Because we haven't proved it works yet, 689 00:42:15,570 --> 00:42:18,830 and I gotta have a possibility for, 690 00:42:18,830 --> 00:42:20,560 a boy crosses every girl off his list, 691 00:42:20,560 --> 00:42:22,274 he gets rejected everywhere. 692 00:42:22,274 --> 00:42:23,690 That is a possibility, so I've got 693 00:42:23,690 --> 00:42:26,150 to say what would happen in that possibility. 694 00:42:26,150 --> 00:42:28,250 Now, we will prove in a few minutes 695 00:42:28,250 --> 00:42:32,430 that condition never arises, OK? 696 00:42:32,430 --> 00:42:34,080 But I'm giving you what might happen, 697 00:42:34,080 --> 00:42:36,580 in which so it never does, so no boy ends up 698 00:42:36,580 --> 00:42:39,610 having to stay home and do homework here. 699 00:42:39,610 --> 00:42:42,100 All right, so that's the algorithm. 700 00:42:42,100 --> 00:42:46,770 Now let's see if we can see if there's any rogue couples. 701 00:42:46,770 --> 00:42:52,920 All right, so, for example, let's look at boy 1. 702 00:42:52,920 --> 00:42:57,405 Boy 1 got paired to his third choice, E, so 1, 703 00:42:57,405 --> 00:43:01,260 C might be a rogue couple. 704 00:43:01,260 --> 00:43:04,100 Is that possible? 705 00:43:04,100 --> 00:43:08,590 No, because C got 4 here, which is her first choice. 706 00:43:08,590 --> 00:43:10,250 She's not going with boy 1. 707 00:43:10,250 --> 00:43:11,450 That's not working. 708 00:43:11,450 --> 00:43:14,190 What about 1, B? 709 00:43:14,190 --> 00:43:16,470 Could that be rogue? 710 00:43:16,470 --> 00:43:23,745 No, B got 2, and B likes 2 better than 1, so 1, C and 1, 711 00:43:23,745 --> 00:43:24,510 B are not rogue. 712 00:43:24,510 --> 00:43:27,810 And 1 got E, so there's no other possibility for boy 1, 713 00:43:27,810 --> 00:43:30,840 so boy 1 is not in a rogue couple. 714 00:43:30,840 --> 00:43:33,342 What about boy 2? 715 00:43:33,342 --> 00:43:39,410 2 got B, and that's 2's second choice. 716 00:43:39,410 --> 00:43:40,240 What about 2, A? 717 00:43:43,860 --> 00:43:52,180 Let's see, A got 5, and A likes 5 better than 2, 718 00:43:52,180 --> 00:43:53,240 so that's not rogue. 719 00:43:53,240 --> 00:43:55,710 Boy 2 is not rogue. 720 00:43:55,710 --> 00:44:04,840 All right, boy 3-- boy 3 got his first choice, right? 721 00:44:04,840 --> 00:44:09,720 3 got D, so 3 is not going anywhere. 722 00:44:09,720 --> 00:44:19,034 Boy 4 got-- who did boy 4 get-- got C. 4 got his second choice. 723 00:44:19,034 --> 00:44:19,700 What about 4, A? 724 00:44:23,370 --> 00:44:25,040 A hates 4. 725 00:44:25,040 --> 00:44:28,760 A is not gonna get caught dead with 4, so that's not rogue. 726 00:44:28,760 --> 00:44:29,766 So 4 is OK. 727 00:44:29,766 --> 00:44:30,890 4 is not in a rogue couple. 728 00:44:30,890 --> 00:44:37,295 And finally, boy 5-- boy 5 is paired with A, 729 00:44:37,295 --> 00:44:40,260 and that is boy 5's first choice, 730 00:44:40,260 --> 00:44:42,760 so he's not wandering off here. 731 00:44:42,760 --> 00:44:43,260 All right? 732 00:44:43,260 --> 00:44:46,060 So in fact, we've just argued that this 733 00:44:46,060 --> 00:44:52,720 is a stable set of marriages, a stable matching in this case. 734 00:44:52,720 --> 00:44:56,351 Any questions now about what we're trying to do? 735 00:44:56,351 --> 00:44:58,100 OK, because we're going to try to show now 736 00:44:58,100 --> 00:45:02,040 it always produces a stable matching. 737 00:45:02,040 --> 00:45:06,020 And to do that, we need to do a few things. 738 00:45:16,355 --> 00:45:17,730 All right, so what are the things 739 00:45:17,730 --> 00:45:20,450 we need to show to prove everything 740 00:45:20,450 --> 00:45:23,357 is going to be good here? 741 00:45:23,357 --> 00:45:24,690 What are some facts we to prove? 742 00:45:24,690 --> 00:45:25,462 Yeah? 743 00:45:25,462 --> 00:45:28,415 AUDIENCE: Don't we need to show that the algorithm, it does 744 00:45:28,415 --> 00:45:29,045 come to an end? 745 00:45:29,045 --> 00:45:29,670 PROFESSOR: Yes. 746 00:45:29,670 --> 00:45:30,169 [LAUGHTER] 747 00:45:30,750 --> 00:45:33,650 The algorithm terminates, so we need 748 00:45:33,650 --> 00:45:39,080 to show that the marriage algorithm, TMA, terminates. 749 00:45:39,080 --> 00:45:41,490 Otherwise, the boys are serenading forever, 750 00:45:41,490 --> 00:45:44,360 and that's not too good. 751 00:45:44,360 --> 00:45:46,100 All right, what else do we want to show? 752 00:45:46,100 --> 00:45:47,055 Yeah? 753 00:45:47,055 --> 00:45:49,909 AUDIENCE: If it does terminate, then one is left empty. 754 00:45:49,909 --> 00:45:50,575 PROFESSOR: Then? 755 00:45:50,575 --> 00:45:52,170 AUDIENCE: Everyone gets someone. 756 00:45:52,170 --> 00:45:54,163 PROFESSOR: Everyone gets married. 757 00:45:56,790 --> 00:45:59,700 Yep. 758 00:45:59,700 --> 00:46:01,550 Stability is easy if nobody gets married. 759 00:46:05,820 --> 00:46:07,910 All right, what else do we want to show here? 760 00:46:07,910 --> 00:46:08,185 Yeah? 761 00:46:08,185 --> 00:46:09,390 AUDIENCE: There are no rogue couples. 762 00:46:09,390 --> 00:46:10,640 PROFESSOR: No rogue couples. 763 00:46:19,000 --> 00:46:22,280 All right, what else might we like to show? 764 00:46:22,280 --> 00:46:23,710 These are the three main ones. 765 00:46:23,710 --> 00:46:25,230 There's a couple of other things you might like. 766 00:46:25,230 --> 00:46:25,668 Yeah? 767 00:46:25,668 --> 00:46:26,751 AUDIENCE: It runs quickly. 768 00:46:26,751 --> 00:46:28,659 PROFESSOR: It runs quickly. 769 00:46:28,659 --> 00:46:30,325 Well, you can only serenade for so long. 770 00:46:35,174 --> 00:46:36,840 In fact, it does run quickly, and that's 771 00:46:36,840 --> 00:46:38,850 why it's useful in practice. 772 00:46:38,850 --> 00:46:41,992 Anything else you might want to show about this algorithm? 773 00:46:41,992 --> 00:46:43,756 AUDIENCE: How many people you crossed out? 774 00:46:43,756 --> 00:46:46,190 PROFESSOR: How many people you crossed out-- yeah, 775 00:46:46,190 --> 00:46:49,370 you could, and that'll tie into how long it takes. 776 00:46:49,370 --> 00:46:51,267 Yeah. 777 00:46:51,267 --> 00:46:51,850 Anything else? 778 00:46:51,850 --> 00:46:52,349 Yeah? 779 00:46:52,349 --> 00:46:58,230 AUDIENCE: The average likeness between the couples. 780 00:46:58,230 --> 00:46:59,970 PROFESSOR: The average likeness, oh. 781 00:46:59,970 --> 00:47:02,985 So yeah, we haven't had a notion here 782 00:47:02,985 --> 00:47:05,610 of how happy people are at the end, 783 00:47:05,610 --> 00:47:07,716 because we don't have a weighting on the edges, 784 00:47:07,716 --> 00:47:09,340 but you might want to think about that. 785 00:47:09,340 --> 00:47:10,548 That's actually a good point. 786 00:47:10,548 --> 00:47:11,567 Yeah? 787 00:47:11,567 --> 00:47:13,352 AUDIENCE: If they [INAUDIBLE] if it 788 00:47:13,352 --> 00:47:16,437 matters who serenades [INAUDIBLE] girls or boys 789 00:47:16,437 --> 00:47:17,411 to get her. 790 00:47:17,411 --> 00:47:19,120 PROFESSOR: That's a great point. 791 00:47:19,120 --> 00:47:23,360 Is this algorithm good for girls, or good for boys? 792 00:47:23,360 --> 00:47:26,760 Yeah, that's a good point-- fairness. 793 00:47:26,760 --> 00:47:29,910 All right, so we'll take a look at fairness also. 794 00:47:29,910 --> 00:47:32,760 Is it better to be a serenader, or be on the balcony making 795 00:47:32,760 --> 00:47:35,060 your choices? 796 00:47:35,060 --> 00:47:36,680 OK, so this is what we've got to do. 797 00:47:40,030 --> 00:47:42,415 So let's start by showing TMA terminates, 798 00:47:42,415 --> 00:47:43,998 and that it terminates pretty quickly. 799 00:47:53,460 --> 00:47:55,860 Now, in fact, I'm going to prove a fairly crude bound 800 00:47:55,860 --> 00:48:01,560 on the time, but it actually does fairly well. 801 00:48:01,560 --> 00:48:04,180 So our first theorem is going to be 802 00:48:04,180 --> 00:48:15,070 that TMA terminates in, at most, N squared plus 1 days. 803 00:48:18,090 --> 00:48:20,583 N is the number of boys and girls. 804 00:48:20,583 --> 00:48:22,333 The proof is going to be by contradiction. 805 00:48:25,252 --> 00:48:26,710 This is probably the only day where 806 00:48:26,710 --> 00:48:29,126 we'll do a bunch of proofs and none of them use induction. 807 00:48:31,380 --> 00:48:34,750 They're pretty much all by contradiction. 808 00:48:34,750 --> 00:48:50,649 Suppose TMA does not terminate in N squared plus 1 days, 809 00:48:50,649 --> 00:48:53,065 because we're going to show that leads to a contradiction. 810 00:49:01,050 --> 00:49:03,670 We need to show that some kind of progress 811 00:49:03,670 --> 00:49:06,420 is made each day to show that it terminates. 812 00:49:06,420 --> 00:49:07,206 Yeah? 813 00:49:07,206 --> 00:49:09,910 AUDIENCE: [INAUDIBLE] the number of causes that have 814 00:49:09,910 --> 00:49:12,682 [INAUDIBLE], so if it has not terminated, 815 00:49:12,682 --> 00:49:15,787 then at least one girl is seeing a group of at least one guy-- 816 00:49:15,787 --> 00:49:16,412 PROFESSOR: Yes. 817 00:49:16,412 --> 00:49:18,822 AUDIENCE: --so the number of crosses cannot be defined 818 00:49:18,822 --> 00:49:19,786 [INAUDIBLE] 819 00:49:19,786 --> 00:49:20,750 PROFESSOR: Very good. 820 00:49:20,750 --> 00:49:23,460 OK, let's state that as a claim, and you've 821 00:49:23,460 --> 00:49:26,890 given the proof of the claim, which is great. 822 00:49:26,890 --> 00:49:38,160 If we don't terminate, on a day, that 823 00:49:38,160 --> 00:49:42,770 must be because a girl had two boys there, or more, therefore 824 00:49:42,770 --> 00:49:45,230 she rejected some, at least one. 825 00:49:45,230 --> 00:49:49,720 And that night, the rejected boy crosses a girl off his list. 826 00:49:52,440 --> 00:49:56,160 So if we don't terminate, then at least one boy 827 00:49:56,160 --> 00:49:58,730 crosses at least one girl off his list. 828 00:50:06,000 --> 00:50:10,820 And so we're going to measure progress by the cross outs. 829 00:50:15,220 --> 00:50:18,150 So every day we don't terminate, a boy 830 00:50:18,150 --> 00:50:20,670 crossed a girl off his list, so if we didn't terminate 831 00:50:20,670 --> 00:50:22,650 at N squared plus 1 days, we must 832 00:50:22,650 --> 00:50:30,390 have crossed off N squared plus 1 girls across all the lists. 833 00:50:30,390 --> 00:50:33,390 Well, is that possible? 834 00:50:33,390 --> 00:50:35,670 To have done N squared plus 1 cross outs? 835 00:50:40,130 --> 00:50:41,600 What do you think? 836 00:50:41,600 --> 00:50:43,510 How many names are on each list? 837 00:50:43,510 --> 00:50:44,900 AUDIENCE: N. 838 00:50:44,900 --> 00:50:47,766 PROFESSOR: N, and how many lists are there? 839 00:50:47,766 --> 00:50:48,620 AUDIENCE: N. 840 00:50:48,620 --> 00:50:56,120 PROFESSOR: N, so there's N lists with N names implies 841 00:50:56,120 --> 00:51:00,870 there's, at most, N squared cross outs ever. 842 00:51:00,870 --> 00:51:03,530 But we just said we had N squared plus 1 cross outs. 843 00:51:06,220 --> 00:51:11,566 But we have also N squared plus 1 cross outs, 844 00:51:11,566 --> 00:51:12,690 and that's a contradiction. 845 00:51:15,930 --> 00:51:17,210 All right? 846 00:51:17,210 --> 00:51:18,720 So we're done. 847 00:51:18,720 --> 00:51:23,282 It has to terminate within N squared plus 1 days. 848 00:51:23,282 --> 00:51:23,865 Any questions? 849 00:51:26,500 --> 00:51:30,630 This is a very common proof technique in computer science. 850 00:51:30,630 --> 00:51:33,560 You're analyzing some system, and every step 851 00:51:33,560 --> 00:51:36,100 or every day or every time period, 852 00:51:36,100 --> 00:51:38,434 you want to argue progress got made, 853 00:51:38,434 --> 00:51:40,350 and then after you've made enough progress you 854 00:51:40,350 --> 00:51:46,130 have to be done, and therefore, the algorithm is completed. 855 00:51:46,130 --> 00:51:48,967 All right, so we know that TMA terminates. 856 00:51:48,967 --> 00:51:50,800 Now, we've still got to get everyone married 857 00:51:50,800 --> 00:51:53,690 and have them all be happy, or at least stable. 858 00:51:56,400 --> 00:51:59,140 Now, to do this, we're going to use an invariant. 859 00:51:59,140 --> 00:52:00,583 Yeah? 860 00:52:00,583 --> 00:52:03,308 AUDIENCE: If a girl has some guy in front 861 00:52:03,308 --> 00:52:05,874 of [INAUDIBLE] on something, then she 862 00:52:05,874 --> 00:52:08,770 will always have [INAUDIBLE] 863 00:52:08,770 --> 00:52:10,400 PROFESSOR: That is true. 864 00:52:10,400 --> 00:52:14,060 Something even stronger is true. 865 00:52:14,060 --> 00:52:15,490 AUDIENCE: All the [INAUDIBLE] 866 00:52:15,490 --> 00:52:17,556 PROFESSOR: Have a-- 867 00:52:17,556 --> 00:52:19,916 PROFESSOR: If she has a preference for someone who 868 00:52:19,916 --> 00:52:24,170 [INAUDIBLE] only better guys. 869 00:52:24,170 --> 00:52:26,860 PROFESSOR: Yeah, that's a great invariant. 870 00:52:26,860 --> 00:52:29,390 As the girl is sitting there on her balcony, 871 00:52:29,390 --> 00:52:32,730 things only get better, because she always 872 00:52:32,730 --> 00:52:35,920 keeps the best one around that's there. 873 00:52:35,920 --> 00:52:37,610 And when new ones come in, they've 874 00:52:37,610 --> 00:52:41,110 got to be better than the last one for her to keep them. 875 00:52:41,110 --> 00:52:44,810 So as she rejects boys, she only does that because she's 876 00:52:44,810 --> 00:52:47,330 got better ones there, and whoever she says maybe to 877 00:52:47,330 --> 00:52:48,780 always comes back. 878 00:52:48,780 --> 00:52:51,420 So an invariant of this algorithm 879 00:52:51,420 --> 00:52:56,400 is that when a girl has a suitor, going forward, 880 00:52:56,400 --> 00:52:59,720 she only has suitors she likes at least as well. 881 00:52:59,720 --> 00:53:02,310 And if she ever rejects a boy, then she's 882 00:53:02,310 --> 00:53:05,780 got somebody better there forever. 883 00:53:05,780 --> 00:53:09,421 All right, so let's state that as an invariant and prove that. 884 00:53:26,610 --> 00:53:29,980 OK, so we're going to let P be our invariant here. 885 00:53:29,980 --> 00:53:43,690 P is the statement that if a girl, G, ever rejected a boy, 886 00:53:43,690 --> 00:53:53,214 B, then the girl, G, has a suitor, 887 00:53:53,214 --> 00:53:54,630 or if the algorithm is terminated, 888 00:53:54,630 --> 00:54:08,696 a husband who she prefers to B. All right, 889 00:54:08,696 --> 00:54:10,070 that's going to be our invariant, 890 00:54:10,070 --> 00:54:12,500 and now we've got to prove it's an invariant. 891 00:54:12,500 --> 00:54:15,220 So we'll do that with a lemma called lemma one. 892 00:54:18,230 --> 00:54:23,900 P is an invariant for TMA. 893 00:54:28,990 --> 00:54:32,074 All right, let's prove that. 894 00:54:32,074 --> 00:54:33,490 Now, what's the first thing you've 895 00:54:33,490 --> 00:54:37,680 got to prove when you're proving something as an invariant? 896 00:54:37,680 --> 00:54:40,680 There's two things you've got to do to establish a variant. 897 00:54:40,680 --> 00:54:41,900 What's the first one? 898 00:54:41,900 --> 00:54:42,733 AUDIENCE: Base case? 899 00:54:42,733 --> 00:54:43,680 PROFESSOR: Base case. 900 00:54:43,680 --> 00:54:46,310 Show it holds true at the beginning. 901 00:54:46,310 --> 00:54:49,380 Proof is going to be by induction, 902 00:54:49,380 --> 00:54:52,304 and so we've got to show that P holds true at the beginning. 903 00:54:52,304 --> 00:54:53,970 But what are we going to induct on here? 904 00:54:53,970 --> 00:54:55,950 What's the parameter we're inducting on? 905 00:54:55,950 --> 00:54:56,690 AUDIENCE: Time? 906 00:54:56,690 --> 00:54:58,189 PROFESSOR: Time, the number of days. 907 00:55:00,810 --> 00:55:03,040 Good. 908 00:55:03,040 --> 00:55:07,500 The base case is day zero, the beginning. 909 00:55:13,630 --> 00:55:15,340 All right. 910 00:55:15,340 --> 00:55:19,115 Well, is that statement true on day zero? 911 00:55:22,030 --> 00:55:24,760 Yeah, it's true for sort of a weird reason. 912 00:55:24,760 --> 00:55:27,790 Nobody's been rejected yet, so it's 913 00:55:27,790 --> 00:55:29,900 what's called vacuously true. 914 00:55:29,900 --> 00:55:34,940 Because no girl, G, has rejected any boy, so it's true. 915 00:55:38,380 --> 00:55:40,000 So no one is rejected yet. 916 00:55:45,360 --> 00:55:46,760 So it's vacuously true. 917 00:55:52,293 --> 00:55:54,280 All right, next we have the induction step. 918 00:56:02,860 --> 00:56:16,660 So we'll assume P holds at the end of day d, 919 00:56:16,660 --> 00:56:19,230 and we need to argue that it holds now 920 00:56:19,230 --> 00:56:22,850 at the end of day d plus 1. 921 00:56:22,850 --> 00:56:25,570 So say it's true up to now, up to day d. 922 00:56:25,570 --> 00:56:28,130 Why Is it true at the end of the next day? 923 00:56:28,130 --> 00:56:33,320 Well, there's two cases to look at here, depending 924 00:56:33,320 --> 00:56:46,410 on when G rejected B. So if she rejects B on this day, day 925 00:56:46,410 --> 00:56:54,817 d plus 1, well, why would she reject B on day d plus 1? 926 00:56:54,817 --> 00:56:55,900 There's only one scenario. 927 00:56:55,900 --> 00:56:56,828 Yeah? 928 00:56:56,828 --> 00:56:58,220 AUDIENCE: There's a better boy. 929 00:56:58,220 --> 00:56:59,850 PROFESSOR: There's a better boy. 930 00:56:59,850 --> 00:57:03,880 And so she says maybe to him, and he becomes her suitor. 931 00:57:03,880 --> 00:57:08,010 So, in fact, P is true. 932 00:57:08,010 --> 00:57:20,670 So then there was someone better, 933 00:57:20,670 --> 00:57:27,950 and that implies P is true on day d plus 1. 934 00:57:27,950 --> 00:57:29,910 Case two is very similar. 935 00:57:29,910 --> 00:57:33,160 It's a very simple proof. 936 00:57:33,160 --> 00:57:41,320 G rejected B before day d, before d plus 1. 937 00:57:45,030 --> 00:57:50,130 Well, now we use the fact that P was true at the end of day 938 00:57:50,130 --> 00:57:57,625 d, which means P now implies that G had at least as good 939 00:57:57,625 --> 00:57:58,125 a suitor. 940 00:58:01,377 --> 00:58:03,335 Actually, it's better, because it was rejected. 941 00:58:06,900 --> 00:58:18,340 A better suitor on day d, that's what the hypothesis says, 942 00:58:18,340 --> 00:58:19,810 the invariant says. 943 00:58:19,810 --> 00:58:22,535 And now we just have to look at what happens on d plus 1. 944 00:58:25,360 --> 00:58:28,780 Well, either she has the same suitor on d plus 1, 945 00:58:28,780 --> 00:58:31,784 or somebody better came along. 946 00:58:31,784 --> 00:58:33,034 And so we're going to be done. 947 00:58:45,150 --> 00:58:55,850 She has the same or better suitor on day d plus 1, 948 00:58:55,850 --> 00:59:03,330 and that implies P is true on d plus 1, and we're done. 949 00:59:05,954 --> 00:59:07,620 All right, so I went through this proof. 950 00:59:07,620 --> 00:59:09,620 It was sort of obvious, but this is 951 00:59:09,620 --> 00:59:11,630 the careful way you'd write it down 952 00:59:11,630 --> 00:59:14,630 to show that the invariant holds. 953 00:59:14,630 --> 00:59:18,015 Any questions about the invariant dilemma? 954 00:59:20,930 --> 00:59:23,070 All right, so things only get better for the girls. 955 00:59:23,070 --> 00:59:26,260 If she ever rejected somebody, she's got somebody better. 956 00:59:26,260 --> 00:59:31,230 So now we can prove the main result, 957 00:59:31,230 --> 00:59:32,360 that everyone is married. 958 00:59:42,380 --> 00:59:44,255 And again the proof will be by contradiction. 959 00:59:52,720 --> 00:59:55,380 So we assume not everyone was married. 960 01:00:00,362 --> 01:00:02,070 Assume, for the purpose of contradiction, 961 01:00:02,070 --> 01:00:11,650 that some boy, B, we'll call him, is not married. 962 01:00:11,650 --> 01:00:14,280 Because if everyone is not married then some boy is not. 963 01:00:14,280 --> 01:00:16,850 If not everyone is married then some boy is not married. 964 01:00:19,530 --> 01:00:21,950 So when it terminates, B is not married. 965 01:00:24,790 --> 01:00:27,720 Well, what do you know about B if he was not 966 01:00:27,720 --> 01:00:28,710 married at the end? 967 01:00:33,680 --> 01:00:35,670 PROFESSOR: He was rejected by everyone. 968 01:00:35,670 --> 01:00:37,980 PROFESSOR: He was rejected by everyone, 969 01:00:37,980 --> 01:00:40,800 because if at the end, he's still under a balcony, 970 01:00:40,800 --> 01:00:44,640 if he still had somebody on his list, he'd be there. 971 01:00:44,640 --> 01:00:48,840 And he'd be getting married, because it's the end. 972 01:00:48,840 --> 01:00:51,235 So this means that if B is not married, 973 01:00:51,235 --> 01:00:52,360 he's rejected by everybody. 974 01:00:52,360 --> 01:00:52,860 Yeah? 975 01:00:52,860 --> 01:00:55,504 AUDIENCE: [INAUDIBLE] list? 976 01:00:55,504 --> 01:00:57,170 PROFESSOR: Oh, he's on everybody's list. 977 01:00:57,170 --> 01:00:59,534 AUDIENCE: Yeah. 978 01:00:59,534 --> 01:01:00,950 PROFESSOR: Everybody has everybody 979 01:01:00,950 --> 01:01:03,240 of the opposite sex on their list, 980 01:01:03,240 --> 01:01:05,860 but he had to cross everybody off. 981 01:01:05,860 --> 01:01:06,730 That's true. 982 01:01:06,730 --> 01:01:07,230 Yeah? 983 01:01:07,230 --> 01:01:09,122 AUDIENCE: That would mean that everyone had somebody 984 01:01:09,122 --> 01:01:11,487 better on the same day that [INAUDIBLE] telling him she 985 01:01:11,487 --> 01:01:13,052 didn't want to be with him. 986 01:01:13,052 --> 01:01:14,010 PROFESSOR: That's true. 987 01:01:14,010 --> 01:01:17,390 That means that B crossed every girl off. 988 01:01:17,390 --> 01:01:19,640 B is rejected by every girl, which 989 01:01:19,640 --> 01:01:21,270 means every girl has somebody better 990 01:01:21,270 --> 01:01:25,020 than B, which is not possible, because that would 991 01:01:25,020 --> 01:01:29,206 mean every girl was married. 992 01:01:29,206 --> 01:01:31,830 And therefore, the equal number of boys and girls, that means B 993 01:01:31,830 --> 01:01:33,190 would have been married. 994 01:01:33,190 --> 01:01:33,690 Good. 995 01:01:33,690 --> 01:01:37,090 All right, let's write that down. 996 01:01:37,090 --> 01:01:39,280 This means that B was rejected by every girl. 997 01:01:47,980 --> 01:01:53,320 OK, that means that every girl, by lemma 1, 998 01:01:53,320 --> 01:02:02,065 has a better suitor, and that's where we use lemma 1. 999 01:02:07,400 --> 01:02:16,640 And that means that every girl is married, 1000 01:02:16,640 --> 01:02:23,497 and that means that every boy is married, including B, 1001 01:02:23,497 --> 01:02:25,080 and that's a contradiction, because we 1002 01:02:25,080 --> 01:02:26,220 said B wasn't married. 1003 01:02:28,983 --> 01:02:29,482 OK? 1004 01:02:32,290 --> 01:02:34,643 Everybody buy that proof? 1005 01:02:34,643 --> 01:02:35,684 Any questions about that? 1006 01:02:38,890 --> 01:02:41,717 Yeah, proof by contradiction is a pretty powerful technique. 1007 01:02:41,717 --> 01:02:43,800 Once you assume something is not going to be true, 1008 01:02:43,800 --> 01:02:47,570 it gives you a lot of power to find a contradiction. 1009 01:02:50,820 --> 01:02:53,306 All right, so now we know that the algorithm ends, 1010 01:02:53,306 --> 01:02:54,430 and everybody gets married. 1011 01:02:54,430 --> 01:03:00,180 All's we got to do is show that there's no rogue couples, 1012 01:03:00,180 --> 01:03:01,230 so let's do that. 1013 01:03:08,830 --> 01:03:14,845 TMA produces a stable matching. 1014 01:03:22,210 --> 01:03:25,180 Now, how do you suppose we're going to prove this? 1015 01:03:25,180 --> 01:03:27,382 What's going to be the approach to prove this? 1016 01:03:27,382 --> 01:03:27,882 Yeah? 1017 01:03:27,882 --> 01:03:29,340 AUDIENCE: Assume that there's a rogue couple. 1018 01:03:29,340 --> 01:03:31,256 PROFESSOR: Assume that there's a rogue couple, 1019 01:03:31,256 --> 01:03:35,280 that namely this is not true, so there must be rogue couple. 1020 01:03:35,280 --> 01:03:50,710 So let Bob and Gail be any pair that are not married. 1021 01:03:58,480 --> 01:04:01,552 I need to prove the Bob and Gail are not rogue, 1022 01:04:01,552 --> 01:04:02,510 and then we'll be fine. 1023 01:04:02,510 --> 01:04:05,260 Because if it says everybody who is not married is not rogue, 1024 01:04:05,260 --> 01:04:09,361 then we know we have a stable matching. 1025 01:04:09,361 --> 01:04:10,860 Now, there's a couple of cases here. 1026 01:04:10,860 --> 01:04:14,239 Bob and Gail weren't married, so there's two ways 1027 01:04:14,239 --> 01:04:15,280 that could have happened. 1028 01:04:17,960 --> 01:04:18,780 What's one of them? 1029 01:04:21,392 --> 01:04:22,850 What's one reason they might not be 1030 01:04:22,850 --> 01:04:25,580 married, something that happened that made that impossible? 1031 01:04:25,580 --> 01:04:27,010 Yeah? 1032 01:04:27,010 --> 01:04:28,480 AUDIENCE: Gail rejected Bob. 1033 01:04:28,480 --> 01:04:29,146 PROFESSOR: Good. 1034 01:04:29,146 --> 01:04:30,680 Case one-- Gail rejected Bob. 1035 01:04:41,330 --> 01:04:45,654 Well, what do we know in that case, if Gail rejected Bob? 1036 01:04:45,654 --> 01:04:47,070 AUDIENCE: Gail had better suitors. 1037 01:04:47,070 --> 01:04:51,430 PROFESSOR: Gail has another suitor that she likes better. 1038 01:04:51,430 --> 01:04:56,674 And, in fact, what do we know about who Gail married? 1039 01:04:56,674 --> 01:04:57,834 AUDIENCE: Better than Bob. 1040 01:04:57,834 --> 01:04:59,500 PROFESSOR: Better than Bob-- things only 1041 01:04:59,500 --> 01:05:01,780 get better for the girls. 1042 01:05:01,780 --> 01:05:03,630 That's the lemma one. 1043 01:05:03,630 --> 01:05:15,260 All right, so this means that Gail marries someone that she 1044 01:05:15,260 --> 01:05:16,460 thinks is better than Bob. 1045 01:05:20,240 --> 01:05:21,370 And that's by lemma one. 1046 01:05:26,460 --> 01:05:31,310 Well, can Gail and Bob be a rogue couple here? 1047 01:05:31,310 --> 01:05:34,970 No, because Gail likes her spouse better than Bob, 1048 01:05:34,970 --> 01:05:37,680 so she's not going to be in a rogue affair with Bob. 1049 01:05:40,410 --> 01:05:49,950 So that means that Gail and Bob are not rogue. 1050 01:05:57,380 --> 01:06:04,890 All right, case two is Gail did not reject Bob. 1051 01:06:04,890 --> 01:06:05,580 She never did. 1052 01:06:09,792 --> 01:06:13,500 That's the other case, she didn't reject Bob. 1053 01:06:13,500 --> 01:06:18,100 Could Bob have ever serenaded Gail in this case? 1054 01:06:18,100 --> 01:06:21,220 No, because if he did and he was never rejected, 1055 01:06:21,220 --> 01:06:23,870 they would have ended up married. 1056 01:06:23,870 --> 01:06:24,790 All right? 1057 01:06:24,790 --> 01:06:34,495 So that means the Bob never serenaded Gail. 1058 01:06:41,390 --> 01:06:45,003 What does that mean about how Bob feels about Gail? 1059 01:06:45,003 --> 01:06:45,502 Yeah? 1060 01:06:45,502 --> 01:06:48,670 AUDIENCE: Bob must have never serenaded for Gail. 1061 01:06:48,670 --> 01:06:51,600 PROFESSOR: Yeah, Bob never got far enough down 1062 01:06:51,600 --> 01:06:54,780 on his list to serenade Gail. 1063 01:06:54,780 --> 01:06:59,830 He got married before he got down there. 1064 01:06:59,830 --> 01:07:06,850 All right, so that means that Gail is lower 1065 01:07:06,850 --> 01:07:11,930 on Bob's list than Bob's wife. 1066 01:07:16,990 --> 01:07:20,940 And that means that they're not rogue, 1067 01:07:20,940 --> 01:07:22,860 because Bob likes his wife better than Gail. 1068 01:07:33,380 --> 01:07:36,420 All right, so in each case, the cases clearly cover everything. 1069 01:07:36,420 --> 01:07:38,570 Gail rejected Bob, or she didn't. 1070 01:07:38,570 --> 01:07:42,030 Either way, Gail and Bob are not rogue. 1071 01:07:42,030 --> 01:07:49,800 So that means there's no rogue couples, 1072 01:07:49,800 --> 01:07:53,190 and that implies M is stable, TMA is stable. 1073 01:07:56,336 --> 01:07:59,230 OK? 1074 01:07:59,230 --> 01:08:01,700 All right, so TMA terminates, everyone 1075 01:08:01,700 --> 01:08:06,537 gets married, no rogue couples, nice outlook. 1076 01:08:06,537 --> 01:08:07,120 So we're done. 1077 01:08:07,120 --> 01:08:09,370 We actually proved it works. 1078 01:08:09,370 --> 01:08:11,990 One issue left to think about here. 1079 01:08:11,990 --> 01:08:16,048 Any questions on that before we launch off into the last issue? 1080 01:08:16,048 --> 01:08:17,024 AUDIENCE: Is it unique? 1081 01:08:19,960 --> 01:08:21,649 PROFESSOR: Is it unique? 1082 01:08:21,649 --> 01:08:27,430 TMA gives you a unique answer because it's an algorithm. 1083 01:08:27,430 --> 01:08:29,310 It's deterministic. 1084 01:08:29,310 --> 01:08:33,649 But there may be other stable matchings. 1085 01:08:33,649 --> 01:08:36,729 OK, so there's not just one stable matching, necessarily. 1086 01:08:36,729 --> 01:08:40,170 You could make examples with multiple stable matchings. 1087 01:08:40,170 --> 01:08:42,524 That's a great question. 1088 01:08:42,524 --> 01:08:43,494 Any other questions? 1089 01:08:46,410 --> 01:08:47,156 All right. 1090 01:08:47,156 --> 01:08:47,656 Oh, yeah? 1091 01:08:47,656 --> 01:08:49,888 AUDIENCE: Is there generally any other way 1092 01:08:49,888 --> 01:08:53,608 to assess optimality besides the fact that it's stable, or-- 1093 01:08:53,608 --> 01:08:56,594 PROFESSOR: Yeah, you can make up lots of them. 1094 01:08:56,594 --> 01:08:58,010 You could put weights on the edges 1095 01:08:58,010 --> 01:08:59,750 and get a min-weight matching. 1096 01:08:59,750 --> 01:09:04,800 You could try to get the perfect matching 1097 01:09:04,800 --> 01:09:08,060 with the least unfavorable marriage kind of thing. 1098 01:09:08,060 --> 01:09:10,649 There's a lot of criteria you can make. 1099 01:09:10,649 --> 01:09:14,720 This one turns out to be useful in practice in a variety ways 1100 01:09:14,720 --> 01:09:16,609 that we'll talk about, and also have 1101 01:09:16,609 --> 01:09:19,319 a nice, fast, simple algorithm that can actually 1102 01:09:19,319 --> 01:09:21,069 run in a distributed environment, which 1103 01:09:21,069 --> 01:09:22,830 is really nice. 1104 01:09:22,830 --> 01:09:25,529 So it is probably the most practical approach 1105 01:09:25,529 --> 01:09:28,279 to matching out there. 1106 01:09:28,279 --> 01:09:29,330 Any other questions? 1107 01:09:31,930 --> 01:09:33,746 OK, the last issue-- I don't know 1108 01:09:33,746 --> 01:09:38,649 if we still have the issues up there-- is fairness. 1109 01:09:38,649 --> 01:09:43,394 So who thinks the TMA is favorable to the boys? 1110 01:09:46,040 --> 01:09:46,630 Just a couple. 1111 01:09:46,630 --> 01:09:49,990 Who thinks it's favorable to the girls? 1112 01:09:49,990 --> 01:09:51,899 More, that's the common response. 1113 01:09:51,899 --> 01:09:54,510 Who thinks you can't even define it one way or the other? 1114 01:09:54,510 --> 01:09:57,450 It's unclear and hopeless to decide. 1115 01:09:57,450 --> 01:10:02,270 OK, well, it seems like maybe the girls, because they 1116 01:10:02,270 --> 01:10:04,170 get the best of their suitors. 1117 01:10:04,170 --> 01:10:05,920 They sit back, and they just take the best 1118 01:10:05,920 --> 01:10:07,770 as they come along. 1119 01:10:07,770 --> 01:10:09,700 On the other hand, the boys do try 1120 01:10:09,700 --> 01:10:11,690 to go out and get their first choice. 1121 01:10:11,690 --> 01:10:13,080 The girls have to wait. 1122 01:10:13,080 --> 01:10:15,402 And Mr. Right may never come along. 1123 01:10:15,402 --> 01:10:16,360 The boys are out there. 1124 01:10:16,360 --> 01:10:20,160 I'm going to my first choice, and they get denied, OK, they 1125 01:10:20,160 --> 01:10:22,670 just move right on to the next choice. 1126 01:10:22,670 --> 01:10:24,620 So this is actually one of these questions 1127 01:10:24,620 --> 01:10:26,780 of study in sociology. 1128 01:10:26,780 --> 01:10:31,550 In the animal species, which is better, proposers or acceptors? 1129 01:10:31,550 --> 01:10:33,800 What's the more powerful result? 1130 01:10:33,800 --> 01:10:36,490 Who has the better power in courtship? 1131 01:10:36,490 --> 01:10:40,000 It turns out that we can answer this question in a very 1132 01:10:40,000 --> 01:10:42,540 clear way, and prove it here. 1133 01:10:42,540 --> 01:10:46,570 And the answer is the boys have all the power here. 1134 01:10:46,570 --> 01:10:50,300 This is very favorable to the boys, and we'll see why. 1135 01:10:50,300 --> 01:10:53,260 Now, to prove that, we need some definitions. 1136 01:11:14,190 --> 01:11:18,029 OK, so I've got to define a couple things here 1137 01:11:18,029 --> 01:11:19,070 to be able to prove this. 1138 01:11:19,070 --> 01:11:22,540 The first is, for any collection of preference lists, 1139 01:11:22,540 --> 01:11:29,280 we're going to let S be the set of all stable matchings. 1140 01:11:36,500 --> 01:11:40,090 Now, we know that S is not empty, right? 1141 01:11:40,090 --> 01:11:43,014 How do we know that S is not empty here? 1142 01:11:43,014 --> 01:11:44,907 AUDIENCE: [INAUDIBLE] stable. 1143 01:11:44,907 --> 01:11:47,240 PROFESSOR: Yeah, because TMA produces a stable matching, 1144 01:11:47,240 --> 01:11:49,350 so we know that S is not empty. 1145 01:11:49,350 --> 01:11:51,780 There's at least one. 1146 01:11:51,780 --> 01:11:54,890 And, in fact, there could be many. 1147 01:11:54,890 --> 01:12:19,310 Now, for each person, P, we define the realm of possibility 1148 01:12:19,310 --> 01:12:27,530 for P to be the set of mates that you might 1149 01:12:27,530 --> 01:12:30,040 have in a stable matching. 1150 01:12:30,040 --> 01:12:32,520 So it's a set queue of people for which 1151 01:12:32,520 --> 01:12:37,660 there exists a matching that's stable such that you're 1152 01:12:37,660 --> 01:12:40,890 mated to that person. 1153 01:12:40,890 --> 01:12:42,560 So I've written this in some-- that's 1154 01:12:42,560 --> 01:12:45,490 sort of complicated mathematics, but somebody 1155 01:12:45,490 --> 01:12:49,450 is in your realm of possibility if there is a stable matching 1156 01:12:49,450 --> 01:12:50,540 where you married them. 1157 01:12:50,540 --> 01:12:52,165 If it exists, there's a stable matching 1158 01:12:52,165 --> 01:12:53,830 where you could marry them. 1159 01:12:53,830 --> 01:12:57,539 And this is vaguely like you see sometimes, you're 1160 01:12:57,539 --> 01:13:00,080 going out with somebody and your parents say, oh, they're not 1161 01:13:00,080 --> 01:13:02,350 in your league, or something. 1162 01:13:02,350 --> 01:13:04,060 This is a mathematical formulation 1163 01:13:04,060 --> 01:13:08,540 for that, that there is some way in the world to marry everybody 1164 01:13:08,540 --> 01:13:10,610 up, so it's all stable, and you could 1165 01:13:10,610 --> 01:13:12,680 be married to that person. 1166 01:13:12,680 --> 01:13:14,760 OK? 1167 01:13:14,760 --> 01:13:18,595 Let's do an example with four people. 1168 01:13:31,090 --> 01:13:39,920 All right, so for example, say we have Brad, Jen, and Angelina 1169 01:13:39,920 --> 01:13:42,420 again. 1170 01:13:42,420 --> 01:13:45,800 And of course Brad likes Angelina and vice versa. 1171 01:13:45,800 --> 01:13:49,360 Gen likes Brad, and then there's Billy Bob here. 1172 01:13:52,720 --> 01:13:53,790 All right. 1173 01:13:53,790 --> 01:13:58,330 Now, Brad is not realistic for Jen. 1174 01:13:58,330 --> 01:14:02,350 Brad Is not in Jen's realm of possibility, 1175 01:14:02,350 --> 01:14:07,120 because in any perfect matching where Brad marries Jen, 1176 01:14:07,120 --> 01:14:10,490 you're going to have a rogue couple. 1177 01:14:10,490 --> 01:14:12,820 Brad's going to go for Angelina. 1178 01:14:12,820 --> 01:14:17,170 So Brad is not within Jen's realm of possibility. 1179 01:14:17,170 --> 01:14:19,350 And similarly, vice versa-- Jen is not 1180 01:14:19,350 --> 01:14:22,679 in Brad's realm of possibility, because there's no stable 1181 01:14:22,679 --> 01:14:24,720 matching where they're married, in this scenario, 1182 01:14:24,720 --> 01:14:26,910 for this problem. 1183 01:14:26,910 --> 01:14:29,300 All right? 1184 01:14:29,300 --> 01:14:30,900 Now that we have that notion, we can 1185 01:14:30,900 --> 01:14:35,828 define who your optimal mate is, and who your pessimal mate is, 1186 01:14:35,828 --> 01:14:36,804 the worst case. 1187 01:14:51,950 --> 01:15:06,800 All right, so we define a person's optimal mate 1188 01:15:06,800 --> 01:15:12,290 is his or her favorite in the realm of possibility. 1189 01:15:22,890 --> 01:15:26,730 So your optimal mate is not your favorite overall, 1190 01:15:26,730 --> 01:15:29,730 it's just your favorite among those who are possible, 1191 01:15:29,730 --> 01:15:32,160 that there is a stable matching that you could 1192 01:15:32,160 --> 01:15:34,330 be matched to that person. 1193 01:15:34,330 --> 01:15:43,860 And similarly, you have a person's pessimal mate 1194 01:15:43,860 --> 01:15:51,450 is your least favorite from the realm of possibility. 1195 01:15:51,450 --> 01:15:51,950 OK? 1196 01:15:51,950 --> 01:15:53,480 Because you have all the people you 1197 01:15:53,480 --> 01:15:56,789 might be married to in stable matchings. 1198 01:15:56,789 --> 01:15:58,830 Your favorite is the optimal, your least favorite 1199 01:15:58,830 --> 01:16:00,590 is the pessimal. 1200 01:16:00,590 --> 01:16:02,090 Any questions about that? 1201 01:16:02,090 --> 01:16:04,247 Does that make sense? 1202 01:16:04,247 --> 01:16:05,830 And you don't count the ones you can't 1203 01:16:05,830 --> 01:16:08,310 be married to, because if you were, it would be unstable. 1204 01:16:11,270 --> 01:16:16,800 OK, now we can state the blockbuster theorems here. 1205 01:16:16,800 --> 01:16:28,370 Theorem four says TMA marries every boy 1206 01:16:28,370 --> 01:16:31,600 with his optimal mate. 1207 01:16:36,630 --> 01:16:41,140 Theorem five, probably can guess, 1208 01:16:41,140 --> 01:16:48,230 TMA marries every girl with her pessimal mate. 1209 01:16:53,900 --> 01:16:56,610 All right, so it is optimal for every boy. 1210 01:16:56,610 --> 01:16:59,960 They get the best possible they could have in stable marriages, 1211 01:16:59,960 --> 01:17:03,306 and every girl gets the worst possible mate. 1212 01:17:03,306 --> 01:17:06,110 Now, you wouldn't necessarily think that when you first 1213 01:17:06,110 --> 01:17:09,320 look at that algorithm, where the boys are working down 1214 01:17:09,320 --> 01:17:12,070 their list, and the girls are just getting better and better. 1215 01:17:12,070 --> 01:17:13,090 But that's the case. 1216 01:17:13,090 --> 01:17:16,220 Now, let's see, I'm not going to have time to prove them both, 1217 01:17:16,220 --> 01:17:19,715 but I will prove theorem five. 1218 01:17:19,715 --> 01:17:21,340 And I'm going to assume theorem four is 1219 01:17:21,340 --> 01:17:23,860 true to prove theorem five. 1220 01:17:23,860 --> 01:17:26,660 Maybe we'll do theorem four tomorrow in recitation. 1221 01:17:26,660 --> 01:17:27,660 I don't know. 1222 01:17:27,660 --> 01:17:30,339 So let's do theorem five so you can see how this works. 1223 01:17:33,300 --> 01:17:47,667 The proof is by contradiction, so we'll 1224 01:17:47,667 --> 01:17:49,250 assume theorem four is true, and we'll 1225 01:17:49,250 --> 01:17:55,010 prove the proof of theorem five by contradiction. 1226 01:18:03,040 --> 01:18:09,040 So assume there was a stable matching where a girl got 1227 01:18:09,040 --> 01:18:12,290 worse off than in TMA. 1228 01:18:12,290 --> 01:18:14,060 All right? 1229 01:18:14,060 --> 01:18:15,900 Assume three and five is not true, 1230 01:18:15,900 --> 01:18:19,680 then there's some girl in some stable matching. 1231 01:18:19,680 --> 01:18:22,270 So suppose, for the purpose of contradiction, 1232 01:18:22,270 --> 01:18:30,230 that there exists a stable matching, 1233 01:18:30,230 --> 01:18:40,760 we'll call it M, where some girl, 1234 01:18:40,760 --> 01:18:42,615 and she fares worse than in TMA. 1235 01:18:48,202 --> 01:18:50,160 I want to show that results in a contradiction. 1236 01:18:53,120 --> 01:18:55,982 And the proof is pretty simple, just a simple picture. 1237 01:19:00,820 --> 01:19:04,295 So G did worse in M than in TMA. 1238 01:19:14,480 --> 01:19:24,475 All right, so let's let B prime be the mate of G in M. 1239 01:19:24,475 --> 01:19:30,550 So girl G did worse in M than in TMA, so here's her mate in M, 1240 01:19:30,550 --> 01:19:32,935 and let B be her mate in TMA. 1241 01:19:38,080 --> 01:19:42,510 Who does she like better, B or B prime? 1242 01:19:42,510 --> 01:19:45,600 B, because we're saying that she did worse in M than she did 1243 01:19:45,600 --> 01:19:48,870 in TMA, so she likes B better. 1244 01:19:51,540 --> 01:20:00,580 And let G prime be the mate of B in M. Now, who does 1245 01:20:00,580 --> 01:20:02,907 B like better, G or G prime? 1246 01:20:02,907 --> 01:20:03,740 [INTERPOSING VOICES] 1247 01:20:07,500 --> 01:20:08,840 PROFESSOR: Not G prime. 1248 01:20:08,840 --> 01:20:15,740 B got married to G prime in M, but what does theorem four say? 1249 01:20:15,740 --> 01:20:19,560 Yeah, G. Theorem four says that across all 1250 01:20:19,560 --> 01:20:24,780 the stable matchings, B gets his favorite mate in TMA. 1251 01:20:24,780 --> 01:20:28,480 So G prime is in the realm of possibility, and so is G, 1252 01:20:28,480 --> 01:20:30,890 and we know from theorem four B likes G 1253 01:20:30,890 --> 01:20:35,100 best, better than G prime, because of theorem four. 1254 01:20:35,100 --> 01:20:38,260 So what happened here? 1255 01:20:38,260 --> 01:20:49,620 There's a rogue couple in M. B and G are a rogue couple in M. 1256 01:20:49,620 --> 01:20:53,259 And that means that M is not stable, 1257 01:20:53,259 --> 01:20:54,425 and that is a contradiction. 1258 01:20:57,550 --> 01:20:58,050 All right? 1259 01:20:58,050 --> 01:21:04,010 And so theorem five is true, because we 1260 01:21:04,010 --> 01:21:07,090 assumed we had a stable matching M where there's 1261 01:21:07,090 --> 01:21:10,810 a girl who did worse off. 1262 01:21:10,810 --> 01:21:14,560 So it really pays off to be aggressive party in courtship. 1263 01:21:14,560 --> 01:21:16,220 Everybody lives happily ever after, 1264 01:21:16,220 --> 01:21:19,030 especially the boys in TMA. 1265 01:21:19,030 --> 01:21:22,060 Now, TMA arises in lots of applications. 1266 01:21:22,060 --> 01:21:24,910 The most famous is the matching program 1267 01:21:24,910 --> 01:21:28,480 that's used to match MDs to residency programs. 1268 01:21:28,480 --> 01:21:31,590 So how many pre-meds are here? 1269 01:21:31,590 --> 01:21:33,380 There's one, at least. 1270 01:21:33,380 --> 01:21:35,576 So you're going to go to medical school some day, 1271 01:21:35,576 --> 01:21:36,950 and at the end of medical school, 1272 01:21:36,950 --> 01:21:38,980 there's a big day called match day, 1273 01:21:38,980 --> 01:21:42,490 where you get assigned to a hospital for your internship, 1274 01:21:42,490 --> 01:21:46,070 and the way that works is using this algorithm. 1275 01:21:46,070 --> 01:21:48,390 And who do you suppose is the boy in this algorithm? 1276 01:21:48,390 --> 01:21:49,348 AUDIENCE: The hospital. 1277 01:21:49,348 --> 01:21:51,040 PROFESSOR: The hospital. 1278 01:21:51,040 --> 01:21:53,560 And they want it so that when they make the matchings, 1279 01:21:53,560 --> 01:21:57,560 that there's not some pair of an intern or doctor in a hospital 1280 01:21:57,560 --> 01:22:00,810 where they'd like each other better than what they got. 1281 01:22:00,810 --> 01:22:04,250 This is used in online dating for the obvious reasons, 1282 01:22:04,250 --> 01:22:06,670 and we actually use this algorithm lot at Akamai 1283 01:22:06,670 --> 01:22:09,330 to load balance traffic on the web. 1284 01:22:09,330 --> 01:22:13,420 And here you have the boys are web servers, 1285 01:22:13,420 --> 01:22:17,200 and the girls are requests for service. 1286 01:22:17,200 --> 01:22:20,960 And the goals are to balance performance, 1287 01:22:20,960 --> 01:22:23,360 getting a server that's nearby you that's fast. 1288 01:22:23,360 --> 01:22:27,190 And on the other side, our cost, and by who 1289 01:22:27,190 --> 01:22:31,690 we make a boy and a girl, we can trade off cost for performance 1290 01:22:31,690 --> 01:22:33,210 in a very nice, distributed way. 1291 01:22:33,210 --> 01:22:35,900 All right, so that's it for today.