Video 7: Graph Theory (online class)

Flash and JavaScript are required for this feature.

Download the video from Internet Archive.

Akin: And today I will present to you one of the most interesting topics in my field of study, which is graph theory.

Um, I know the topic might sound a little bit intimidating, but what you need to understand this presentation is quite simple.

So, if you can do the basic math, like simple additions or simple multiplication, you are pretty good to go.

And what you'll need is the observation skills and that's probably all you need to have for understanding this presentation.

Before I jump in, can I ask like, if any of you guys have been familiar with this topic before?

Student: A little bit, a little bit.

Akin: Okay, um, yeah, I hope you get something out of today's presentation.

Hope it will be useful.


Okay about today's agenda, we'll go over some definitions to see what the graph is.

And next we are going to explore one of the most interesting questions in graph theory, which is the shortest path problem.

And then we are going to see some examples.

And we are going to recap it at the end.

All right.

Akin: And also feel free to interrupt me with any questions you may have.

Just don't be shy.

Akin: Okay.

All right.

Let's dive in.

Akin: The question is, what is a graph?

If you have been dealing with data before, you might have been familiar with the concept of graph on the left one, you have the graph on the x axis and y axis and the right one you have a bar graph to represent some data.

And but this is not the graph we are going to talk about today.

What we are going to talk about today is quite--a little bit different and the definition of it is the graph is a collection of nodes and edges.

And by nodes here I will use the red circle to represent a node and the edges will be this just a straight line.

So basically nodes can represent any objects.

It can be people, it can be animals, it can be just just anything.

Akin: And the idea is to indicate some relationships between two nodes.

Akin: And that might not sound clear, but let's take a look at some examples . Here.

Okay, here I have a node that represents Harvard.

Akin: And I have a node that represents MIT.

And they both can be connected by the edge--the space--they are in the same city of Cambridge.

Is it clear on this one?

Student: Yes.

Akin: All right.

Akin: And I can have a node of Math and EECS Electrical Engineering and Computer Science: and both are the departments at MIT.

I have Akin--this is me--who is a student at MIT and I study math and EECS.

I can have Alice who loves math and Bob who hates math and Alice and Bob are rivals.

Akin: Is it good?

Student: Mmm hmm.

Akin: Okay, ah okay.

I would like to make some notes here.

This graph is actually quite messy.

It has like so many kinds of nodes--you have schools you have departments and you also have people.

And at the same time, you also have so many kinds of edges, you have the same city, have departments, students and many more.

So, in theory, this is not wrong.

In one graph, you can have so many kind of nodes and so many kind of edges.

But in practice, we usually refer to a graph as only having one kind of nodes and one kind of edges.

And what it means by that, if you take a look at the right graph, you can see this graph has nodes that are the states in New England and the edges will be this indication if two states are neighbors.

Akin: Are we still on the same page?

Students: Mmm hmm.

Uh huh.

Akin: Yeah, and this is--I also have some examples--you can probably have a better understanding.

Ah, the example I'm going to use is the network representations.

And probably you guys have seen Facebook before.

And what we are going to do is Facebook actually have a very nice way to present the network as a graph.

And to do so you can have the node to represent a user and edge to represent the friendships between any two users.

For example, this diagram here you can see Liz here is has--Liz has a page that connects to Emma, Shane and Alan.

That means our list has three friends, which is Emma, Shane and Alan.

Akin: Is it--is it okay?

Is it all right?

Student: Yeah.

Akin: Okay, I just want to ask like to make sure that we are on the same page like just a quick questions like how many friends does John have?

Student: Four?

Akin: Four.

Akin: Yeah.

Who they are?

Akin: Yeah the four friends of John are Bob, Jill, Shane and Leah.

Akin: Okay, still good?


Akin: Okay, I have another question for you.

On the right, I have a graph whose--whose nodes are some states in the US.

You can have Maine, New Hampshire, Massachusetts, and many more.

And the edges will represent that there is a road that connects two nodes together.

For example, this edge is the road that connects Maine and New Hampshire.

This edge is the road that connects Vermont and New York.

Akin: So basically, you can view this graph as a map and there are states then they are roads that connects states together.


So here's my question.

You want to drive from Maine to Maryland, which is this circle to this circle.

And to use a road, you need to pay $1 for each road you take.

Yeah, the question is that what is the cheapest route you can take?

Akin: Any figures?

Student: You can go along the left edges.

Akin: Left edges in New Hampshire, Vermont, New York, Pennsylvania and Maryland.

Student: Yeah.

Akin: Yeah, that's perfect.

And there are actually two cheapest routes here, which are indicated by the green lines.

Akin: And whatever route you take, you need to pay $5.

And this is what we call the shortest path problem.

I will explain it in in a minute.

But if you guys have any questions, if you don't understand the graph, you can ask me.

Akin: Okay, ah, let's move on.

So, um, the shortest path problem.

Akin: It is probably one of the most important questions in graph theory, where scientists have been dealing with it for decades, and it also has so many applications in real life.

And the way we formulate a problem is that we are given a graph.

And we want to find the shortest path in terms of the number of edges to go from one node to another, like we just did to go from Maine to Maryland.

Akin: And it's actually easy to solve by eyes if a graph is so small.


Did I pronounce correctly?

Student: Yep.

Akin: Yeah, he just solved it in like 10 seconds.

And it's pretty easy if the graph is small.

But the question is, like, if the graph is large, how do we do it?

Like on this one, if you want to go from the left node to the right node, is probably impossible to solve it by eyes because you know, there are like 100 nodes and thousand edges.

So to solve these problems, computer scientists have come up with very nice and very simple procedures to find a shortest path.

And we call it the breadth first search or BFS for short.


Akin: And we are going to do it now.

And I'm going to list the instructions on the left, and we are going to solve it together, on the right.

Akin: So to do it, we are going to start with labeling the start node, which is Maine here with zero.

And then you're going to see that from Maine, you can expand to New Hampshire.

Akin: So we're going to put 1 at New Hampshire.

Akin: And then from New Hampshire, you can only go to Vermont and Massachusetts.

So we will put 2 here.

And if you do the same thing from Vermont and Massachusetts, you can only go to New York, Connecticut and Rhode Island, and we put 3 there.

Akin: And we are going to do it again and again until we find Maryland, Akin: which is 5.

Akin: Is it clear on the procedure?

Students: Yeah.

Akin: That's good.

Okay, so um, We found Maryland, it's level five, meaning that to go from Maine to Maryland, you need to take five edges.

However, these procedures only tell you how like the number, the least number of edges you need to take.

But it doesn't exactly tell you like what path you should be taking.

So the question is, how do you find such a path that costs you $5?

And the answer is what we call backtracking.

And it is quite simple too.

So what it means by backtracking is that you have Maryland at 5 and you have Maine at 0.

You want to find a path that goes like 5-4-3-2-1 and 0.

And to do that, on the left one, you can go 5-4-3-2-1 and 0 and under right one you can go 5-4-3-2-1 and 0 and these are actually two paths that we just saw it earlier by eyes.

Akin: is it clear for everyone?

Students: Yes.

Akin: Okay, sounds good.

So, how do you guys feel about this example?

Is it like, too hard to easy or just okay?

Student: It's all right.

Akin: It's all right?

All right for everybody?

Okay, um, if this is not too hard for you, I have two questions that might be a bit more challenging.

For this one, you still have a map.

You have to have the same graph with the nodes of the states.

And but now, each road will cost you differently.

Like for example, from Maine to New Hampshire, it will cost you $1.

And from New Hampshire to Massachusetts, it will cost you $2.

So basically, it's like the numbers above the edge to tell you the amount of money you need to pay for using the road.

Akin: You still want to go from Maine to Maryland?

Akin: Will you still pick the same route?

Akin: I'll tell you here that the old one will cost you $11--or $1, $2, $3, $3 and $2.

Akin: Yeah, can we do better?

Student: I think in the lower part of the graph, we can take the right route this time, so it would cost $4.

Akin: Yeah.

Akin: Yeah, that's a good catch.

If you go this way, you only need to pay four, right?

Student: Mmm hmm.

Akin: How about the upper part?

Akin: Can you find the shorter way, the cheaper way?

Student: Well, we can go from New Hampshire to Massachusetts to Connecticut to New York.

Akin: Yeah, that's great.

This is actually the cheapest path we can buy.

Akin: So, this type of question, we call it the weighted shortest path problem, is basically the shortest path problem with some variations.

So it--here every edge will have the corresponding weight.

In this case, the way is just the amount of toll we need to pay for using the road.

Akin: Is everybody still good?


Akin: So, as you can see, the traditional breadth first search will not work on this graph because it will just tell us to go on this way, the old way.

But the actual the actual cheapest route is just to go on the green line.

So the question is like ah, how can we solve it by using the BFS?

Akin: The answer is we need to do some modifications.

To use the BFS to solve it, we can add an intermediate node here.

So we basically can split up the roads.

And so from one road that cost you $2 is going to be split up into two roads that cost you $1 for each road.

Akin: Is the diagram clear for you?

Student: Yeah.

Akin: Yeah.

And also the same thing with a road that cost you $3 can be split into three roads that cost you $1 each.

And you can transform the graph from the graph with the weights to the graph with intermediate nodes.

As you can see, Massachusetts to Rhode Island--$2 will be split into two roads and you can do the same for every single edge.

Akin: And from here, you can use the BFS like we just did before.

I'm going to just show you how it goes because it will take too long.

You have 0-1-2-3-4-5-6-7-8-9.

Akin: And you can do the backtracking to find the actual shortest path.

Akin: Is it clear for everybody?

Student: Yep.

Akin: Yeah, sounds good.



I'd like to end with some--a couple of examples that you may have come across.

So, these are the actual examples in real life of the BFS.

So the first one is the cheapest flight transits.

If you have used some traveling engines before, like, you will want to go from one place to another.

But if you do a search, we will tell you what is the cheapest route but it's a transit.

So in this model, you are given the origin and destination and price of several flights.

And for example, here you want to go from Boston to Los Angeles.

You can use the breadth first search to see that this is actually the cheapest route you can find.

And another example that I have here is the minimizing the signal delay.

So if you want to call a friend--like Alice wants to call Bob, wants to call Bob, so the signal's actually going to bounce off a lot of cellphone towers and to reaching the destination and from the signal to go from one tower to another tower, it has some delays.

So we can we can model this as a graph with the node to be the cell phone towers and the edge to represent the delays from tower to tower.

And we can use the breadth first search to see like what should be the fastest route that signal actually minimize the delay.


Akin: Is the example clear to everybody?

Student: Yep.

Akin: Yeah.

That's pretty much all I have for today.

Just want to recap everything up.

Today we learned what the graph is.

And we see how to solve the shortest path problems by the breadth first search, but on the one without the weight and weighted on.

And we also saw some applications in real life like route planning and minimizing delays.

Akin: And yeah, that's all I have for today.

You guys have any questions?

I'll be happy to answer it.

Student: I think everything is clear.

Student: Yeah.

Clear for me too.

No questions from me.

Student: Same.

Akin: That's, yeah, that's all I have today.

Thank you.

Thank you, you guys.

Free Downloads



  • English-US (SRT)