1 00:00:01,496 --> 00:00:02,870 PROFESSOR: In this video lecture, 2 00:00:02,870 --> 00:00:05,720 we're going to introduce the idea of directed graphs, 3 00:00:05,720 --> 00:00:08,940 or digraphs for short. 4 00:00:08,940 --> 00:00:10,580 So normally and before this class, 5 00:00:10,580 --> 00:00:13,170 you might have thought of graphs as being something like this. 6 00:00:13,170 --> 00:00:16,530 Y is a function of x and graphed on the xy plane. 7 00:00:16,530 --> 00:00:18,810 But that's not what we want to be thinking about. 8 00:00:18,810 --> 00:00:21,710 Instead, we want to think about something like this. 9 00:00:21,710 --> 00:00:23,870 This is a graph to a computer scientist. 10 00:00:23,870 --> 00:00:26,800 Show a bunch of vertices, which are those point that you see, 11 00:00:26,800 --> 00:00:29,210 and edges, which connect vertices. 12 00:00:29,210 --> 00:00:31,550 Being more specific and direct about this, 13 00:00:31,550 --> 00:00:34,530 it's composed of a set V of vertices 14 00:00:34,530 --> 00:00:39,750 and a set E of edges, which are composed of 2V each. 15 00:00:39,750 --> 00:00:42,540 The way you write that out, an edge is v comma w, 16 00:00:42,540 --> 00:00:46,590 and that specifies an edge going from v to w. 17 00:00:46,590 --> 00:00:49,360 And in the graph, it would look something like this. 18 00:00:49,360 --> 00:00:50,560 Note that they are directed. 19 00:00:50,560 --> 00:00:53,290 That an edge from v to w is not the same thing 20 00:00:53,290 --> 00:00:58,440 as an edge from w to v in a directed graph. 21 00:00:58,440 --> 00:01:01,220 For example, here we have one directed graph, 22 00:01:01,220 --> 00:01:03,936 and you write out vertices as the set of all the vertices 23 00:01:03,936 --> 00:01:04,519 you see there. 24 00:01:04,519 --> 00:01:08,342 And edges are pairs of vertices. 25 00:01:08,342 --> 00:01:11,060 You can also realize that digraph 26 00:01:11,060 --> 00:01:14,737 is the same thing as a binary relation on the vertices, 27 00:01:14,737 --> 00:01:16,695 because each edge just defines the relationship 28 00:01:16,695 --> 00:01:18,480 from one vertice to another. 29 00:01:18,480 --> 00:01:21,900 So, every binary relation can be drawn out as a graph. 30 00:01:21,900 --> 00:01:25,960 You just put each of the things in each of the sets as vertices 31 00:01:25,960 --> 00:01:28,450 and edges being the things that relate 32 00:01:28,450 --> 00:01:29,995 from one set to the other. 33 00:01:32,610 --> 00:01:36,400 So, now we're going to define walks and paths. 34 00:01:36,400 --> 00:01:39,640 Now, a walk follows successive edges 35 00:01:39,640 --> 00:01:42,710 but it can repeat vertices or edges. 36 00:01:42,710 --> 00:01:45,930 For example, I can start at the black vertice there, 37 00:01:45,930 --> 00:01:50,720 and we can go to red, blue, yellow, red. 38 00:01:50,720 --> 00:01:52,500 And w can go back to blue again. 39 00:01:52,500 --> 00:01:53,836 There's nothing stopping us. 40 00:01:53,836 --> 00:01:56,220 And the length of these paths is not 41 00:01:56,220 --> 00:01:58,200 how many vertices we've gone through, 42 00:01:58,200 --> 00:02:01,150 but the number of edges that we've gone through. 43 00:02:01,150 --> 00:02:03,480 So here, the length would be five 44 00:02:03,480 --> 00:02:06,230 because we went from white to black, black to blue, 45 00:02:06,230 --> 00:02:09,949 blue to yellow, yellow red, red blue. 46 00:02:09,949 --> 00:02:12,686 It's not the six vertices that we went through. 47 00:02:12,686 --> 00:02:14,370 And you have to be careful about that, 48 00:02:14,370 --> 00:02:17,550 because that difference of one kind of gets you. 49 00:02:17,550 --> 00:02:21,190 A path, on the other hand, walk through vertices with that 50 00:02:21,190 --> 00:02:23,380 repeating a single vertex. 51 00:02:23,380 --> 00:02:26,810 So, for example, start at blue, you can go to yellow, 52 00:02:26,810 --> 00:02:30,480 you can go red, you can go pink, you can go green, 53 00:02:30,480 --> 00:02:32,160 but then we're stuck. 54 00:02:32,160 --> 00:02:33,610 We can't go back to red. 55 00:02:33,610 --> 00:02:34,910 We've already been there. 56 00:02:34,910 --> 00:02:35,750 So, that's it. 57 00:02:35,750 --> 00:02:37,280 That would be the end of our path. 58 00:02:37,280 --> 00:02:40,615 If we went to red again, then it wouldn't be a path anymore. 59 00:02:40,615 --> 00:02:42,110 Not be a valid path. 60 00:02:42,110 --> 00:02:44,380 And here, the [INAUDIBLE] length is four edges, not 61 00:02:44,380 --> 00:02:44,970 five vertices. 62 00:02:47,600 --> 00:02:49,890 And every graph can be represented 63 00:02:49,890 --> 00:02:52,190 as a matrix representation. 64 00:02:52,190 --> 00:02:53,680 You draw it out like this. 65 00:02:53,680 --> 00:02:57,180 And what we're going to do is if there's 66 00:02:57,180 --> 00:03:02,110 a edge that goes from one of the things on the right over to one 67 00:03:02,110 --> 00:03:05,360 of things on the top, we'll put a one at that position. 68 00:03:05,360 --> 00:03:08,110 For example, there's an edge that goes from the black 69 00:03:08,110 --> 00:03:09,050 to the red. 70 00:03:09,050 --> 00:03:13,390 So, on the black row in the red column, 71 00:03:13,390 --> 00:03:15,381 we're going to put in a one. 72 00:03:15,381 --> 00:03:17,630 Same thing, there's one that goes from black to green. 73 00:03:17,630 --> 00:03:21,530 We'll put black row, green column, put in another one. 74 00:03:21,530 --> 00:03:25,940 And so on for all the edges that we have in our graph. 75 00:03:25,940 --> 00:03:27,610 And the rest we just filled with zeroes. 76 00:03:27,610 --> 00:03:30,120 And this is called an adjacency matrix. 77 00:03:30,120 --> 00:03:32,340 And as you can see, it uniquely defines a graph. 78 00:03:32,340 --> 00:03:36,260 Every edge is represented here, and every one of the vertices 79 00:03:36,260 --> 00:03:37,290 is represented here. 80 00:03:37,290 --> 00:03:40,460 So, any graph can be drawn up this way.