1 00:00:00,040 --> 00:00:02,480 The following content is provided under a Creative 2 00:00:02,480 --> 00:00:04,010 Commons license. 3 00:00:04,010 --> 00:00:06,340 Your support will help MIT OpenCourseWare 4 00:00:06,340 --> 00:00:10,700 continue to offer high quality educational resources for free. 5 00:00:10,700 --> 00:00:13,320 To make a donation or view additional materials 6 00:00:13,320 --> 00:00:17,035 from hundreds of MIT courses, visit MIT OpenCourseWare 7 00:00:17,035 --> 00:00:17,660 at ocw.mit.edu. 8 00:00:20,274 --> 00:00:21,440 SRINIVAS DEVADAS: All right. 9 00:00:21,440 --> 00:00:22,700 Good morning, everyone. 10 00:00:22,700 --> 00:00:24,540 Welcome back from spring break. 11 00:00:24,540 --> 00:00:26,270 Hope you had a nice time off and couldn't 12 00:00:26,270 --> 00:00:29,230 wait to get back to 6.046. 13 00:00:29,230 --> 00:00:31,620 So exciting second half. 14 00:00:31,620 --> 00:00:36,230 Going to do flow networks today on Thursday. 15 00:00:36,230 --> 00:00:38,890 Next week, it's linear programming, 16 00:00:38,890 --> 00:00:43,880 on to complexity, distributed algorithms, cryptography. 17 00:00:43,880 --> 00:00:45,730 Topics going to come fast and furious. 18 00:00:45,730 --> 00:00:47,710 Hopefully, they'll all be interesting. 19 00:00:47,710 --> 00:00:50,700 So there's a lot of setup associated 20 00:00:50,700 --> 00:00:54,220 with network flow, max flow. 21 00:00:54,220 --> 00:00:56,080 It's an optimization problem. 22 00:00:56,080 --> 00:00:58,980 And so I'm going to spend like the first hour here-- 23 00:00:58,980 --> 00:01:01,820 and hopefully, it won't be too boring-- 24 00:01:01,820 --> 00:01:04,819 setting up flow networks, describing the max flow 25 00:01:04,819 --> 00:01:05,700 problem. 26 00:01:05,700 --> 00:01:08,920 As you can see, this outline is fairly involved, 27 00:01:08,920 --> 00:01:13,210 talking about cuts in a network, residual networks. 28 00:01:13,210 --> 00:01:20,655 And we'll, more or less, end the lecture with the statement, 29 00:01:20,655 --> 00:01:22,600 though not the proof-- we'll save 30 00:01:22,600 --> 00:01:26,150 that for next time-- of the mas-flow min-cut theorem, which 31 00:01:26,150 --> 00:01:30,000 is really an iconic theorem in the literature, 32 00:01:30,000 --> 00:01:34,340 and suddenly, the crucial theorem for flow networks. 33 00:01:34,340 --> 00:01:39,680 And we'll take the max-flow min-cut theorem 34 00:01:39,680 --> 00:01:46,140 and use that to get to the first ever max-flow algorithm, which 35 00:01:46,140 --> 00:01:48,330 was due to Ford and Fulkerson. 36 00:01:48,330 --> 00:01:53,390 And that should be, pretty much, at the end of today's lecture. 37 00:01:53,390 --> 00:01:58,990 And next time, we'll talk about the proof of max-flow min-cut, 38 00:01:58,990 --> 00:02:01,820 talk about some of the issues with Ford-Fulkerson, 39 00:02:01,820 --> 00:02:06,350 and then use max flow as a hammer 40 00:02:06,350 --> 00:02:11,650 to solve interesting problems in bipartite matching, baseball 41 00:02:11,650 --> 00:02:14,150 playoff elimination, and things like that. 42 00:02:14,150 --> 00:02:17,730 So just like shortest paths, can be used not just 43 00:02:17,730 --> 00:02:23,370 to compute the shortest distance from point A to point B, 44 00:02:23,370 --> 00:02:26,160 you can imagine that other problems, for example, 45 00:02:26,160 --> 00:02:28,224 scheduling problems, time problems, 46 00:02:28,224 --> 00:02:30,390 could be solved using Dijkstra-- and you've probably 47 00:02:30,390 --> 00:02:32,900 seen examples of that-- max flow is 48 00:02:32,900 --> 00:02:36,360 another algorithmic hammer that's being used to solve 49 00:02:36,360 --> 00:02:38,150 a wide variety of problems. 50 00:02:38,150 --> 00:02:40,860 We won't really touch on that aspect today, 51 00:02:40,860 --> 00:02:45,680 but we'll spend a bunch of time on Thursday talking about that. 52 00:02:45,680 --> 00:02:46,800 So let's get started. 53 00:02:50,150 --> 00:02:52,070 We're going to start with defining 54 00:02:52,070 --> 00:02:54,660 what a flow network is. 55 00:02:54,660 --> 00:02:56,410 And at some level, it's really simple. 56 00:02:56,410 --> 00:02:58,815 I mean, it's a graph. 57 00:02:58,815 --> 00:03:02,380 A graph is going to have vertices and edges. 58 00:03:02,380 --> 00:03:06,470 We're going to only look at directed graphs. 59 00:03:06,470 --> 00:03:09,642 And we're going to have a couple of constraints associated 60 00:03:09,642 --> 00:03:11,350 with these directed graphs that are going 61 00:03:11,350 --> 00:03:13,390 to make the algorithms, and the proofs, 62 00:03:13,390 --> 00:03:15,510 and the notation a lot simpler. 63 00:03:15,510 --> 00:03:17,660 I'll get to that in a few minutes. 64 00:03:17,660 --> 00:03:20,590 And the key thing with the flow networks-- I 65 00:03:20,590 --> 00:03:23,380 mean, just like you have a source and a destination 66 00:03:23,380 --> 00:03:25,760 for shortest paths, in a flow network 67 00:03:25,760 --> 00:03:27,450 as well, you're going to have a source, 68 00:03:27,450 --> 00:03:29,300 and you're going to have a sink. 69 00:03:29,300 --> 00:03:33,612 So we're going to have distinguished vertices, two 70 00:03:33,612 --> 00:03:34,570 distinguished vertices. 71 00:03:39,160 --> 00:03:46,330 And we're going to call them the source, s, and a sink, t. 72 00:03:46,330 --> 00:03:49,250 And so the basic idea here-- and just to sort of set things 73 00:03:49,250 --> 00:03:51,310 up right up front-- is that there's 74 00:03:51,310 --> 00:03:53,980 going to be some flow coming out of s. 75 00:03:53,980 --> 00:03:56,750 And it's going to have to obey some constraints associated 76 00:03:56,750 --> 00:04:01,310 with capacities of the edges, in order to make its way to t. 77 00:04:01,310 --> 00:04:04,030 And along the way-- this is flow. 78 00:04:04,030 --> 00:04:04,850 This is water. 79 00:04:04,850 --> 00:04:07,670 You can think of it as water, or cars, or what have you. 80 00:04:07,670 --> 00:04:09,150 It's a rate. 81 00:04:09,150 --> 00:04:11,970 You're not going to allow accumulation 82 00:04:11,970 --> 00:04:13,650 in the intermediate nodes. 83 00:04:13,650 --> 00:04:18,120 So you're going to have law of conservation associated 84 00:04:18,120 --> 00:04:20,250 with this commodity that's flowing, 85 00:04:20,250 --> 00:04:22,670 be water, or cars, or people. 86 00:04:22,670 --> 00:04:28,960 And that essentially comes down to, for any vertex, other 87 00:04:28,960 --> 00:04:32,790 than s or t, everything entering the vertex has 88 00:04:32,790 --> 00:04:34,550 to leave the vertex. 89 00:04:34,550 --> 00:04:37,180 So that's like Kirchoff's current law, for example. 90 00:04:37,180 --> 00:04:42,140 So there's a lot of analogies here with respect to real life, 91 00:04:42,140 --> 00:04:44,510 or electricity in this case. 92 00:04:44,510 --> 00:04:50,240 And you'll see that, I think, over and over as we go along. 93 00:04:50,240 --> 00:04:53,254 So let's take a look at a flow network. 94 00:04:53,254 --> 00:04:54,670 I'm not going to draw it out here. 95 00:04:54,670 --> 00:04:56,560 I'm going to keep this one example 96 00:04:56,560 --> 00:04:58,200 all through the lecture. 97 00:04:58,200 --> 00:05:04,750 But just to go off and talk about edges and capacities 98 00:05:04,750 --> 00:05:08,190 before we actually draw an example, 99 00:05:08,190 --> 00:05:10,840 we're going to have edges, directed edges, 100 00:05:10,840 --> 00:05:14,490 u, v. So you have an edge from u to v. 101 00:05:14,490 --> 00:05:18,680 And it's going to belong to E, obviously. 102 00:05:18,680 --> 00:05:21,990 That's the reason the edge is in the network. 103 00:05:21,990 --> 00:05:26,160 And this edge is going to have a non-negative-- 104 00:05:26,160 --> 00:05:33,748 each edge is going to have a non-negative capacity, C(u,v). 105 00:05:33,748 --> 00:05:35,080 Right? 106 00:05:35,080 --> 00:05:40,430 And if perchance theres' no edge from, let's say, 107 00:05:40,430 --> 00:05:43,580 s1 to s2-- these are different vertices 108 00:05:43,580 --> 00:05:49,020 from the source or the sink, just as an example, 109 00:05:49,020 --> 00:05:51,600 you can say it's between a and b-- then, we can 110 00:05:51,600 --> 00:05:54,560 assume that the capacity is 0. 111 00:05:54,560 --> 00:06:03,560 So if u, v does not belong to E, then assume that C(u,v) is 0. 112 00:06:03,560 --> 00:06:05,370 So there's no way of getting from u 113 00:06:05,370 --> 00:06:09,350 to v. This rate, wall water, cars-- you know, 114 00:06:09,350 --> 00:06:13,400 there's no road that gets you from u to v, OK? 115 00:06:13,400 --> 00:06:16,700 So let's draw an example of a flow network. 116 00:06:16,700 --> 00:06:19,170 We'll talk a little bit about what the flow is 117 00:06:19,170 --> 00:06:25,760 and what the max flow is in example-driven algorithm 118 00:06:25,760 --> 00:06:27,880 design, if you will. 119 00:06:27,880 --> 00:06:30,010 So I've got a source, s. 120 00:06:30,010 --> 00:06:33,950 And I've got a sink, t. 121 00:06:33,950 --> 00:06:37,170 And then, I've got a bunch of nodes in the middle. 122 00:06:37,170 --> 00:06:38,265 Just draw them out. 123 00:06:41,780 --> 00:06:45,630 I'm not going to bother naming those nodes. 124 00:06:45,630 --> 00:06:48,800 Well, that might be a mistake. 125 00:06:48,800 --> 00:06:49,300 We'll see. 126 00:06:57,000 --> 00:06:59,308 So this is not like it's an acyclic graph. 127 00:07:02,490 --> 00:07:06,430 You're allowed cycles in this graph. 128 00:07:06,430 --> 00:07:08,910 But we will have a couple of constraints 129 00:07:08,910 --> 00:07:10,850 that are associated with this graph 130 00:07:10,850 --> 00:07:12,980 that I'll get to in just a minute. 131 00:07:12,980 --> 00:07:14,970 So first, that's all we've got. 132 00:07:14,970 --> 00:07:17,510 You've got g,v,e, directed graph. 133 00:07:17,510 --> 00:07:19,360 Can't have cycles in it. 134 00:07:19,360 --> 00:07:23,520 And I'm going to draw a couple of numbers here. 135 00:07:23,520 --> 00:07:36,620 The numbers I'm putting up here are the capacities associated 136 00:07:36,620 --> 00:07:38,540 with each of these edges. 137 00:07:38,540 --> 00:07:42,270 So those are just the capacities. 138 00:07:42,270 --> 00:07:43,690 Those are C(u,v). 139 00:07:43,690 --> 00:07:47,295 And I said that, if u,v does not belong to E, 140 00:07:47,295 --> 00:07:49,980 then you're going to assume that C(u,v) is 0. 141 00:07:49,980 --> 00:07:55,800 So there's no edge, for example, between this node 142 00:07:55,800 --> 00:07:56,940 and that node. 143 00:07:56,940 --> 00:07:58,580 So there's no way that you can directly 144 00:07:58,580 --> 00:08:00,180 get from here to there. 145 00:08:00,180 --> 00:08:03,770 You can go like this, like this, and like that, 146 00:08:03,770 --> 00:08:05,860 and get from here to there. 147 00:08:05,860 --> 00:08:09,840 And you can obviously go like so, and like this, 148 00:08:09,840 --> 00:08:15,550 and like that, to get from the one on the top left 149 00:08:15,550 --> 00:08:17,400 to the one on the bottom right, OK? 150 00:08:17,400 --> 00:08:23,040 So that's essentially the set up, 151 00:08:23,040 --> 00:08:27,690 except for the fact that we've just talked about capacities. 152 00:08:27,690 --> 00:08:31,020 And this is sort of the bandwidth, if you will. 153 00:08:31,020 --> 00:08:34,539 This is the amount of traffic that can go through this road. 154 00:08:34,539 --> 00:08:37,039 And now, we have to talk about the specific case 155 00:08:37,039 --> 00:08:39,390 where we're actually going to shove things 156 00:08:39,390 --> 00:08:40,880 through the network. 157 00:08:40,880 --> 00:08:42,480 So we're going to have another number. 158 00:08:42,480 --> 00:08:44,930 So typically, we're going to have two numbers associated 159 00:08:44,930 --> 00:08:46,360 with each edge. 160 00:08:46,360 --> 00:08:48,320 One of them is going to be the capacity, 161 00:08:48,320 --> 00:08:50,910 and the other one is going to be the flow that 162 00:08:50,910 --> 00:08:51,952 goes through the edge. 163 00:08:51,952 --> 00:08:53,410 And as you can imagine, we're going 164 00:08:53,410 --> 00:08:57,020 to have this constraint that says that the flow can never 165 00:08:57,020 --> 00:08:58,370 exceed the capacity. 166 00:08:58,370 --> 00:09:02,800 And that's the local constraint associated with each edge, OK? 167 00:09:02,800 --> 00:09:06,760 That doesn't mean that there aren't 168 00:09:06,760 --> 00:09:11,030 variations possible with respect to the overall flow 169 00:09:11,030 --> 00:09:12,800 of the network. 170 00:09:12,800 --> 00:09:14,720 Things can change. 171 00:09:14,720 --> 00:09:17,330 You obey the edge capacities. 172 00:09:17,330 --> 00:09:20,500 And there could be different flow coming out of s 173 00:09:20,500 --> 00:09:22,972 and going into t, et cetera. 174 00:09:22,972 --> 00:09:25,430 And so there is going to be an optimization here associated 175 00:09:25,430 --> 00:09:28,750 with the exact numbers that all obey 176 00:09:28,750 --> 00:09:32,290 these edge constraints, so these edge capacity constraints, OK? 177 00:09:32,290 --> 00:09:36,290 So let's take a real simple example 178 00:09:36,290 --> 00:09:39,670 of a flow in this network. 179 00:09:39,670 --> 00:09:44,110 And ah, I have some colored chalk here. 180 00:09:44,110 --> 00:09:49,123 So I can put down the flow over here. 181 00:09:49,123 --> 00:09:49,956 And so this is flow. 182 00:09:52,860 --> 00:09:53,750 Wow. 183 00:09:53,750 --> 00:09:55,470 That is an ugly color. 184 00:09:55,470 --> 00:09:57,290 [LAUGHTER] 185 00:09:57,290 --> 00:10:01,690 But now, we're stuck for the rest of this lecture. 186 00:10:01,690 --> 00:10:07,840 So I've got 2, 2, 1, colon, 3. 187 00:10:07,840 --> 00:10:10,590 So the first number is the flow, and the second number 188 00:10:10,590 --> 00:10:11,600 is the capacity. 189 00:10:11,600 --> 00:10:14,000 Let me just write that out. 190 00:10:14,000 --> 00:10:22,100 This is-- and then, this is 1, colon, 3. 191 00:10:22,100 --> 00:10:25,360 This is 1, colon, 2. 192 00:10:25,360 --> 00:10:27,960 So that meets the capacity. 193 00:10:27,960 --> 00:10:31,240 This is 2, colon, 3. 194 00:10:31,240 --> 00:10:39,020 And then 1, colon, 3, 2, colon, 3, and 1, 2, right? 195 00:10:39,020 --> 00:10:44,780 So that's my first example of a flow. 196 00:10:44,780 --> 00:10:49,880 And we want to make sure that this flow makes sense, OK? 197 00:10:49,880 --> 00:10:51,880 And we're going to write this down a little more 198 00:10:51,880 --> 00:10:55,690 precisely in just a minute, but I've sort of given you 199 00:10:55,690 --> 00:10:57,930 the intuition already. 200 00:10:57,930 --> 00:11:03,050 I've talked about it's OK to have a flow from the source. 201 00:11:03,050 --> 00:11:07,790 It's the mountain spewing water, or that's 202 00:11:07,790 --> 00:11:09,180 the source of the river. 203 00:11:09,180 --> 00:11:11,030 And this is the sea, for example. 204 00:11:11,030 --> 00:11:13,110 And the river flows into it. 205 00:11:13,110 --> 00:11:20,190 But along the way, you really can't have accumulation, OK? 206 00:11:20,190 --> 00:11:22,710 Because when you think about it as a rate-- 207 00:11:22,710 --> 00:11:26,960 and so this is sort of gallons per second-- then maybe 208 00:11:26,960 --> 00:11:29,020 you'll have a little bit of accumulation allowed. 209 00:11:29,020 --> 00:11:32,020 But over a huge period of time, you 210 00:11:32,020 --> 00:11:33,620 can't have infinite accumulation. 211 00:11:33,620 --> 00:11:37,760 So that's where the conservation law kicks in, which says, 212 00:11:37,760 --> 00:11:41,700 anything that goes into a node that is not marked 213 00:11:41,700 --> 00:11:44,370 s or t has to leave the node. 214 00:11:44,370 --> 00:11:47,810 So you look at this, and you go, well, there's 215 00:11:47,810 --> 00:11:48,960 two things coming in here. 216 00:11:48,960 --> 00:11:53,060 There's 1 and 1, which adds up to 2. 217 00:11:53,060 --> 00:11:54,990 And there's two 2 leaving. 218 00:11:54,990 --> 00:11:56,310 So we're good there. 219 00:11:56,310 --> 00:11:57,040 OK? 220 00:11:57,040 --> 00:11:59,150 And then pick another one. 221 00:11:59,150 --> 00:12:00,700 This one, for example. 222 00:12:00,700 --> 00:12:04,530 You've got 2 coming in, and you've got 1 and 1 leaving. 223 00:12:04,530 --> 00:12:06,030 We're good there, right? 224 00:12:06,030 --> 00:12:10,280 For t, you've got 3 coming in, 2 plus 1. 225 00:12:10,280 --> 00:12:13,860 And another check to do is, well, you've 226 00:12:13,860 --> 00:12:16,310 got 2 coming out of the source, right? 227 00:12:16,310 --> 00:12:19,280 So hopefully, that all will make sense. 228 00:12:19,280 --> 00:12:23,830 And ask questions if you're confused. 229 00:12:23,830 --> 00:12:27,150 One other thing to look at, which is interesting, 230 00:12:27,150 --> 00:12:33,210 is that you could have flows that are essentially cyclic. 231 00:12:33,210 --> 00:12:37,790 You could have commodities that are flowing in a little cycle. 232 00:12:37,790 --> 00:12:38,680 And can you see that? 233 00:12:38,680 --> 00:12:42,536 Can anyone see that over here? 234 00:12:42,536 --> 00:12:45,000 Yep? 235 00:12:45,000 --> 00:12:45,786 Go ahead. 236 00:12:45,786 --> 00:12:48,814 STUDENT: The bottom-right triangle [INAUDIBLE]. 237 00:12:48,814 --> 00:12:50,480 SRINIVAS DEVADAS: Bottom-right triangle? 238 00:12:50,480 --> 00:12:51,310 This thing over here? 239 00:12:51,310 --> 00:12:51,760 STUDENT: Yeah. 240 00:12:51,760 --> 00:12:52,700 SRINIVAS DEVADAS: Like that? 241 00:12:52,700 --> 00:12:53,170 Good. 242 00:12:53,170 --> 00:12:53,420 Right? 243 00:12:53,420 --> 00:12:55,503 So you see this one going over this way, this way, 244 00:12:55,503 --> 00:12:56,380 and that way? 245 00:12:56,380 --> 00:13:04,100 And so there's nothing that's stopping us from taking this 246 00:13:04,100 --> 00:13:08,130 and-- I had 1 over here, so I'm going to make that 0. 247 00:13:08,130 --> 00:13:10,450 I had 2 over here, and I'm going to make that 1. 248 00:13:10,450 --> 00:13:13,335 And I had 2 over here, and I'm going to make that 1. 249 00:13:13,335 --> 00:13:14,210 STUDENT: [INAUDIBLE]. 250 00:13:14,210 --> 00:13:15,455 STUDENT: [INAUDIBLE] 251 00:13:15,455 --> 00:13:16,330 SRINIVAS DEVADAS: Oh. 252 00:13:16,330 --> 00:13:17,143 What is it? 253 00:13:17,143 --> 00:13:17,970 STUDENT: It was 1. 254 00:13:17,970 --> 00:13:20,142 SRINIVAS DEVADAS: It was 1 before? 255 00:13:20,142 --> 00:13:20,850 Oh, you're right. 256 00:13:20,850 --> 00:13:21,516 It was 1 before. 257 00:13:21,516 --> 00:13:23,260 So I should make that 0 then. 258 00:13:23,260 --> 00:13:25,450 Good. 259 00:13:25,450 --> 00:13:28,280 I wanted to subtract 1 from what I had before, right? 260 00:13:28,280 --> 00:13:31,890 And I screwed that one up, the simple thing. 261 00:13:31,890 --> 00:13:32,920 All right? 262 00:13:32,920 --> 00:13:35,300 Wow. 263 00:13:35,300 --> 00:13:37,080 No wonder I didn't major in mathematics. 264 00:13:37,080 --> 00:13:38,310 [LAUGHTER] 265 00:13:38,310 --> 00:13:39,140 OK. 266 00:13:39,140 --> 00:13:42,650 Computer Science is this forgiving field. 267 00:13:42,650 --> 00:13:47,300 So you can go 0-- well, this is 0. 268 00:13:47,300 --> 00:13:49,460 So now, let's take a look at what we have here 269 00:13:49,460 --> 00:13:53,320 and check that nothing went wrong, right? 270 00:13:53,320 --> 00:13:55,160 We want to check that nothing went wrong. 271 00:13:55,160 --> 00:13:59,160 And so 2 coming in, 1 going out, 1 going out. 272 00:13:59,160 --> 00:14:01,290 And nothing coming in here, so we're all good. 273 00:14:01,290 --> 00:14:03,610 And so on and so forth, OK? 274 00:14:03,610 --> 00:14:07,190 So there's interesting things happening here 275 00:14:07,190 --> 00:14:17,170 with respect to the conservation laws and having to obey them. 276 00:14:17,170 --> 00:14:21,650 In general, you can imagine that what we're interested in 277 00:14:21,650 --> 00:14:27,340 is simply maximizing the flow from the source, 278 00:14:27,340 --> 00:14:30,240 and getting as much flow out of the source as possible, 279 00:14:30,240 --> 00:14:32,030 and pushing it into the sink. 280 00:14:32,030 --> 00:14:32,710 OK? 281 00:14:32,710 --> 00:14:37,150 Now, the flow here into t, as you can see, 282 00:14:37,150 --> 00:14:41,810 is 2 plus 1, which is 3, OK? 283 00:14:41,810 --> 00:14:46,360 Can anyone take this particular flow network 284 00:14:46,360 --> 00:14:48,410 and increase the flow? 285 00:14:48,410 --> 00:14:50,340 I mean, it's easy to decrease the flow. 286 00:14:50,340 --> 00:14:53,210 You can make everything 0, and that'd be valid, right? 287 00:14:53,210 --> 00:14:55,370 But can you increase the flow? 288 00:14:55,370 --> 00:14:57,530 Do you think that this flow network 289 00:14:57,530 --> 00:15:02,920 allows for a larger flow than 3, given 290 00:15:02,920 --> 00:15:05,086 that the capacities of those edges are fixed 291 00:15:05,086 --> 00:15:06,460 and I'm not going to change them? 292 00:15:10,370 --> 00:15:12,820 Let's see. 293 00:15:12,820 --> 00:15:15,060 I think all of you have Frisbees, right? 294 00:15:15,060 --> 00:15:15,890 Yeah. 295 00:15:15,890 --> 00:15:17,244 Yeah, back there. 296 00:15:17,244 --> 00:15:19,160 STUDENT: I don't think you can, because you're 297 00:15:19,160 --> 00:15:23,380 maximizing two edges, which would have to be increased. 298 00:15:23,380 --> 00:15:25,485 Like, the bottom one coming out of s 299 00:15:25,485 --> 00:15:26,610 would have to be increased. 300 00:15:26,610 --> 00:15:31,024 Or the one on the very top would, too, also 301 00:15:31,024 --> 00:15:33,900 have to be increased. 302 00:15:33,900 --> 00:15:35,810 SRINIVAS DEVADAS: People agree with that? 303 00:15:35,810 --> 00:15:36,320 Over there? 304 00:15:36,320 --> 00:15:36,820 Yep? 305 00:15:36,820 --> 00:15:38,486 STUDENT: You can have a path going along 306 00:15:38,486 --> 00:15:40,271 the top with a flow of 2, so that s is 307 00:15:40,271 --> 00:15:42,660 the one on the top of it has 2. 308 00:15:42,660 --> 00:15:46,430 That, from that, to the right, has 2, like it has now. 309 00:15:46,430 --> 00:15:47,810 From that node, the t has 2. 310 00:15:47,810 --> 00:15:49,268 And then, along the bottom, we have 311 00:15:49,268 --> 00:15:51,972 another path that has 2, from s to the 1 [? plot of it. ?] 312 00:15:51,972 --> 00:15:53,205 And then [INAUDIBLE]. 313 00:15:53,205 --> 00:15:54,080 SRINIVAS DEVADAS: OK. 314 00:15:54,080 --> 00:15:54,579 So-- 315 00:15:54,579 --> 00:15:55,670 [LAUGHTER] 316 00:15:55,670 --> 00:15:58,970 That made perfect sense-- to me. 317 00:15:58,970 --> 00:16:01,100 [CHUCKLES] It did. 318 00:16:01,100 --> 00:16:04,350 So one of the crucial observations 319 00:16:04,350 --> 00:16:06,820 that [? Rajesh ?] made here-- and let me just focus in 320 00:16:06,820 --> 00:16:11,390 on that-- is-- and that's why I think the other gentleman said 321 00:16:11,390 --> 00:16:14,300 no-- is that you can actually decrease 322 00:16:14,300 --> 00:16:17,130 the flow in particular edges. 323 00:16:17,130 --> 00:16:19,070 And that's going to help you increase 324 00:16:19,070 --> 00:16:20,820 the overall flow, right? 325 00:16:20,820 --> 00:16:22,970 And that's why this problem is challenging. 326 00:16:22,970 --> 00:16:25,550 That's why we need so much of a setup, all right? 327 00:16:25,550 --> 00:16:30,450 So one thing that I could do is I could essentially say, 328 00:16:30,450 --> 00:16:35,660 I'm going to take this and make this 0. 329 00:16:35,660 --> 00:16:39,610 So when I do that, essentially what I have is I 330 00:16:39,610 --> 00:16:46,200 get to push more flow out from here, right? 331 00:16:46,200 --> 00:16:48,850 So I get to push more flow. 332 00:16:48,850 --> 00:16:51,160 I can turn this into a 2. 333 00:16:51,160 --> 00:16:54,370 And I can turn this into a 2, right? 334 00:16:54,370 --> 00:16:55,590 Am I done? 335 00:16:55,590 --> 00:16:56,460 STUDENT: No. 336 00:16:56,460 --> 00:16:57,190 SRINIVAS DEVADAS: Not quite. 337 00:16:57,190 --> 00:16:58,731 I mean, I've got one little bug here, 338 00:16:58,731 --> 00:17:00,310 but I can fix that, right? 339 00:17:00,310 --> 00:17:02,400 I've got one little bug here which says, 340 00:17:02,400 --> 00:17:03,810 I've got 2 coming out here. 341 00:17:03,810 --> 00:17:06,230 I made this 0, so I have to push something more. 342 00:17:06,230 --> 00:17:07,599 But hey, I'm lucky. 343 00:17:07,599 --> 00:17:10,730 I've got a s here, which is giving me as much as I want, 344 00:17:10,730 --> 00:17:11,410 correct? 345 00:17:11,410 --> 00:17:12,677 So I can just make this a 2. 346 00:17:15,349 --> 00:17:18,849 And so now we get a flow of 4, right? 347 00:17:18,849 --> 00:17:20,770 You both get Frisbees. 348 00:17:20,770 --> 00:17:23,381 Shall we do blue and purple? 349 00:17:23,381 --> 00:17:23,880 Here you go. 350 00:17:23,880 --> 00:17:24,764 Could you stand up? 351 00:17:27,730 --> 00:17:28,240 Oh, OK. 352 00:17:28,240 --> 00:17:28,890 Over there. 353 00:17:32,150 --> 00:17:35,600 So that actually kind of summarizes, 354 00:17:35,600 --> 00:17:39,070 at some level, our task ahead, right? 355 00:17:39,070 --> 00:17:44,550 So we have to find ways of increasing the flow. 356 00:17:44,550 --> 00:17:48,190 And sometimes, we have to take a step backwards in the sense 357 00:17:48,190 --> 00:17:51,260 that we decrease the flow on a particular edge, right? 358 00:17:51,260 --> 00:17:56,370 So it's not this monotonic increase that Dijkstra would do 359 00:17:56,370 --> 00:17:59,500 or a greedy algorithm, like MST that Eric talked about. 360 00:17:59,500 --> 00:18:02,210 There's going to be something a little more interesting here. 361 00:18:02,210 --> 00:18:04,410 We eventually are going to end up 362 00:18:04,410 --> 00:18:10,960 doing things in a monotonic way, in terms of the overall flow. 363 00:18:10,960 --> 00:18:14,080 So the max flow that we're trying to get at 364 00:18:14,080 --> 00:18:16,030 is going to start with the current flow. 365 00:18:16,030 --> 00:18:19,850 And we're going to improve the current flow constantly. 366 00:18:19,850 --> 00:18:23,750 But that doesn't mean that the edges 367 00:18:23,750 --> 00:18:26,210 are going to look monotonic in terms 368 00:18:26,210 --> 00:18:29,610 of the flows on a particular edge in relation 369 00:18:29,610 --> 00:18:30,360 to the capacity. 370 00:18:30,360 --> 00:18:32,030 You'll never exceed the capacity. 371 00:18:32,030 --> 00:18:34,540 But as you saw in this little example already, 372 00:18:34,540 --> 00:18:37,640 we increase from 3 to 4, by taking that edge that 373 00:18:37,640 --> 00:18:41,100 was vertical up there, which says 0, colon, 3, 374 00:18:41,100 --> 00:18:44,310 and that was 1, and we shrank the flow on it. 375 00:18:44,310 --> 00:18:46,850 And so how are we going to discover these paths, 376 00:18:46,850 --> 00:18:50,660 especially if we have a 5,000-node network and-- I 377 00:18:50,660 --> 00:18:52,390 don't know-- 10,000 edges? 378 00:18:52,390 --> 00:18:54,380 And so that's essentially what we 379 00:18:54,380 --> 00:18:56,870 have to do for the rest of this lecture. 380 00:18:56,870 --> 00:19:00,180 Any questions so far? 381 00:19:00,180 --> 00:19:01,140 OK. 382 00:19:01,140 --> 00:19:04,090 So we've done flow networks. 383 00:19:04,090 --> 00:19:08,160 I kind of defined what the max flow problem is. 384 00:19:08,160 --> 00:19:11,964 And let me just write that out more precisely. 385 00:19:15,470 --> 00:19:31,400 Given a flow network, G, find the flow 386 00:19:31,400 --> 00:19:46,769 with maximum value on G. And for that, the max flow is 4, right? 387 00:19:46,769 --> 00:19:48,560 So that's another thing we haven't actually 388 00:19:48,560 --> 00:19:51,560 done, which is obviously important for us to do, 389 00:19:51,560 --> 00:19:55,940 which is we have to show that the 4, in this case, 390 00:19:55,940 --> 00:19:57,690 is the max flow, right? 391 00:19:57,690 --> 00:20:00,410 So now, of course, I've given that away. 392 00:20:00,410 --> 00:20:04,120 And so I'm not going to ask you can you push this over to 5. 393 00:20:04,120 --> 00:20:07,070 But you might think that 5 is a possibility, simply 394 00:20:07,070 --> 00:20:08,770 because the capacities of the edges that 395 00:20:08,770 --> 00:20:13,130 are coming out of the source are 3 plus 2, which is 5, right? 396 00:20:13,130 --> 00:20:16,940 So it's certainly possible that you 397 00:20:16,940 --> 00:20:20,380 could push at least, if you only look at those two edges, 398 00:20:20,380 --> 00:20:23,200 that you could push 5 units from the source. 399 00:20:23,200 --> 00:20:25,950 But in this case, in this example, 400 00:20:25,950 --> 00:20:28,910 if you obey the laws of conservation, 401 00:20:28,910 --> 00:20:34,850 you cannot obey those laws and get 5 units from the source 402 00:20:34,850 --> 00:20:36,227 to the sink, t. 403 00:20:36,227 --> 00:20:37,310 But we have to prove that. 404 00:20:37,310 --> 00:20:39,180 And we have an algorithm that says 405 00:20:39,180 --> 00:20:41,370 this is the best that you can possibly do. 406 00:20:41,370 --> 00:20:43,680 And the algorithm terminates when that happens. 407 00:20:43,680 --> 00:20:46,320 And that's our Ford-Fulkerson algorithm, right? 408 00:20:49,010 --> 00:20:50,290 Good. 409 00:20:50,290 --> 00:20:54,430 So that's what we have so far. 410 00:20:54,430 --> 00:20:57,280 I want to talk about flow network assumptions. 411 00:20:57,280 --> 00:21:00,544 And I can do that over here. 412 00:21:00,544 --> 00:21:02,127 This is going to make our life easier. 413 00:21:05,080 --> 00:21:08,730 One of the things that's a little bit confusing 414 00:21:08,730 --> 00:21:13,000 sometimes is the circular flow and the fact 415 00:21:13,000 --> 00:21:18,940 that we're going to potentially have 416 00:21:18,940 --> 00:21:25,940 flows that correspond to edges coming in and edges going out. 417 00:21:25,940 --> 00:21:31,940 So for example, if I had something like s and u, 418 00:21:31,940 --> 00:21:34,730 for example-- and s could be the source in this case, 419 00:21:34,730 --> 00:21:37,690 or it could be another node-- suppose 420 00:21:37,690 --> 00:21:42,230 I had a little subnetwork that looks like this. 421 00:21:42,230 --> 00:21:45,830 And I'm just giving you what the capacities are. 422 00:21:45,830 --> 00:21:49,460 This is a bit strange in the sense 423 00:21:49,460 --> 00:21:54,790 that you could have a situation where you essentially 424 00:21:54,790 --> 00:21:59,700 have zero flow, really, because you have one unit coming 425 00:21:59,700 --> 00:22:01,950 in here and one unit leaving. 426 00:22:01,950 --> 00:22:02,480 All right? 427 00:22:02,480 --> 00:22:04,271 And you can think of this-- let's just call 428 00:22:04,271 --> 00:22:07,720 this s1, to make it clear that it doesn't 429 00:22:07,720 --> 00:22:10,389 have to be the source, right? 430 00:22:10,389 --> 00:22:11,930 And so you could have the circularity 431 00:22:11,930 --> 00:22:13,390 that you saw over there. 432 00:22:13,390 --> 00:22:16,730 And now you're talking about, well, I 433 00:22:16,730 --> 00:22:20,430 might have 1, colon, 1 here, and 1, colon, 2 here, 434 00:22:20,430 --> 00:22:22,480 which is fine for this subnetwork. 435 00:22:22,480 --> 00:22:26,320 But if I have stuff going out, what happens with that? 436 00:22:26,320 --> 00:22:27,990 Well that's got to be a 0. 437 00:22:27,990 --> 00:22:30,360 I could have a 1 and a 2. 438 00:22:30,360 --> 00:22:36,530 And if I have a 2 here, then-- if I had a 1 and 2 here, 439 00:22:36,530 --> 00:22:39,460 then that doesn't work, because maybe I 440 00:22:39,460 --> 00:22:41,670 need something else coming in. 441 00:22:41,670 --> 00:22:44,240 So you can see that, pretty quickly, it 442 00:22:44,240 --> 00:22:46,470 gets kind of confusing, if we end up 443 00:22:46,470 --> 00:22:54,930 having these cycles that are such simple cycles, 444 00:22:54,930 --> 00:22:59,000 especially the ones where you have Su and Us, OK? 445 00:22:59,000 --> 00:23:03,696 And so we're going to disallow cycles of two kinds, right? 446 00:23:03,696 --> 00:23:05,320 The first cycle we're going to disallow 447 00:23:05,320 --> 00:23:09,930 is this simple one where we say, if I have a, then 448 00:23:09,930 --> 00:23:11,600 no self-loop edges allowed. 449 00:23:20,570 --> 00:23:23,110 So that would involve accumulation 450 00:23:23,110 --> 00:23:24,202 at a particular node. 451 00:23:24,202 --> 00:23:26,160 And it's going to make things really confusing. 452 00:23:26,160 --> 00:23:28,680 And CLRS disallows that. 453 00:23:28,680 --> 00:23:31,930 And most flow network algorithms assume that you're just 454 00:23:31,930 --> 00:23:35,000 going to discard these cycles. 455 00:23:35,000 --> 00:23:39,580 This particular transformation that I'm going to describe here 456 00:23:39,580 --> 00:23:44,060 is something that is going to be forced on you. 457 00:23:44,060 --> 00:23:51,430 And this is for your benefit in over 6 lectures and sections. 458 00:23:51,430 --> 00:23:56,270 But it's not actually something that CLRS follows. 459 00:23:56,270 --> 00:23:58,640 And it's going to make things simpler, though. 460 00:23:58,640 --> 00:24:00,410 And what we're going to do is we're 461 00:24:00,410 --> 00:24:06,210 going to take any pair of vertices that 462 00:24:06,210 --> 00:24:11,200 has this characteristic, where you have s1, u, and u, s1, 463 00:24:11,200 --> 00:24:14,550 and they have non-zero capacities. 464 00:24:14,550 --> 00:24:17,410 So s1, u has a capacity of 1. 465 00:24:17,410 --> 00:24:19,740 u, s1 has a capacity of 2. 466 00:24:19,740 --> 00:24:21,440 Both of these edges exist. 467 00:24:21,440 --> 00:24:22,940 And if these edges exist, that means 468 00:24:22,940 --> 00:24:26,580 they have non-zero capacity, positive capacity. 469 00:24:26,580 --> 00:24:31,910 And we're going to transform that, very simply, into-- this 470 00:24:31,910 --> 00:24:35,760 is not changing the generality of the algorithm, 471 00:24:35,760 --> 00:24:38,250 but all I'm going to do is transform 472 00:24:38,250 --> 00:24:42,120 it-- call this s1-- into something that 473 00:24:42,120 --> 00:24:45,750 satisfies this restriction. 474 00:24:45,750 --> 00:24:52,330 So I could have 2 here, 1, and 1, OK? 475 00:24:52,330 --> 00:24:56,092 So all I've done is introduce u prime, right? 476 00:24:56,092 --> 00:24:57,550 Then I can always do this-- if this 477 00:24:57,550 --> 00:25:00,750 is trivial for any pair of vertices, 478 00:25:00,750 --> 00:25:02,670 I can introduce one other vertex. 479 00:25:02,670 --> 00:25:04,190 It all works out. 480 00:25:04,190 --> 00:25:08,180 Linear expansion, constant factors, ignore them. 481 00:25:08,180 --> 00:25:10,060 Life is wonderful. 482 00:25:10,060 --> 00:25:15,430 So all I've done is taken away the situation 483 00:25:15,430 --> 00:25:20,310 where I have-- you can think of it as two-way streets, right? 484 00:25:20,310 --> 00:25:22,310 Two-way streets are annoying. 485 00:25:22,310 --> 00:25:24,310 You don't quite know what the rate of traffic 486 00:25:24,310 --> 00:25:26,700 is from one end of the street to another, 487 00:25:26,700 --> 00:25:28,770 because cars are going in both directions. 488 00:25:28,770 --> 00:25:30,520 And you have to do subtraction. 489 00:25:30,520 --> 00:25:35,060 Subtraction is painful, so we don't want that. 490 00:25:35,060 --> 00:25:38,560 So we're just going to assume that this is u prime. 491 00:25:38,560 --> 00:25:41,120 And now, you're all set. 492 00:25:41,120 --> 00:25:41,950 We allow this. 493 00:25:41,950 --> 00:25:45,040 So we have to allow for generality reasons. 494 00:25:45,040 --> 00:25:48,230 As we saw in that very first example there, 495 00:25:48,230 --> 00:25:50,070 we are going to have cycles here, OK? 496 00:25:50,070 --> 00:25:55,180 But we just don't want cycles to be of length 1 or 2, OK? 497 00:25:55,180 --> 00:25:57,630 So that's essentially what we're going to disallow. 498 00:25:57,630 --> 00:25:58,560 All right? 499 00:25:58,560 --> 00:26:01,800 The good news is that, if you do this, 500 00:26:01,800 --> 00:26:05,890 then we'll only have a single notion of flow. 501 00:26:05,890 --> 00:26:08,860 Whereas, if you go read CLRS, you'll 502 00:26:08,860 --> 00:26:11,820 see that there's two notions of flow in CLRS. 503 00:26:11,820 --> 00:26:15,060 There's positive flow, which is different from net flow. 504 00:26:17,640 --> 00:26:20,610 And the positive flow is different from net flow 505 00:26:20,610 --> 00:26:24,840 in graphs that have this particular structure, 506 00:26:24,840 --> 00:26:27,840 or have nodes with these properties. 507 00:26:27,840 --> 00:26:31,280 But if you disallow them, then you can just talk about flow, 508 00:26:31,280 --> 00:26:33,140 and it doesn't matter. 509 00:26:33,140 --> 00:26:35,540 Positive flow is the same as net flow, all right? 510 00:26:35,540 --> 00:26:38,010 So for the purposes of [? 6 over 6, ?] 511 00:26:38,010 --> 00:26:42,400 for this semester, we're going to simply think about flow 512 00:26:42,400 --> 00:26:45,910 and equate that to positive flow, equate that to net flow. 513 00:26:45,910 --> 00:26:48,140 And it's all going to work out, assuming 514 00:26:48,140 --> 00:26:52,370 your graphs satisfy these two properties of the cycle 515 00:26:52,370 --> 00:26:53,350 lengths. 516 00:26:53,350 --> 00:26:55,350 All right? 517 00:26:55,350 --> 00:26:56,621 Cool. 518 00:26:56,621 --> 00:26:57,120 Good. 519 00:26:57,120 --> 00:26:59,250 So let's keep going here. 520 00:26:59,250 --> 00:27:02,325 So we're up to finished up on max flow. 521 00:27:04,930 --> 00:27:09,745 Let me just give you some sense of notation. 522 00:27:13,320 --> 00:27:20,160 I've talked a lot about constraints. 523 00:27:20,160 --> 00:27:23,090 But we've got to write some stuff out, 524 00:27:23,090 --> 00:27:28,660 because we're going to be getting more precise 525 00:27:28,660 --> 00:27:31,620 and proving things in just a few minutes. 526 00:27:34,260 --> 00:27:36,800 So what is a flow? 527 00:27:36,800 --> 00:27:44,230 Well, to be precise, it is going to be a function that satisfies 528 00:27:44,230 --> 00:27:45,770 the following properties. 529 00:27:45,770 --> 00:27:47,675 It satisfies the capacity constraint. 530 00:27:59,960 --> 00:28:06,800 This is the obvious capacity constraint, intuitive capacity 531 00:28:06,800 --> 00:28:07,319 constraint. 532 00:28:07,319 --> 00:28:08,860 And then we've got flow conservation. 533 00:28:16,120 --> 00:28:22,940 And the important thing here is that I don't have it for all V, 534 00:28:22,940 --> 00:28:26,840 but I do have it for vertices, V, that 535 00:28:26,840 --> 00:28:29,760 are not the source or the sink. 536 00:28:29,760 --> 00:28:41,660 And I'm going to require f(u,v) equals 0, right? 537 00:28:41,660 --> 00:28:46,680 And the last one, which I haven't talked about, 538 00:28:46,680 --> 00:28:52,070 but becomes easy to talk about, given this constraint, 539 00:28:52,070 --> 00:28:52,875 is skew symmetry. 540 00:29:06,430 --> 00:29:12,110 So if you take-- this doesn't have to be an edge between u 541 00:29:12,110 --> 00:29:17,370 and v. Now, I'm talking about the flow, f, between u and v. 542 00:29:17,370 --> 00:29:20,300 And so the u could be s, which is the source. 543 00:29:20,300 --> 00:29:22,770 v could be t, which is the sink. 544 00:29:22,770 --> 00:29:25,680 So in general, I'm not talking about a flow. 545 00:29:25,680 --> 00:29:31,300 And there obviously has to be a path from u to v, 546 00:29:31,300 --> 00:29:35,310 in order for there to be a non-zero flow, f(u,v), right? 547 00:29:35,310 --> 00:29:38,040 If there's no path, there's no way of getting there. 548 00:29:38,040 --> 00:29:43,770 But having said that, the definition of a flow here 549 00:29:43,770 --> 00:29:47,570 in our network is the straightforward definition, 550 00:29:47,570 --> 00:29:52,380 which simply says, if there's a flow from u to v, 551 00:29:52,380 --> 00:29:56,830 regardless of what u and v are, then the value of that flow 552 00:29:56,830 --> 00:30:00,570 is simply the negation of the value 553 00:30:00,570 --> 00:30:06,770 of the flow from v to u, which makes perfect sense, right? 554 00:30:06,770 --> 00:30:13,510 And this all works out under the definition of net flow. 555 00:30:13,510 --> 00:30:16,380 And so this is essentially what the definition of net flow 556 00:30:16,380 --> 00:30:18,910 is in the textbook. 557 00:30:18,910 --> 00:30:21,430 But for our purposes here, we don't 558 00:30:21,430 --> 00:30:24,310 have to add that adjective. 559 00:30:24,310 --> 00:30:26,370 We just are going to be talking about flows. 560 00:30:26,370 --> 00:30:30,350 Positive or net, they're the same, all right? 561 00:30:30,350 --> 00:30:31,080 All right. 562 00:30:31,080 --> 00:30:32,026 Good. 563 00:30:32,026 --> 00:30:41,580 So one of the things you can do with this notation-- 564 00:30:41,580 --> 00:30:45,610 and we're going to use what's called implicit summation 565 00:30:45,610 --> 00:30:50,280 notation on top of this-- is to prove some interesting things, 566 00:30:50,280 --> 00:30:51,850 interesting theorems, that give you 567 00:30:51,850 --> 00:30:55,310 some intuition as to how algorithms on flow networks 568 00:30:55,310 --> 00:30:56,690 are going to work. 569 00:30:56,690 --> 00:31:07,160 And in particular, we're going to use this notation when we 570 00:31:07,160 --> 00:31:10,580 talk about the value of a flow. 571 00:31:10,580 --> 00:31:20,220 So the value of a flow, f, is denoted-- 572 00:31:20,220 --> 00:31:22,860 you can think of it as a cardinality of f. 573 00:31:22,860 --> 00:31:33,380 And f is v, belonging to capital V, f(s,v). 574 00:31:33,380 --> 00:31:38,410 And that is f(s,V), so what I have written here. 575 00:31:38,410 --> 00:31:44,250 Well, given a flow network, I want one particular quantity 576 00:31:44,250 --> 00:31:46,610 that I want to maximize. 577 00:31:46,610 --> 00:31:48,920 And that particular quantity is going 578 00:31:48,920 --> 00:31:55,220 to be defined, based on how much I can push from s, how much can 579 00:31:55,220 --> 00:31:57,600 I push outward from s. 580 00:31:57,600 --> 00:32:01,130 That's the crucial quantity that I want to maximize. 581 00:32:01,130 --> 00:32:05,260 That quantity is-- you think about everything 582 00:32:05,260 --> 00:32:09,230 that is going out of s, and you add it all up together. 583 00:32:09,230 --> 00:32:17,380 So from s, you look at any other vertex, every other vertex, 584 00:32:17,380 --> 00:32:20,050 and you say, what is f(s,v)? 585 00:32:20,050 --> 00:32:23,840 And I'm not talking about just the edges that come out of s. 586 00:32:23,840 --> 00:32:28,380 A vertex, v, small v, can be any vertex. 587 00:32:28,380 --> 00:32:34,750 If I add up all of the flows that come out of s, then 588 00:32:34,750 --> 00:32:39,280 that is the flow that responds to my flow network. 589 00:32:39,280 --> 00:32:44,360 That is everything that's getting pushed out of s, OK? 590 00:32:44,360 --> 00:32:47,280 Now, it may be the case that-- remember, 591 00:32:47,280 --> 00:32:49,840 I'm talking about flow here-- so it 592 00:32:49,840 --> 00:33:00,470 may be the case that you have an edge from s coming in from v4. 593 00:33:00,470 --> 00:33:06,310 And there may be a flow associated with that. 594 00:33:06,310 --> 00:33:10,140 This is maybe something like 1, colon, 2, all right? 595 00:33:10,140 --> 00:33:20,020 So what this means is that f(s,vr) is-- this is f, 596 00:33:20,020 --> 00:33:24,510 remember-- so this is minus f(v4,s). 597 00:33:24,510 --> 00:33:30,790 And in this particular case, this is 1. 598 00:33:30,790 --> 00:33:34,980 So this is minus 1, OK? 599 00:33:34,980 --> 00:33:38,040 So keep that in mind. 600 00:33:38,040 --> 00:33:40,930 When I talk about the flow of the network, 601 00:33:40,930 --> 00:33:43,130 I'm going to be looking at the source. 602 00:33:43,130 --> 00:33:45,370 And I'm going to be looking at all of the flows that 603 00:33:45,370 --> 00:33:46,520 are going outward. 604 00:33:46,520 --> 00:33:50,400 And I have to keep in mind the skew symmetry relationship. 605 00:33:50,400 --> 00:33:52,690 I obviously have to obey capacity constraints 606 00:33:52,690 --> 00:33:56,920 and the conservation laws, all right? 607 00:33:56,920 --> 00:34:03,880 So given that, let's use this implicit summation notation 608 00:34:03,880 --> 00:34:08,346 and show some simple properties of flow. 609 00:34:08,346 --> 00:34:30,670 So let's look at-- one thing I want 610 00:34:30,670 --> 00:34:34,860 to emphasize is what I've done here 611 00:34:34,860 --> 00:34:42,820 is use this implicit summation notation, 612 00:34:42,820 --> 00:34:46,400 which simply says, if I see a capital letter here, 613 00:34:46,400 --> 00:34:47,699 that's a set. 614 00:34:47,699 --> 00:34:52,080 And I'm going to have to enumerate 615 00:34:52,080 --> 00:34:55,570 all of the members of that set. 616 00:34:55,570 --> 00:34:58,790 And it's implicit summation. 617 00:34:58,790 --> 00:35:01,650 So as I enumerate those members, I'm 618 00:35:01,650 --> 00:35:03,855 going to add up all of these quantities, right? 619 00:35:03,855 --> 00:35:05,230 So that's really what this means. 620 00:35:05,230 --> 00:35:09,360 So the sigma here gets embedded into this capital 621 00:35:09,360 --> 00:35:11,270 V. So two things going on. 622 00:35:11,270 --> 00:35:12,860 The small v turned into capital V, 623 00:35:12,860 --> 00:35:15,250 because I'm looking at the entire set. 624 00:35:15,250 --> 00:35:17,410 And the sigma gets in there too. 625 00:35:17,410 --> 00:35:19,550 And that's why it's implicit summation, not just 626 00:35:19,550 --> 00:35:22,670 implicit set notation. 627 00:35:22,670 --> 00:35:24,140 So some simple properties. 628 00:35:24,140 --> 00:35:31,741 I can say, f(x,x) is 0, where x is an arbitrary set. 629 00:35:31,741 --> 00:35:38,150 All that says is, let's say, x has a single member in it, 630 00:35:38,150 --> 00:35:39,540 which is a. 631 00:35:39,540 --> 00:35:44,430 Then f(a,a) is always 0, because if you don't allow self-loop 632 00:35:44,430 --> 00:35:49,110 edges, and that's pretty much all you need. 633 00:35:49,110 --> 00:35:53,630 If you have a pair of vertices here, a and b, 634 00:35:53,630 --> 00:36:02,560 then what you're saying is f(a,b) plus f(b,a) is 0. 635 00:36:02,560 --> 00:36:05,630 And that's true, because of skew symmetry. 636 00:36:05,630 --> 00:36:06,130 Right? 637 00:36:06,130 --> 00:36:07,470 We just wrote that out. 638 00:36:07,470 --> 00:36:10,520 So f(x,x) is 0. 639 00:36:10,520 --> 00:36:15,070 And in general, you can say, even though X and Y are sets 640 00:36:15,070 --> 00:36:20,240 of vertices, I'm going to be able to use skew symmetry 641 00:36:20,240 --> 00:36:27,180 to say that f(X,Y) is minus of f(Y,X), all right? 642 00:36:27,180 --> 00:36:29,040 Similar argument. 643 00:36:29,040 --> 00:36:32,930 And then, lastly-- there's any number of these, 644 00:36:32,930 --> 00:36:40,820 we just do three of them here-- X of f(XUY, 645 00:36:40,820 --> 00:36:48,590 to Z) is f(X,Z) plus f(Y,Z)-- we've got to use these 646 00:36:48,590 --> 00:36:52,590 properties to prove our first theorem here on flow networks-- 647 00:36:52,590 --> 00:36:57,500 if X of X intersection Y is null. 648 00:36:57,500 --> 00:36:58,940 So you don't want to double-count. 649 00:36:58,940 --> 00:37:00,360 So that's all this is. 650 00:37:00,360 --> 00:37:02,160 Make sure you're not double-counting. 651 00:37:02,160 --> 00:37:06,660 You've got f(XUY), and you want to look 652 00:37:06,660 --> 00:37:11,180 at that entire set, the union, and then 653 00:37:11,180 --> 00:37:16,940 look at the flow from any member in XUY to any member in Z. 654 00:37:16,940 --> 00:37:20,020 And you can do that by breaking it up, 655 00:37:20,020 --> 00:37:22,470 provided you're careful about double-counting. 656 00:37:22,470 --> 00:37:25,940 And the fact that the two sets, X and Y, 657 00:37:25,940 --> 00:37:28,910 do not have an intersection, or they have a null intersection, 658 00:37:28,910 --> 00:37:31,610 implies that you're OK with the [? write ?] inside. 659 00:37:31,610 --> 00:37:32,630 All right? 660 00:37:32,630 --> 00:37:35,530 So you might be going, why are we doing this? 661 00:37:35,530 --> 00:37:43,390 Well, here's a good reason to like implicit set notation. 662 00:37:43,390 --> 00:37:50,530 You can prove some interesting theorems in a very elegant way, 663 00:37:50,530 --> 00:37:52,890 using this notation. 664 00:37:52,890 --> 00:37:55,182 So let's do one example of that. 665 00:37:55,182 --> 00:37:56,765 You'll probably see others in section. 666 00:38:01,410 --> 00:38:03,980 So one of the things that we'd like to do 667 00:38:03,980 --> 00:38:09,090 is prove a pretty important theorem, 668 00:38:09,090 --> 00:38:12,030 which I think all of you probably 669 00:38:12,030 --> 00:38:17,350 can assume in your heads, given all of the properties of flow 670 00:38:17,350 --> 00:38:18,760 networks that we have. 671 00:38:18,760 --> 00:38:23,100 And it's a very simple theorem that simply says, 672 00:38:23,100 --> 00:38:25,040 I have the law of conservation that 673 00:38:25,040 --> 00:38:28,440 is applied on all of these intermediate vertices, 674 00:38:28,440 --> 00:38:32,670 and I've got a bunch of commodities, 675 00:38:32,670 --> 00:38:36,750 I've got a flow going out of s, right? 676 00:38:36,750 --> 00:38:39,360 So where can this flow go? 677 00:38:39,360 --> 00:38:42,580 Where does this flow end up? 678 00:38:42,580 --> 00:38:48,430 It ends up at the sink, at t, right? 679 00:38:48,430 --> 00:38:51,770 So the point is that, if you have all of these properties 680 00:38:51,770 --> 00:38:57,480 that we have up here, you're going to be able to show-- 681 00:38:57,480 --> 00:39:00,820 and you want to show this, you want to prove this-- 682 00:39:00,820 --> 00:39:07,530 that the value of a flow, which is defined as what gets pushed 683 00:39:07,530 --> 00:39:14,000 out from the source, is exactly what goes into the sink, right? 684 00:39:14,000 --> 00:39:16,800 If that's not the case, there's been a violation 685 00:39:16,800 --> 00:39:21,700 of some property, perhaps a capacity constraint, perhaps, 686 00:39:21,700 --> 00:39:26,500 more likely, a conservation constraint, OK? 687 00:39:26,500 --> 00:39:31,890 So the theorem that we'd like to prove is simply that f is 688 00:39:31,890 --> 00:39:34,900 f(v,t), right? 689 00:39:34,900 --> 00:39:36,400 That's the theorem. 690 00:39:36,400 --> 00:39:38,360 And there's a lot going on here, so it's worth 691 00:39:38,360 --> 00:39:42,180 spending 30 seconds looking at what exactly this means. 692 00:39:42,180 --> 00:39:45,820 What I have here is that, if you just look at this 693 00:39:45,820 --> 00:39:50,890 and that, I'm saying that f is what gets 694 00:39:50,890 --> 00:39:54,760 pushed out of the source, OK? 695 00:39:54,760 --> 00:39:58,870 And now what I'm saying here is that f, the value, 696 00:39:58,870 --> 00:40:04,120 is exactly what gets pushed into the sink, OK? 697 00:40:04,120 --> 00:40:06,140 So this is what I have to prove, right? 698 00:40:06,140 --> 00:40:09,920 And I should be able to prove that, by invoking my laws. 699 00:40:09,920 --> 00:40:10,540 That's it. 700 00:40:10,540 --> 00:40:12,600 I mean, that's my axiomatic system. 701 00:40:12,600 --> 00:40:13,880 I've got those laws. 702 00:40:13,880 --> 00:40:18,320 I've got a definition of a flow that may not necessarily 703 00:40:18,320 --> 00:40:19,340 be the max flow. 704 00:40:19,340 --> 00:40:21,505 It might be something much less than the max flow, 705 00:40:21,505 --> 00:40:22,810 it might be the max flow. 706 00:40:22,810 --> 00:40:24,940 Regardless, what gets out of the source 707 00:40:24,940 --> 00:40:26,630 has to get into the sink, right? 708 00:40:26,630 --> 00:40:28,110 So how are we going to do that? 709 00:40:28,110 --> 00:40:30,464 And the implicit summation notation 710 00:40:30,464 --> 00:40:31,880 is going to give you, essentially, 711 00:40:31,880 --> 00:40:35,250 a three or four-line proof, which is very intuitive, right? 712 00:40:35,250 --> 00:40:36,270 So let's do that. 713 00:40:36,270 --> 00:40:39,010 And maybe you can help me. 714 00:40:39,010 --> 00:40:41,410 So we're going to start with what we know. 715 00:40:41,410 --> 00:40:44,110 So that's the proof. 716 00:40:44,110 --> 00:40:46,642 f equals f(s,V). 717 00:40:49,380 --> 00:40:49,880 Right? 718 00:40:49,880 --> 00:40:50,950 So that's what we've got. 719 00:40:50,950 --> 00:40:54,050 That's the definition of cardinality 720 00:40:54,050 --> 00:40:56,530 of f, or a value of f, OK? 721 00:40:59,830 --> 00:41:03,540 What I'm going to do is I'm going 722 00:41:03,540 --> 00:41:08,080 to say this is the same as-- I'll give you the first step, 723 00:41:08,080 --> 00:41:09,890 and then let's see if you can help me 724 00:41:09,890 --> 00:41:16,290 with the remaining-- is the same as f of v minus s 725 00:41:16,290 --> 00:41:18,960 capital V, right? 726 00:41:18,960 --> 00:41:24,070 So if you're having trouble differentiating between my cap 727 00:41:24,070 --> 00:41:26,790 V's and small v's, holler. 728 00:41:26,790 --> 00:41:28,700 I'm trying to write them as big as possible. 729 00:41:28,700 --> 00:41:28,960 Yeah? 730 00:41:28,960 --> 00:41:31,050 STUDENT: Could you maybe put little hats on the top of them? 731 00:41:31,050 --> 00:41:32,800 SRINIVAS DEVADAS: Put little hats on them. 732 00:41:32,800 --> 00:41:34,317 Yes, I will put little hats on them. 733 00:41:34,317 --> 00:41:36,150 I'd put little Frisbees on them, if I could, 734 00:41:36,150 --> 00:41:41,990 but-- I like Frisbees much better than hats. 735 00:41:41,990 --> 00:41:42,490 All right. 736 00:41:42,490 --> 00:41:43,180 That's good. 737 00:41:43,180 --> 00:41:45,000 That's good to do. 738 00:41:45,000 --> 00:41:47,210 So yeah. 739 00:41:47,210 --> 00:41:49,240 So I think, hopefully, I'll keep doing this, 740 00:41:49,240 --> 00:41:51,610 and it won't be confusing. 741 00:41:51,610 --> 00:41:56,370 So what I've done here is invoke, essentially, 742 00:41:56,370 --> 00:42:01,280 this, except it's not exactly that, in the sense 743 00:42:01,280 --> 00:42:03,170 that it's written a little bit differently. 744 00:42:03,170 --> 00:42:06,180 But if you see what's going on here, what I've done 745 00:42:06,180 --> 00:42:15,420 is look at this s, and I've said, think of this s 746 00:42:15,420 --> 00:42:22,340 as being cap V minus s. 747 00:42:22,340 --> 00:42:22,840 Right? 748 00:42:22,840 --> 00:42:23,920 So that gives you s. 749 00:42:23,920 --> 00:42:25,820 And those are clearly disjoint, right? 750 00:42:25,820 --> 00:42:28,430 Those are clearly disjoint sets. 751 00:42:28,430 --> 00:42:30,680 There is this one and this one are disjoint sets. 752 00:42:30,680 --> 00:42:31,530 That's what I mean to say. 753 00:42:31,530 --> 00:42:32,946 I mean, these two aren't disjoint, 754 00:42:32,946 --> 00:42:34,354 but this and that are disjoint. 755 00:42:34,354 --> 00:42:35,770 And that's what you need, in order 756 00:42:35,770 --> 00:42:40,220 to invoke the little property that you have here. 757 00:42:40,220 --> 00:42:42,810 And so that all make sense? 758 00:42:42,810 --> 00:42:44,020 You see why I did that? 759 00:42:44,020 --> 00:42:45,960 OK? 760 00:42:45,960 --> 00:42:50,260 What can I say about either of these two quantities? 761 00:42:50,260 --> 00:42:52,660 Can I say something about either of these two quantities? 762 00:42:56,560 --> 00:42:57,286 Yeah? 763 00:42:57,286 --> 00:42:58,870 STUDENT: f(V,V) is 0. 764 00:42:58,870 --> 00:43:00,120 SRINIVAS DEVADAS: f(V,V) is 0. 765 00:43:00,120 --> 00:43:01,430 That's exactly right. 766 00:43:01,430 --> 00:43:02,510 f(V,V) is 0. 767 00:43:02,510 --> 00:43:04,905 There you go. 768 00:43:04,905 --> 00:43:05,405 Yep. 769 00:43:08,780 --> 00:43:14,910 So this is simply I'm going to invert that. 770 00:43:14,910 --> 00:43:23,257 I'm going to write this as f of V hat minus s, OK? 771 00:43:23,257 --> 00:43:24,090 I'll just flip this. 772 00:43:24,090 --> 00:43:26,420 I had a negative sign here, but I've flipped that. 773 00:43:26,420 --> 00:43:29,663 And skew symmetry tells me I can do that, right? 774 00:43:33,210 --> 00:43:34,080 All right. 775 00:43:34,080 --> 00:43:36,630 So I'm up to this point here. 776 00:43:36,630 --> 00:43:43,895 Now, what I'm going to do is I'm going to do f(V,t). 777 00:43:43,895 --> 00:43:46,020 And the reason I want to do this is because this is 778 00:43:46,020 --> 00:43:47,400 where I want to get at, right? 779 00:43:47,400 --> 00:43:49,608 Eventually, I want to show something that corresponds 780 00:43:49,608 --> 00:43:54,710 to f(V,t), right? 781 00:43:54,710 --> 00:43:58,440 And what I have here is V,t. 782 00:43:58,440 --> 00:44:06,120 But now, I could do plus f(V,V minus-- cap-- 783 00:44:06,120 --> 00:44:10,460 minus s minus t) right? 784 00:44:10,460 --> 00:44:13,860 So what I've done here is taken V minus s 785 00:44:13,860 --> 00:44:15,580 and pulled out t from it. 786 00:44:15,580 --> 00:44:18,630 Remember, t is part of cap V. Cap 787 00:44:18,630 --> 00:44:20,810 V contains all of the vertices. 788 00:44:20,810 --> 00:44:23,600 So I've pulled out t from it, but that implies 789 00:44:23,600 --> 00:44:26,750 that I have to do a V minus s minus t over here. 790 00:44:26,750 --> 00:44:32,000 And again, they're disjoint, so it's all good. 791 00:44:32,000 --> 00:44:37,150 What can I say about this? 792 00:44:37,150 --> 00:44:38,040 Yeah? 793 00:44:38,040 --> 00:44:40,270 STUDENT: It's 0 because of flow conservation? 794 00:44:40,270 --> 00:44:42,520 SRINIVAS DEVADAS: It's 0 because of flow conservation. 795 00:44:42,520 --> 00:44:43,810 That's exactly right. 796 00:44:43,810 --> 00:44:46,110 We didn't quite write it that way. 797 00:44:46,110 --> 00:44:49,770 But if you look at what the implicit summation notation 798 00:44:49,770 --> 00:44:54,700 would mean for that, you look at it and you say, 799 00:44:54,700 --> 00:45:00,400 maybe one more step would be, let me think about this 800 00:45:00,400 --> 00:45:02,150 as being, f(V,t). 801 00:45:05,202 --> 00:45:08,720 It'll become more obvious if I write it this way. 802 00:45:08,720 --> 00:45:11,770 f(V-- I'm putting a minus in here-- 803 00:45:11,770 --> 00:45:18,220 V minus s minus t and cap V again, right? 804 00:45:18,220 --> 00:45:21,510 So all I've done here is flip these two. 805 00:45:21,510 --> 00:45:23,750 Skew symmetry allows me to do that. 806 00:45:23,750 --> 00:45:25,340 And now look at what I have here. 807 00:45:25,340 --> 00:45:28,280 I'm talking about a flow that corresponds 808 00:45:28,280 --> 00:45:34,330 to some-- for any vertex, I pick-- 809 00:45:34,330 --> 00:45:36,540 and it's not an s vertex, it's not a t vertex, 810 00:45:36,540 --> 00:45:38,426 so it's an intermediate vertex. 811 00:45:38,426 --> 00:45:40,050 And if I look at an intermediate vertex 812 00:45:40,050 --> 00:45:45,720 and look at the flow that goes out to all vertices, 813 00:45:45,720 --> 00:45:48,720 conservation says that has to be 0, right? 814 00:45:48,720 --> 00:45:51,540 So that's exactly what this says. 815 00:45:51,540 --> 00:45:58,810 For any u that's neither s nor t but in V, the sum has to be 0. 816 00:45:58,810 --> 00:46:02,760 So this is zero, and we're done. 817 00:46:02,760 --> 00:46:04,997 All right. 818 00:46:04,997 --> 00:46:05,830 Oh, you-- a Frisbee? 819 00:46:05,830 --> 00:46:07,100 Who is that? 820 00:46:07,100 --> 00:46:07,600 Ah. 821 00:46:07,600 --> 00:46:08,099 Here. 822 00:46:10,800 --> 00:46:15,720 So that's the power of implicit summation notation. 823 00:46:15,720 --> 00:46:19,740 So we could invoke these different properties. 824 00:46:19,740 --> 00:46:21,500 It was fairly straightforward. 825 00:46:21,500 --> 00:46:22,920 Your first example of this. 826 00:46:22,920 --> 00:46:24,550 You'll probably see a few more. 827 00:46:24,550 --> 00:46:25,560 All right? 828 00:46:25,560 --> 00:46:26,538 Any questions so far? 829 00:46:29,940 --> 00:46:30,950 OK. 830 00:46:30,950 --> 00:46:35,390 So as you can see, as I promised, or threatened 831 00:46:35,390 --> 00:46:38,870 at the beginning, but followed through on my threat, 832 00:46:38,870 --> 00:46:41,030 we have a lot of notation, a lot of baggage 833 00:46:41,030 --> 00:46:43,500 here before we get to algorithms. 834 00:46:43,500 --> 00:46:45,500 But we're slowly getting there. 835 00:46:45,500 --> 00:46:50,070 The next major concept is the concept of cuts. 836 00:46:50,070 --> 00:46:53,440 So a cut, you think of a cut as being, 837 00:46:53,440 --> 00:46:56,950 well, a cut through paper, a cut through the air, whatever. 838 00:46:56,950 --> 00:46:59,860 It turns out that notion of a cut in a network 839 00:46:59,860 --> 00:47:01,770 is more general than that, right? 840 00:47:01,770 --> 00:47:04,220 A cut is basically a partition. 841 00:47:04,220 --> 00:47:06,490 A cut is a partition of nodes. 842 00:47:06,490 --> 00:47:08,700 And a partition means that you can't have 843 00:47:08,700 --> 00:47:10,550 a node in both sides, right? 844 00:47:10,550 --> 00:47:15,470 So a cut is going to give you two disjoint components 845 00:47:15,470 --> 00:47:16,500 at the end of it. 846 00:47:16,500 --> 00:47:18,810 But the cut doesn't have to be something contiguous. 847 00:47:18,810 --> 00:47:21,587 It doesn't have to be a line through the network. 848 00:47:21,587 --> 00:47:23,170 And everything to the left of the line 849 00:47:23,170 --> 00:47:26,380 is in one half of the cut, and everything 850 00:47:26,380 --> 00:47:29,460 on the right of the line is in a different half of the cut. 851 00:47:29,460 --> 00:47:33,980 I can just break up these nodes into two disjoint parts. 852 00:47:33,980 --> 00:47:36,780 And the only constraint that I'm going to ask for 853 00:47:36,780 --> 00:47:43,080 is that s, which is the source, is on one side of the cut, 854 00:47:43,080 --> 00:47:47,110 and t, which is the sink, is another side of the cut, OK? 855 00:47:47,110 --> 00:47:48,640 That's it. 856 00:47:48,640 --> 00:47:53,170 And given that, I'm going to say interesting things, really 857 00:47:53,170 --> 00:47:58,180 interesting things, about the flow through a cut, OK? 858 00:47:58,180 --> 00:47:59,870 And so let's do that. 859 00:47:59,870 --> 00:48:01,005 Let's define a cut. 860 00:48:22,840 --> 00:48:41,850 So a cut is (S,T) of a flow network, G, 861 00:48:41,850 --> 00:48:53,640 is a partition of V, such that small s belongs to cap S, 862 00:48:53,640 --> 00:48:59,820 and small t belongs to cap T. I don't know. 863 00:48:59,820 --> 00:49:01,355 Do you want hats on the T too? 864 00:49:05,890 --> 00:49:08,550 I'll just write them large. 865 00:49:08,550 --> 00:49:23,930 If a flow on G-- if f is a flow on G, 866 00:49:23,930 --> 00:49:31,140 then the flow across the cut is f(S,T). 867 00:49:35,290 --> 00:49:37,440 OK? 868 00:49:37,440 --> 00:49:40,770 So again, implicit summation notation here. 869 00:49:40,770 --> 00:49:46,780 The flow across the cut is as the sum of the flows 870 00:49:46,780 --> 00:49:50,200 corresponding to each pair of vertices, 871 00:49:50,200 --> 00:49:55,360 such that the source vertex is part of capital S. 872 00:49:55,360 --> 00:50:00,570 And the destination vertex is part of capital T. All right? 873 00:50:00,570 --> 00:50:01,550 That's it. 874 00:50:01,550 --> 00:50:03,430 I'm just going to add them all up. 875 00:50:03,430 --> 00:50:04,845 That's the flow across the cut. 876 00:50:09,090 --> 00:50:12,020 So what I can do now is just talk about-- 877 00:50:12,020 --> 00:50:16,460 let's just go up here back to this. 878 00:50:16,460 --> 00:50:23,010 And I'm going to look at exactly what I have here. 879 00:50:23,010 --> 00:50:24,530 Is that right? 880 00:50:24,530 --> 00:50:26,050 Not exactly. 881 00:50:26,050 --> 00:50:28,370 I'm going to change this a little bit, 882 00:50:28,370 --> 00:50:31,920 because I want to make sure I don't 883 00:50:31,920 --> 00:50:37,730 have to add up numbers and do that incorrectly. 884 00:50:37,730 --> 00:50:40,240 So I need a 1. 885 00:50:42,651 --> 00:50:43,150 Yup. 886 00:50:43,150 --> 00:50:48,030 That's all I need to do is change it. 887 00:50:48,030 --> 00:50:49,820 So I'm going to change our example here, 888 00:50:49,820 --> 00:50:55,570 not the topology of the example, but the actual numbers. 889 00:50:55,570 --> 00:51:01,420 And you'll need to verify that what I have here satisfies 890 00:51:01,420 --> 00:51:04,150 our flow network properties. 891 00:51:04,150 --> 00:51:08,033 And there's one more. 892 00:51:13,650 --> 00:51:14,910 OK? 893 00:51:14,910 --> 00:51:16,830 So I think I'm good. 894 00:51:16,830 --> 00:51:17,750 All right. 895 00:51:17,750 --> 00:51:22,990 So this is going to be an example of a cut. 896 00:51:22,990 --> 00:51:24,280 I haven't defined the cut yet. 897 00:51:27,840 --> 00:51:30,510 Let's get rid of that. 898 00:51:30,510 --> 00:51:33,910 Holler if you think there's something wrong with this flow. 899 00:51:33,910 --> 00:51:34,410 All right? 900 00:51:34,410 --> 00:51:35,550 I think I got it right. 901 00:51:35,550 --> 00:51:38,610 It satisfies capacity constraints. 902 00:51:38,610 --> 00:51:41,650 It satisfies flow conservation constraints. 903 00:51:41,650 --> 00:51:44,490 The flow that is going into t is 4. 904 00:51:44,490 --> 00:51:46,180 This happens to be a max flow. 905 00:51:46,180 --> 00:51:47,440 Doesn't really matter. 906 00:51:47,440 --> 00:51:50,970 So what we're going to talk about with respect to cuts, 907 00:51:50,970 --> 00:51:53,730 it doesn't require the flow to be maximum. 908 00:51:53,730 --> 00:51:56,000 Keep that in mind. 909 00:51:56,000 --> 00:52:02,270 What do I mean by the flow across a cut via an example? 910 00:52:02,270 --> 00:52:12,090 I'm going to simply say that the shaded nodes, two of them, 911 00:52:12,090 --> 00:52:14,520 are part of capital S, OK? 912 00:52:27,160 --> 00:52:30,150 So as you can see, I just arbitrarily picked 913 00:52:30,150 --> 00:52:31,560 a couple of nodes. 914 00:52:31,560 --> 00:52:34,880 And that not necessarily something that can be easily 915 00:52:34,880 --> 00:52:38,550 partitioned using an actual cut line, a physical cut line. 916 00:52:38,550 --> 00:52:41,620 I just picked that one over there and the one over here 917 00:52:41,620 --> 00:52:43,050 with S. 918 00:52:43,050 --> 00:52:53,150 And so, I can now look at this, and I can compute numerically, 919 00:52:53,150 --> 00:52:54,020 for this example. 920 00:52:54,020 --> 00:52:57,170 And it's worth doing at least once what 921 00:52:57,170 --> 00:52:59,220 the flow across this particular cut 922 00:52:59,220 --> 00:53:07,430 is, defined by the particular choice of cap S and cap T, OK? 923 00:53:07,430 --> 00:53:10,410 And that's what we're going to do. 924 00:53:10,410 --> 00:53:23,100 So f(S,T) is-- I'm going to have to look at pairs of nodes, 925 00:53:23,100 --> 00:53:27,530 such that I've got a shaded node on the left-hand side 926 00:53:27,530 --> 00:53:29,985 and non-shaded node on the right-hand side. 927 00:53:29,985 --> 00:53:31,610 And I'm going to have to go through all 928 00:53:31,610 --> 00:53:35,090 of the combinations, right? 929 00:53:35,090 --> 00:53:38,540 So if I look at this, I can first 930 00:53:38,540 --> 00:53:42,650 knock off this one, and that one, and that one. 931 00:53:42,650 --> 00:53:50,740 Let me actually put in-- let's call this a, b, and c here. 932 00:53:50,740 --> 00:53:53,680 And we can call that d. 933 00:53:53,680 --> 00:53:56,280 So we have s and d as being part of the cut, 934 00:53:56,280 --> 00:54:01,450 in terms of s, capital S. And the other ones are in cap T. 935 00:54:01,450 --> 00:54:05,330 And so what I have is I could do Sa and Sb. 936 00:54:05,330 --> 00:54:08,170 So I've got 2 plus 2, all right? 937 00:54:08,170 --> 00:54:12,230 And this would correspond to Sa and Sb. 938 00:54:12,230 --> 00:54:14,030 So those are going out, right? 939 00:54:14,030 --> 00:54:15,620 So far, so good. 940 00:54:15,620 --> 00:54:19,170 And then, I'm going to write out a bunch of numbers here, 941 00:54:19,170 --> 00:54:24,260 minus 2 plus 1 minus 1 plus 2. 942 00:54:24,260 --> 00:54:29,640 And the minus 2, where would the minus 2 come from? 943 00:54:29,640 --> 00:54:34,970 Well, an a,d, for example, is a minus 2, right? 944 00:54:34,970 --> 00:54:37,940 Because d is part of-- it would be d, a. 945 00:54:37,940 --> 00:54:43,580 So a, d has a flow of 2, correct? 946 00:54:43,580 --> 00:54:46,560 And so d, a has a flow of minus 2, right? 947 00:54:46,560 --> 00:54:48,280 And d, a is part of what I have here, 948 00:54:48,280 --> 00:54:52,241 because d is part of capital S, and A is part of capital T. 949 00:54:52,241 --> 00:54:52,990 You guys see that? 950 00:54:52,990 --> 00:54:57,670 So this is not trivial, so pay attention. 951 00:54:57,670 --> 00:55:01,270 So this would be, for example, the minus 2 952 00:55:01,270 --> 00:55:07,150 would correspond to d, a. 953 00:55:07,150 --> 00:55:08,470 That's what I need here. 954 00:55:08,470 --> 00:55:12,270 And I could also have-- what do I have here? 955 00:55:12,270 --> 00:55:15,560 I have something is going into d. 956 00:55:15,560 --> 00:55:17,170 So a c, d is 1. 957 00:55:17,170 --> 00:55:19,990 So d, c is minus 1, right? 958 00:55:19,990 --> 00:55:21,410 Make sense? 959 00:55:21,410 --> 00:55:22,900 d, c is minus 1. 960 00:55:22,900 --> 00:55:24,615 What about the plus 1? 961 00:55:24,615 --> 00:55:25,823 Where do I get a plus 1 from? 962 00:55:29,064 --> 00:55:29,990 STUDENT: d, b. 963 00:55:29,990 --> 00:55:32,130 SRINIVAS DEVADAS: d, b is going out. 964 00:55:32,130 --> 00:55:34,530 That's exactly right, d, b. 965 00:55:34,530 --> 00:55:39,120 And the plus 2, it would be d, T, right? 966 00:55:43,470 --> 00:55:46,760 And so you have to do the enumeration. 967 00:55:46,760 --> 00:55:48,520 It's worthwhile doing once. 968 00:55:48,520 --> 00:55:50,160 And then it gets kind of boring. 969 00:55:50,160 --> 00:55:51,300 We won't to do it again. 970 00:55:51,300 --> 00:55:54,930 But you have to realize that you have to absolutely look 971 00:55:54,930 --> 00:55:58,540 at every pair of vertices. 972 00:55:58,540 --> 00:56:01,190 And you have to use skew symmetry 973 00:56:01,190 --> 00:56:04,400 and ensure that, even though there's actually 974 00:56:04,400 --> 00:56:06,729 no edge going out, if there's an edge coming in, 975 00:56:06,729 --> 00:56:07,770 you've got to count that. 976 00:56:07,770 --> 00:56:09,840 And that's going to get a negative. 977 00:56:09,840 --> 00:56:12,212 Whatever is coming in, you've got to subtract, OK? 978 00:56:12,212 --> 00:56:13,420 So it's not that complicated. 979 00:56:13,420 --> 00:56:14,400 Yeah, go ahead. 980 00:56:14,400 --> 00:56:15,797 STUDENT: Do we not consider S, c? 981 00:56:15,797 --> 00:56:16,963 SRINIVAS DEVADAS: I'm sorry? 982 00:56:16,963 --> 00:56:19,220 STUDENT: Do we not consider S, c? 983 00:56:19,220 --> 00:56:23,110 SRINIVAS DEVADAS: So the beauty of this 984 00:56:23,110 --> 00:56:28,760 is that, when you don't have a particular edge from S to c, 985 00:56:28,760 --> 00:56:32,420 you can use skew symmetry to argue that S, c and c, 986 00:56:32,420 --> 00:56:35,300 S cancel out each other, all right? 987 00:56:35,300 --> 00:56:36,680 So that's the good part, right? 988 00:56:36,680 --> 00:56:38,360 And thanks for asking the question. 989 00:56:38,360 --> 00:56:39,730 That's a good question. 990 00:56:39,730 --> 00:56:40,230 All right. 991 00:56:40,230 --> 00:56:40,729 Here you go. 992 00:56:43,860 --> 00:56:47,950 So you can do that by just looking at the edges. 993 00:56:47,950 --> 00:56:50,940 And you can add up the numbers, all right? 994 00:56:50,940 --> 00:56:53,970 And so I don't think this is going 995 00:56:53,970 --> 00:56:56,930 to be absolutely crucial to understand 996 00:56:56,930 --> 00:56:59,220 the rest of the lecture. 997 00:56:59,220 --> 00:57:02,630 Keep this in mind, that there's a process by which you 998 00:57:02,630 --> 00:57:07,310 define the value of a cut. 999 00:57:07,310 --> 00:57:09,490 And we're going to get back to this, 1000 00:57:09,490 --> 00:57:12,470 when we prove the max-flow min-cut theorem next time. 1001 00:57:12,470 --> 00:57:14,680 But at this point, I want to say something actually 1002 00:57:14,680 --> 00:57:17,710 much more straightforward, which is going to be important 1003 00:57:17,710 --> 00:57:22,100 when we look at residual networks, which 1004 00:57:22,100 --> 00:57:25,790 is the last concept that we need to get at before we 1005 00:57:25,790 --> 00:57:27,090 get to an algorithm. 1006 00:57:27,090 --> 00:57:35,580 And that is simply that the capacity of a cut 1007 00:57:35,580 --> 00:57:38,760 and the relationship between the capacity of the cut 1008 00:57:38,760 --> 00:57:42,650 and the flow of a cut. 1009 00:57:42,650 --> 00:57:44,640 So the capacity of a cut is c(S,T). 1010 00:57:49,190 --> 00:57:49,690 Oops. 1011 00:57:49,690 --> 00:57:52,140 I didn't draw that properly. 1012 00:57:52,140 --> 00:57:55,190 Open brackets, capital S, capital T. 1013 00:57:55,190 --> 00:57:57,480 And we can do it exactly the same way, except this 1014 00:57:57,480 --> 00:58:03,150 is a lot simpler, because you only look at edges 1015 00:58:03,150 --> 00:58:05,550 and you only have positive quantities. 1016 00:58:05,550 --> 00:58:07,490 So in this case, you'll simply say 1017 00:58:07,490 --> 00:58:12,670 it's 3 plus 2, corresponding to-- what did I have here? 1018 00:58:12,670 --> 00:58:18,310 I had d, a-- S, a and S, d. 1019 00:58:18,310 --> 00:58:23,580 And then, the capacity is you only 1020 00:58:23,580 --> 00:58:27,610 need to look at the edges that go from a node in S 1021 00:58:27,610 --> 00:58:34,900 to a node in capital T. And so those are 1 plus 3. 1022 00:58:34,900 --> 00:58:41,190 And this simply would be the 1 would be d, b. 1023 00:58:41,190 --> 00:58:46,490 And the 3 is d, t. 1024 00:58:46,490 --> 00:58:49,190 So you don't care about the other flows. 1025 00:58:49,190 --> 00:58:51,800 This is not about flows, this is simply about capacity. 1026 00:58:51,800 --> 00:58:58,820 So this adds up to 9, OK? 1027 00:58:58,820 --> 00:59:05,840 And so we have, at this point, we have 1028 00:59:05,840 --> 00:59:08,480 defined the flow through a cut. 1029 00:59:08,480 --> 00:59:12,440 And we know the capacity of a cut, OK? 1030 00:59:12,440 --> 00:59:17,730 It's more or less obvious-- though you could certainly 1031 00:59:17,730 --> 00:59:20,930 prove a theorem which is going to take a couple of lines-- 1032 00:59:20,930 --> 00:59:35,430 to say that the value of any flow 1033 00:59:35,430 --> 00:59:46,580 is bounded by the capacity of any cut. 1034 00:59:46,580 --> 00:59:48,410 And sorry, I lied. 1035 00:59:48,410 --> 00:59:52,710 It's not a trivial proof. 1036 00:59:52,710 --> 00:59:55,380 And that is actually something profound going on here. 1037 00:59:55,380 --> 01:00:00,150 And so I'll have to explain exactly what this means. 1038 01:00:00,150 --> 01:00:03,820 And then we'll take a look at how we could prove something 1039 01:00:03,820 --> 01:00:04,970 like this. 1040 01:00:04,970 --> 01:00:09,070 So what's cool about this is that you're 1041 01:00:09,070 --> 01:00:12,600 saying that it's the value of any flow is 1042 01:00:12,600 --> 01:00:17,740 bounded by the capacity of any cut, OK? 1043 01:00:17,740 --> 01:00:22,460 And so that's an upper-bound on the maximum flow value, right? 1044 01:00:22,460 --> 01:00:24,880 So I'm saying there's all these cuts that 1045 01:00:24,880 --> 01:00:27,090 are possible in the network. 1046 01:00:27,090 --> 01:00:33,100 And I'm making a statement about what the maximum flow can 1047 01:00:33,100 --> 01:00:39,510 be, based on the values corresponding to the capacities 1048 01:00:39,510 --> 01:00:41,940 of any cut, right? 1049 01:00:41,940 --> 01:00:44,800 So why is that the case? 1050 01:00:44,800 --> 01:00:50,490 Well, we're not going to be able to prove that fully today. 1051 01:00:50,490 --> 01:00:52,530 That's the max-flow min-cut theorem. 1052 01:00:52,530 --> 01:00:55,620 But you can certainly get a sense of it, 1053 01:00:55,620 --> 01:01:00,860 by looking at a different characterization of the flow 1054 01:01:00,860 --> 01:01:01,390 value. 1055 01:01:01,390 --> 01:01:05,030 So I'm going to give you one half of the proof, at least, 1056 01:01:05,030 --> 01:01:07,470 and intuition about the other half. 1057 01:01:07,470 --> 01:01:09,740 And we'll finish it next time. 1058 01:01:12,540 --> 01:01:23,928 But here's another characterization 1059 01:01:23,928 --> 01:01:25,092 of the flow value. 1060 01:01:29,080 --> 01:01:30,680 So our lemma here, which is going 1061 01:01:30,680 --> 01:01:41,680 to lead us to this statement, is that, for any flow, f, 1062 01:01:41,680 --> 01:02:00,150 and any cut, (S, T), we have a really powerful dilemma. 1063 01:02:00,150 --> 01:02:01,930 Maybe you should call it a theorem. 1064 01:02:01,930 --> 01:02:04,520 But it essentially says, look, it 1065 01:02:04,520 --> 01:02:07,520 doesn't matter what cut you choose, 1066 01:02:07,520 --> 01:02:10,090 you've got a flow on the network. 1067 01:02:10,090 --> 01:02:14,240 And when you look at the flow on the network, 1068 01:02:14,240 --> 01:02:17,247 it's going to equal the flow across the cut. 1069 01:02:17,247 --> 01:02:18,830 And the only reason for this is simply 1070 01:02:18,830 --> 01:02:22,510 because you've got the source on one side of the cut. 1071 01:02:22,510 --> 01:02:25,030 And you've got the sink on the other side of the cut. 1072 01:02:25,030 --> 01:02:26,040 That's it. 1073 01:02:26,040 --> 01:02:28,140 That's the only thing that you need, right? 1074 01:02:28,140 --> 01:02:31,050 You dump these vertices these into two bins. 1075 01:02:31,050 --> 01:02:32,780 You know, dump the source on the left, 1076 01:02:32,780 --> 01:02:35,550 and dump the sink on the right. 1077 01:02:35,550 --> 01:02:38,000 And you compute the flow the way we've defined it. 1078 01:02:38,000 --> 01:02:39,080 That's the flow. 1079 01:02:39,080 --> 01:02:42,310 It doesn't matter how you partition these vertices, 1080 01:02:42,310 --> 01:02:44,960 as long as you've got the source on the left and the sink 1081 01:02:44,960 --> 01:02:46,830 on the right, OK? 1082 01:02:46,830 --> 01:02:50,180 And so we can prove this using implicit summation notation. 1083 01:02:53,310 --> 01:02:55,660 We'll do that. 1084 01:02:55,660 --> 01:02:59,470 And that'll give you a really good sense of why 1085 01:02:59,470 --> 01:03:01,820 this statement is true, because we 1086 01:03:01,820 --> 01:03:07,170 know that, for any given cut, the flow that cut 1087 01:03:07,170 --> 01:03:10,120 is bounded by the capacity of that cut, right? 1088 01:03:10,120 --> 01:03:11,730 You know that. 1089 01:03:11,730 --> 01:03:17,150 But to show this, here's how we could show that, f(S, 1090 01:03:17,150 --> 01:03:30,170 T) is f(S, V) minus f(S, S), OK? 1091 01:03:30,170 --> 01:03:33,690 So I'm playing around, just like I did before. 1092 01:03:33,690 --> 01:03:39,480 I had taken the cap T-- I know that S union T is cap V, right? 1093 01:03:39,480 --> 01:03:40,590 This is a partition. 1094 01:03:40,590 --> 01:03:42,540 So I know that S union T is cap V. 1095 01:03:42,540 --> 01:03:45,380 So I can put a V here and an S here, right? 1096 01:03:45,380 --> 01:03:47,790 And that's a subtraction over there, of course, right? 1097 01:03:47,790 --> 01:03:53,910 So put that up here and finish this, a couple more lines. 1098 01:04:01,760 --> 01:04:06,260 And what can I say about either of these? 1099 01:04:06,260 --> 01:04:09,471 I could say something about one of these terms. 1100 01:04:09,471 --> 01:04:09,970 Yep? 1101 01:04:09,970 --> 01:04:11,845 STUDENT: The one on the right is [INAUDIBLE]. 1102 01:04:11,845 --> 01:04:13,760 SRINIVAS DEVADAS: The one on the right is 0. 1103 01:04:13,760 --> 01:04:16,040 So call this f(S,V). 1104 01:04:19,521 --> 01:04:20,020 Right? 1105 01:04:20,020 --> 01:04:25,440 And now, I'm going to break it up again, make it small s, 1106 01:04:25,440 --> 01:04:33,730 big V, plus f(S minus s, cap V). 1107 01:04:33,730 --> 01:04:37,400 So broken this up into small s, which is just 1108 01:04:37,400 --> 01:04:40,436 joined from cap S minus s, clearly. 1109 01:04:42,960 --> 01:04:46,930 And what can I say about this? 1110 01:04:46,930 --> 01:04:53,500 This is a little more subtle than, perhaps, 1111 01:04:53,500 --> 01:04:55,200 the previous question. 1112 01:04:55,200 --> 01:04:56,820 What can I say about that quantity? 1113 01:04:56,820 --> 01:05:00,285 I mean, the answer is not subtle, but-- yeah, go ahead. 1114 01:05:00,285 --> 01:05:01,660 STUDENT: That that is equal to 0. 1115 01:05:01,660 --> 01:05:02,850 SRINIVAS DEVADAS: And why? 1116 01:05:02,850 --> 01:05:06,175 STUDENT: Because the cap S doesn't contain t. 1117 01:05:06,175 --> 01:05:07,050 SRINIVAS DEVADAS: Ah. 1118 01:05:07,050 --> 01:05:07,550 Beautiful. 1119 01:05:07,550 --> 01:05:08,200 That's right. 1120 01:05:08,200 --> 01:05:09,310 So that's what I wanted. 1121 01:05:09,310 --> 01:05:11,063 So this does not contain t. 1122 01:05:15,030 --> 01:05:17,650 And so, now you can use flow conservation, right? 1123 01:05:17,650 --> 01:05:19,750 And that's the important thing. 1124 01:05:19,750 --> 01:05:24,000 You can use flow conservation, because this does not 1125 01:05:24,000 --> 01:05:25,110 contain t. 1126 01:05:25,110 --> 01:05:28,010 And then, it clearly does not contain small s, because I just 1127 01:05:28,010 --> 01:05:30,180 took it out of it, right? 1128 01:05:30,180 --> 01:05:31,780 So that goes to 0. 1129 01:05:31,780 --> 01:05:33,460 And voila. 1130 01:05:33,460 --> 01:05:40,560 That's simply f(S, V), which we know is f. 1131 01:05:40,560 --> 01:05:43,300 We proved that. 1132 01:05:43,300 --> 01:05:44,960 Our first implicit summation proof 1133 01:05:44,960 --> 01:05:48,640 was showing that-- well, this is a definition. 1134 01:05:48,640 --> 01:05:49,380 Excuse me. 1135 01:05:49,380 --> 01:05:54,460 So we did it for the sink. 1136 01:05:54,460 --> 01:05:58,250 But this is simply the definition of the flow value, 1137 01:05:58,250 --> 01:05:58,750 right? 1138 01:05:58,750 --> 01:06:00,520 So this is beautiful. 1139 01:06:00,520 --> 01:06:04,510 I mean, it's like fantastic, right? 1140 01:06:04,510 --> 01:06:06,140 Why aren't people excited? 1141 01:06:06,140 --> 01:06:07,520 [LAUGHTER] 1142 01:06:07,520 --> 01:06:10,810 Because I put people to sleep before, in the hour before. 1143 01:06:10,810 --> 01:06:12,670 But this is absolutely fantastic, 1144 01:06:12,670 --> 01:06:19,410 because this says that I have ways of figuring out 1145 01:06:19,410 --> 01:06:24,630 what the maximum flow of the network would be, 1146 01:06:24,630 --> 01:06:28,480 by making arbitrary cuts through this network 1147 01:06:28,480 --> 01:06:31,690 and looking for capacities of these cuts, right? 1148 01:06:31,690 --> 01:06:35,950 Because I know that the capacity of any cut-- and now 1149 01:06:35,950 --> 01:06:38,110 you see why min cut is interesting-- 1150 01:06:38,110 --> 01:06:40,580 but you know that the capacity of any cut 1151 01:06:40,580 --> 01:06:43,580 is going to bound the flow of the network, 1152 01:06:43,580 --> 01:06:45,130 because the flow through a cut is 1153 01:06:45,130 --> 01:06:46,710 the flow through the network. 1154 01:06:46,710 --> 01:06:50,850 So if I go through and look at the min cut corresponding 1155 01:06:50,850 --> 01:06:53,780 to the minimum capacity associated with the flow 1156 01:06:53,780 --> 01:06:56,900 network, that's going to point me to my max flow, 1157 01:06:56,900 --> 01:06:59,690 because that going to be an upper bound on the max 1158 01:06:59,690 --> 01:07:00,670 flow, right? 1159 01:07:00,670 --> 01:07:03,690 And so now you see why the min-- not the min flow, 1160 01:07:03,690 --> 01:07:08,590 sorry-- the min-cut max-flow theorem is an interesting one. 1161 01:07:08,590 --> 01:07:13,680 But it relates-- and this is the beginning of that relationship, 1162 01:07:13,680 --> 01:07:15,780 we're not quite done to prove it-- 1163 01:07:15,780 --> 01:07:17,420 but the beginning of the relationship 1164 01:07:17,420 --> 01:07:23,370 is that you can look at any cut, and you can look at the flow 1165 01:07:23,370 --> 01:07:25,730 through the cut as being the flow through the network. 1166 01:07:25,730 --> 01:07:27,355 And then you use the second part of it, 1167 01:07:27,355 --> 01:07:29,830 which is the capacity bounding-- of course, in a very 1168 01:07:29,830 --> 01:07:32,820 simple way, because of edge capacities-- the flow 1169 01:07:32,820 --> 01:07:33,780 through the cut. 1170 01:07:33,780 --> 01:07:36,790 And you can put those two things together, all right? 1171 01:07:36,790 --> 01:07:41,240 We still don't quite know how to find these cuts, right? 1172 01:07:41,240 --> 01:07:43,250 So we don't quite know how to find these cuts. 1173 01:07:43,250 --> 01:07:45,210 And that's the last thing that we're 1174 01:07:45,210 --> 01:07:47,010 going to do today, give you a sense of how 1175 01:07:47,010 --> 01:07:48,900 we're going to find these min cuts, 1176 01:07:48,900 --> 01:07:50,780 so we can find the max flow. 1177 01:07:50,780 --> 01:07:53,060 All right? 1178 01:07:53,060 --> 01:07:54,270 Cool. 1179 01:07:54,270 --> 01:07:59,060 So the one last notion that we have 1180 01:07:59,060 --> 01:08:01,780 here that is going to allow us to go into the algorithm 1181 01:08:01,780 --> 01:08:05,350 domain, as opposed to the analysis domain-- all we've 1182 01:08:05,350 --> 01:08:08,550 done so far is analysis, analysis, analysis-- 1183 01:08:08,550 --> 01:08:12,250 is the notion of a residual network. 1184 01:08:12,250 --> 01:08:13,330 OK? 1185 01:08:13,330 --> 01:08:16,390 And a residual network, as its name implies, 1186 01:08:16,390 --> 01:08:19,850 is something that has residual capacities. 1187 01:08:19,850 --> 01:08:22,550 It's the network that points you to places 1188 01:08:22,550 --> 01:08:27,029 where you can increase the flow, because there's capacity left. 1189 01:08:27,029 --> 01:08:29,439 Your flow is less than the edge capacity. 1190 01:08:29,439 --> 01:08:32,990 It's a local notion, so it's easy to compute. 1191 01:08:32,990 --> 01:08:36,010 There's a capacity of 3 on this edge, there's a flow of 2. 1192 01:08:36,010 --> 01:08:38,300 The residual capacity is 1, right? 1193 01:08:38,300 --> 01:08:40,020 3 minus 2. 1194 01:08:40,020 --> 01:08:55,370 And so the residual network Gf (V, Ef), right? 1195 01:08:55,370 --> 01:08:57,891 So the actual network is G(V, E). 1196 01:08:57,891 --> 01:08:59,640 And the vertices are going to be the same. 1197 01:08:59,640 --> 01:09:01,170 The graph is obviously different, 1198 01:09:01,170 --> 01:09:02,836 but the edges are going to be different. 1199 01:09:02,836 --> 01:09:05,430 There's going to be a different set of edges 1200 01:09:05,430 --> 01:09:08,870 in the residual network, as opposed to the flow network, 1201 01:09:08,870 --> 01:09:10,430 OK? 1202 01:09:10,430 --> 01:09:17,920 And you have strictly positive. 1203 01:09:17,920 --> 01:09:21,140 That means greater than 0, strictly greater 1204 01:09:21,140 --> 01:09:23,609 than 0, residual capacities. 1205 01:09:30,399 --> 01:09:39,840 So Cf ) equals c(u,v) minus f(u,v). 1206 01:09:39,840 --> 01:09:41,380 And that's strictly greater than 0. 1207 01:09:41,380 --> 01:09:43,740 I'm going to put an edge in there, if there 1208 01:09:43,740 --> 01:09:45,819 is a residual capacity. 1209 01:09:45,819 --> 01:09:49,420 0 doesn't mean there's any residual capacity. 1210 01:09:49,420 --> 01:10:00,144 Edges in Ef admit more flow, OK? 1211 01:10:02,960 --> 01:10:06,820 And one last thing. 1212 01:10:06,820 --> 01:10:13,550 If (V, u) does not belong to E-- so we are talking about 1213 01:10:13,550 --> 01:10:17,270 the original network here, E means the original network-- 1214 01:10:17,270 --> 01:10:22,790 then we know c(V, u) equals 0. 1215 01:10:22,790 --> 01:10:24,070 That was our definition. 1216 01:10:24,070 --> 01:10:27,490 If you don't have that edge, the capacity is 0. 1217 01:10:27,490 --> 01:10:32,680 But we are talking now about f, which 1218 01:10:32,680 --> 01:10:34,540 is a flow, which doesn't necessarily 1219 01:10:34,540 --> 01:10:37,980 require that there be an edge. 1220 01:10:37,980 --> 01:10:43,740 And we are simply going to use our skew symmetry relationship. 1221 01:10:43,740 --> 01:10:47,290 And you'll see that this may not be completely clear as to why 1222 01:10:47,290 --> 01:10:49,250 I wrote this at this moment. 1223 01:10:49,250 --> 01:10:51,180 But as I draw the residual network, 1224 01:10:51,180 --> 01:10:53,210 you'll see why that is important. 1225 01:10:53,210 --> 01:10:54,710 It's going to be the case that we're 1226 01:10:54,710 --> 01:10:59,200 going to have extra edges in the residual network that 1227 01:10:59,200 --> 01:11:02,430 don't exist in the original network, 1228 01:11:02,430 --> 01:11:05,130 because of that last line there, right? 1229 01:11:05,130 --> 01:11:06,980 So let me clear that up. 1230 01:11:06,980 --> 01:11:11,600 So we're going to draw a residual network 1231 01:11:11,600 --> 01:11:15,470 for-- I'm going to change that yet again-- 1232 01:11:15,470 --> 01:11:18,660 but we're going to draw the residual network 1233 01:11:18,660 --> 01:11:22,870 for our example up there. 1234 01:11:22,870 --> 01:11:24,760 Topology is going to stay the same. 1235 01:11:24,760 --> 01:11:26,530 Numbers are going to change, because I 1236 01:11:26,530 --> 01:11:30,340 want something slightly more interesting than what 1237 01:11:30,340 --> 01:11:32,800 we have there. 1238 01:11:32,800 --> 01:11:40,940 So I'm going to take this out-- 2, 1. 1239 01:11:40,940 --> 01:11:46,630 1, 2-- go back to what it was before, I think. 1240 01:11:46,630 --> 01:11:50,983 1-- all right. 1241 01:11:50,983 --> 01:11:51,730 Good. 1242 01:11:51,730 --> 01:11:55,610 So I want a 1 over here. 1243 01:11:55,610 --> 01:12:02,260 I want a 1 over here, a 2 over here. 1244 01:12:02,260 --> 01:12:07,720 And keep checking to make sure I'm not messing up here, 1245 01:12:07,720 --> 01:12:09,800 in terms of flow constraints. 1246 01:12:09,800 --> 01:12:12,284 But that's pretty much all I got. 1247 01:12:15,560 --> 01:12:16,850 OK? 1248 01:12:16,850 --> 01:12:22,530 So the flow here and the s and t don't particularly matter. 1249 01:12:22,530 --> 01:12:24,090 The max flow is 4. 1250 01:12:24,090 --> 01:12:26,560 The flow that you see up there is 3. 1251 01:12:26,560 --> 01:12:29,570 This is what we had right at the beginning, all right? 1252 01:12:29,570 --> 01:12:32,110 So what I want to do now is give you 1253 01:12:32,110 --> 01:12:35,840 what the residual network is for this particular flow. 1254 01:12:35,840 --> 01:12:39,820 Remember, the residual network is defined, based on a flow. 1255 01:12:39,820 --> 01:12:43,050 That's why you have Gf, G subscript f. 1256 01:12:43,050 --> 01:12:43,682 f is a flow. 1257 01:12:43,682 --> 01:12:45,890 So you're going to have a different residual network, 1258 01:12:45,890 --> 01:12:47,090 if the flow is different. 1259 01:12:47,090 --> 01:12:48,834 So that original example that I had 1260 01:12:48,834 --> 01:12:50,500 would have a different residual network. 1261 01:12:50,500 --> 01:12:52,666 This one is going to have the one I'm going to draw, 1262 01:12:52,666 --> 01:12:53,650 all right? 1263 01:12:53,650 --> 01:12:57,490 So the residual network has the same set of vertices. 1264 01:12:57,490 --> 01:13:01,080 So I can go ahead and draw these vertices. 1265 01:13:05,690 --> 01:13:08,200 I'll just mark T and S over here. 1266 01:13:08,200 --> 01:13:10,250 Those are exactly the same as before. 1267 01:13:10,250 --> 01:13:12,920 And this is Gf, OK? 1268 01:13:12,920 --> 01:13:14,400 That's a residual network. 1269 01:13:14,400 --> 01:13:16,140 And the edges are going to be different. 1270 01:13:16,140 --> 01:13:19,100 All I have to do is look up there and say, 1271 01:13:19,100 --> 01:13:22,850 look, I'm going to have a residual capacity of 2-- 1272 01:13:22,850 --> 01:13:27,920 let me use a different color, since I have them-- 1273 01:13:27,920 --> 01:13:30,520 corresponding to that edge from S to a, 1274 01:13:30,520 --> 01:13:33,340 because I clearly have a capacity of 3, 1275 01:13:33,340 --> 01:13:35,300 and I only have a flow of 1, right? 1276 01:13:35,300 --> 01:13:37,080 So that's all there is to it. 1277 01:13:37,080 --> 01:13:40,980 Now, the interesting thing is that, because of this line 1278 01:13:40,980 --> 01:13:49,560 over here, I'm actually going to define an edge in Ef, in Gf 1279 01:13:49,560 --> 01:13:54,300 or Ef, that corresponds to this edge that didn't exist in E, 1280 01:13:54,300 --> 01:13:58,470 because I can shrink the flow from 1 to 0. 1281 01:13:58,470 --> 01:14:03,190 And that essentially says that that shrinkage is represented 1282 01:14:03,190 --> 01:14:05,430 in the residual network by an edge that 1283 01:14:05,430 --> 01:14:09,880 goes from this node, a, up there, to s, right? 1284 01:14:09,880 --> 01:14:16,280 And that is going to have a residual capacity of 1, right? 1285 01:14:16,280 --> 01:14:17,190 So that's it. 1286 01:14:17,190 --> 01:14:19,450 That's the only extra thing that you 1287 01:14:19,450 --> 01:14:22,960 have to remember when you draw the residual network. 1288 01:14:22,960 --> 01:14:27,550 You not only can increase the flow, you can also shrink it. 1289 01:14:27,550 --> 01:14:30,080 You have to represent the shrinkage of the flow 1290 01:14:30,080 --> 01:14:32,230 by an edge in the residual network. 1291 01:14:32,230 --> 01:14:34,740 And you obviously represent the increase of the flow 1292 01:14:34,740 --> 01:14:36,434 by an edge in the residual network. 1293 01:14:36,434 --> 01:14:38,600 And now you see why this is all going to make sense. 1294 01:14:38,600 --> 01:14:43,180 Remember, way back, eons ago, only an hour ago, 1295 01:14:43,180 --> 01:14:47,650 but we had this example where we had 1296 01:14:47,650 --> 01:14:51,020 to shrink the flow in a particular edge, 1297 01:14:51,020 --> 01:14:54,460 in order to get the overall flow to increase, right? 1298 01:14:54,460 --> 01:14:56,680 The residual network is going to point us 1299 01:14:56,680 --> 01:15:01,200 in the direction of, potentially, those edges whose 1300 01:15:01,200 --> 01:15:02,590 flow has to shrink. 1301 01:15:02,590 --> 01:15:06,100 But they're going to be represented, in effect, 1302 01:15:06,100 --> 01:15:09,360 as these reverse edges with positive numbers associated 1303 01:15:09,360 --> 01:15:09,860 with them. 1304 01:15:09,860 --> 01:15:11,140 So there's a 1 here. 1305 01:15:11,140 --> 01:15:13,610 It's positive, because it goes from this node, 1306 01:15:13,610 --> 01:15:15,530 call it a, back to s. 1307 01:15:15,530 --> 01:15:21,370 And if I shrink this from 1 to 0, 1308 01:15:21,370 --> 01:15:24,970 that is, in effect, taking what I have up here 1309 01:15:24,970 --> 01:15:27,177 and making this 1 as 0, OK? 1310 01:15:27,177 --> 01:15:29,010 That's the way you want to think about this. 1311 01:15:29,010 --> 01:15:31,410 So that's pretty much it. 1312 01:15:31,410 --> 01:15:33,110 I could draw out the rest of this, 1313 01:15:33,110 --> 01:15:36,360 and it should all make sense. 1314 01:15:36,360 --> 01:15:37,600 I have an edge like that. 1315 01:15:41,980 --> 01:15:48,620 So the edges that are at capacity up there 1316 01:15:48,620 --> 01:15:50,510 aren't going to show up here. 1317 01:15:50,510 --> 01:15:53,090 The edges that are not at capacity end up with two edges 1318 01:15:53,090 --> 01:15:57,690 down below, if they have a flow that is non-zero, right? 1319 01:15:57,690 --> 01:16:00,335 If you have a 0 flow up there, you're 1320 01:16:00,335 --> 01:16:01,460 only going to get one edge. 1321 01:16:03,459 --> 01:16:05,750 Obviously, you'll get one edge, because the capacity is 1322 01:16:05,750 --> 01:16:06,700 non-zero. 1323 01:16:06,700 --> 01:16:09,380 But the ones that are not quite at capacity end 1324 01:16:09,380 --> 01:16:10,740 up to two edges, right? 1325 01:16:10,740 --> 01:16:13,030 Think of that as being the simple rule. 1326 01:16:13,030 --> 01:16:15,220 And make sure that I'm following this rule. 1327 01:16:15,220 --> 01:16:19,952 Good exercise is to check for bugs, lecture bugs. 1328 01:16:19,952 --> 01:16:21,576 Best way of understanding the material. 1329 01:16:35,421 --> 01:16:35,920 OK? 1330 01:16:35,920 --> 01:16:39,350 So that's my residual network. 1331 01:16:39,350 --> 01:16:43,060 And let me just point-- I'll put in some numbers. 1332 01:16:43,060 --> 01:16:45,850 Or maybe you can tell me what some of these numbers are. 1333 01:16:45,850 --> 01:16:46,750 What is this number? 1334 01:16:46,750 --> 01:16:47,590 STUDENT: 2. 1335 01:16:47,590 --> 01:16:49,200 SRINIVAS DEVADAS: 2. 1336 01:16:49,200 --> 01:16:49,700 Right? 1337 01:16:49,700 --> 01:16:51,620 Now, this is a little more tricky. 1338 01:16:51,620 --> 01:16:53,774 Take a look at the number that goes up, 1339 01:16:53,774 --> 01:16:55,190 versus the number that comes down. 1340 01:16:55,190 --> 01:16:56,160 What is this number? 1341 01:16:56,160 --> 01:16:56,680 Goes up. 1342 01:16:56,680 --> 01:16:57,980 STUDENTS: 2. 1343 01:16:57,980 --> 01:17:00,390 SRINIVAS DEVADAS: That's 2, because I can go from 1 to 3. 1344 01:17:00,390 --> 01:17:01,431 And this number would be? 1345 01:17:01,431 --> 01:17:02,150 STUDENTS: 1. 1346 01:17:02,150 --> 01:17:03,316 SRINIVAS DEVADAS: Beautiful. 1347 01:17:03,316 --> 01:17:04,740 All right, you guys got it. 1348 01:17:04,740 --> 01:17:05,543 Did my job. 1349 01:17:16,980 --> 01:17:19,060 All right, so that's our residual network 1350 01:17:19,060 --> 01:17:21,460 for this particular flow. 1351 01:17:21,460 --> 01:17:24,430 So a mechanical way of computing it. 1352 01:17:24,430 --> 01:17:27,690 And you should be able to do that. 1353 01:17:27,690 --> 01:17:33,780 Now what exactly can we do with this residual network? 1354 01:17:33,780 --> 01:17:36,780 It turns out that the algorithm now 1355 01:17:36,780 --> 01:17:41,280 can be described in a couple of sentences, right? 1356 01:17:41,280 --> 01:17:43,042 Essentially our Ford-Fulkerson algorithm-- 1357 01:17:43,042 --> 01:17:44,750 I'm not going to bother writing this out, 1358 01:17:44,750 --> 01:17:46,230 because I'm going to have to prove 1359 01:17:46,230 --> 01:17:48,300 the max-flow min-cut theorem next time. 1360 01:17:48,300 --> 01:17:50,770 And we're going to talk about the Ford-Fulkerson algorithm 1361 01:17:50,770 --> 01:17:52,614 and issues with it next time. 1362 01:17:52,614 --> 01:17:55,030 But I'm going to show you how the Ford-Fulkerson algorithm 1363 01:17:55,030 --> 01:17:57,240 works on this particular example. 1364 01:17:57,240 --> 01:17:59,590 And it's only going to have one step, all right? 1365 01:17:59,590 --> 01:18:01,560 So it's going to converge in one step. 1366 01:18:01,560 --> 01:18:03,570 So it's going to be relatively easy. 1367 01:18:03,570 --> 01:18:07,670 But the bottom line is the the Ford-Fulkerson algorithm 1368 01:18:07,670 --> 01:18:18,050 is going to look for augmenting paths in Gf. 1369 01:18:18,050 --> 01:18:22,940 Augmenting paths are defined in the residual network. 1370 01:18:22,940 --> 01:18:25,290 What is an augmenting path, you ask? 1371 01:18:25,290 --> 01:18:31,724 Well, an augmenting path is simply a path from s in Gf 1372 01:18:31,724 --> 01:18:34,810 to t in Gf, OK? 1373 01:18:34,810 --> 01:18:36,107 That's it. 1374 01:18:36,107 --> 01:18:37,190 That's all there is to it. 1375 01:18:37,190 --> 01:18:40,250 If you can find a path, you could use depth-first search, 1376 01:18:40,250 --> 01:18:41,920 you could use breadth-first search, 1377 01:18:41,920 --> 01:18:43,510 you could use whatever you wanted. 1378 01:18:43,510 --> 01:18:48,150 You find a path from s to t, OK? 1379 01:18:48,150 --> 01:18:52,270 If you find such a path, if this path exists, 1380 01:18:52,270 --> 01:18:57,140 it means that the flow is not maximum, OK? 1381 01:18:57,140 --> 01:19:01,870 If no path exists, the flow is maximum, and you're done. 1382 01:19:01,870 --> 01:19:04,910 If such a path exists, you will be 1383 01:19:04,910 --> 01:19:07,470 able to increase the flow, in this case, because we 1384 01:19:07,470 --> 01:19:11,180 have integral quantities, by at least one, OK? 1385 01:19:11,180 --> 01:19:13,600 And you will be able to increase the flow by one. 1386 01:19:13,600 --> 01:19:16,080 And not only that, the augmenting path 1387 01:19:16,080 --> 01:19:20,470 is going to tell you exactly what to do with respect to what 1388 01:19:20,470 --> 01:19:23,850 edges to change, sometimes subtract 1389 01:19:23,850 --> 01:19:26,585 the flow from, sometimes increase, right? 1390 01:19:26,585 --> 01:19:28,710 So the augmenting path is going to take care of it. 1391 01:19:28,710 --> 01:19:30,992 But you've flipped it, so everything is positive. 1392 01:19:30,992 --> 01:19:32,650 You know, life is great. 1393 01:19:32,650 --> 01:19:34,090 Positive numbers. 1394 01:19:34,090 --> 01:19:39,570 Just look at s to t and give me any path from s 1395 01:19:39,570 --> 01:19:45,160 to t here in the residual network. 1396 01:19:45,160 --> 01:19:53,030 So let me just call them a, b, d, and c. 1397 01:19:53,030 --> 01:19:54,780 And we don't care about partitions or cuts 1398 01:19:54,780 --> 01:19:55,640 at this point. 1399 01:19:55,640 --> 01:19:57,410 That's required for proofs. 1400 01:19:57,410 --> 01:20:02,452 But give me a path from s to t Yeah, go ahead. 1401 01:20:02,452 --> 01:20:04,320 STUDENT: S to a, a to b-- 1402 01:20:04,320 --> 01:20:05,910 All right a little bit more slowly. 1403 01:20:05,910 --> 01:20:09,060 s a, OK. 1404 01:20:09,060 --> 01:20:09,654 And then? 1405 01:20:09,654 --> 01:20:10,320 STUDENT: a to b. 1406 01:20:10,320 --> 01:20:11,880 SRINIVAS DEVADAS: a to b. 1407 01:20:11,880 --> 01:20:12,932 Beautiful. 1408 01:20:12,932 --> 01:20:14,170 STUDENT: b to c. 1409 01:20:14,170 --> 01:20:15,493 SRINIVAS DEVADAS: b to c. 1410 01:20:15,493 --> 01:20:16,582 STUDENT: c to t. 1411 01:20:16,582 --> 01:20:17,790 SRINIVAS DEVADAS: And c to t. 1412 01:20:17,790 --> 01:20:18,900 Wonderful. 1413 01:20:18,900 --> 01:20:26,520 And I have a capacity, a residual capacity, of 2 here. 1414 01:20:26,520 --> 01:20:31,270 I have a residual capacity of 1 here, 1 here, and 1 here. 1415 01:20:31,270 --> 01:20:38,790 And so the value of this augmenting path is 1, right? 1416 01:20:38,790 --> 01:20:43,330 It's not 2, because the minimum value is what 1417 01:20:43,330 --> 01:20:45,850 I can push through the network. 1418 01:20:45,850 --> 01:20:48,160 And I just need to take the min of all 1419 01:20:48,160 --> 01:20:51,030 of the residual capacities corresponding to the edges 1420 01:20:51,030 --> 01:20:53,160 that I traversed, that correspond 1421 01:20:53,160 --> 01:20:54,320 to this particular path. 1422 01:20:54,320 --> 01:20:58,180 And that min value of 2, 1, 1, 1, is 1, right? 1423 01:20:58,180 --> 01:21:02,240 So what this means is I've discovered an augmenting path 1424 01:21:02,240 --> 01:21:05,670 of residual capacity, 1. 1425 01:21:05,670 --> 01:21:08,840 Now I can go back to this thing over here. 1426 01:21:08,840 --> 01:21:13,760 And these edges are going to point me, in some cases, 1427 01:21:13,760 --> 01:21:18,540 to complimentary edges, in some cases to the direct edges that 1428 01:21:18,540 --> 01:21:22,200 are going to have to have their flows changed, either increased 1429 01:21:22,200 --> 01:21:27,110 or decreased, to increase the flow in the original network. 1430 01:21:27,110 --> 01:21:29,520 So you're guaranteed now that f, which 1431 01:21:29,520 --> 01:21:33,150 caused this residual network to have an augmenting path in it 1432 01:21:33,150 --> 01:21:34,750 was not maximum. 1433 01:21:34,750 --> 01:21:37,860 You're guaranteed that, because you found this path, OK? 1434 01:21:37,860 --> 01:21:39,760 So what happens here? 1435 01:21:39,760 --> 01:21:42,150 Well, you go back up and you say, remember, 1436 01:21:42,150 --> 01:21:44,170 I'm going to increment by plus 1, 1437 01:21:44,170 --> 01:21:46,700 because that's the residual capacity. 1438 01:21:46,700 --> 01:21:50,050 So I'm going to go up here, and I have s to a. 1439 01:21:50,050 --> 01:21:51,890 You'll need to help me out again. 1440 01:21:51,890 --> 01:21:55,310 So I'm going to make this 2, because I 1441 01:21:55,310 --> 01:21:56,800 needed to add a one to it. 1442 01:21:56,800 --> 01:21:58,100 What happens here? 1443 01:21:58,100 --> 01:21:59,652 This is the key step. 1444 01:21:59,652 --> 01:22:00,644 STUDENT: Subtract. 1445 01:22:00,644 --> 01:22:04,280 SRINIVAS DEVADAS: Subtract and make this a 0, right? 1446 01:22:04,280 --> 01:22:05,620 We're not quite done. 1447 01:22:05,620 --> 01:22:06,775 What's next? 1448 01:22:09,510 --> 01:22:11,380 I have b to c, right? 1449 01:22:11,380 --> 01:22:12,609 Right? 1450 01:22:12,609 --> 01:22:13,650 You're still on the hook. 1451 01:22:13,650 --> 01:22:14,400 STUDENT: [LAUGHS]. 1452 01:22:14,400 --> 01:22:16,000 SRINIVAS DEVADAS: b to c becomes? 1453 01:22:16,000 --> 01:22:16,500 STUDENT: 3. 1454 01:22:16,500 --> 01:22:17,150 SRINIVAS DEVADAS: 3. 1455 01:22:17,150 --> 01:22:17,650 Right. 1456 01:22:20,650 --> 01:22:24,101 And then, lastly, this becomes 2. 1457 01:22:27,230 --> 01:22:28,600 OK? 1458 01:22:28,600 --> 01:22:33,300 And at this point, if you create a residual network 1459 01:22:33,300 --> 01:22:35,690 for this new flow, you will not be 1460 01:22:35,690 --> 01:22:39,630 able to find a path in that residual network from s to t. 1461 01:22:39,630 --> 01:22:41,310 And you know you're done, right? 1462 01:22:41,310 --> 01:22:43,790 So all of this works. 1463 01:22:43,790 --> 01:22:46,450 We haven't quite shown that it works, because we haven't 1464 01:22:46,450 --> 01:22:48,440 done enough of the proofs. 1465 01:22:48,440 --> 01:22:50,237 But you have a sense as to why this works. 1466 01:22:50,237 --> 01:22:51,570 You could probably code this up. 1467 01:22:51,570 --> 01:22:52,860 It would all work. 1468 01:22:52,860 --> 01:22:54,600 A couple of issues in applications. 1469 01:22:54,600 --> 01:22:57,050 See you next time.