00:01
So in this exercise we should find the shortest path between cities.
00:06
So we got this graph that represents the location of some cities, and the edges represent the distance between each city.
00:16
Okay, so we need to find the shortest path between boston and la.
00:22
So the way to proceed in this case is use the well -known dijkstra algorithm.
00:29
So how to apply the dijkstra algorithm in this exercise? well, just remember that you should put an infinite distance between each city, and then we are going to update this value with the shortest one.
00:49
So in this case, we are going to start from boston, and then we are going, for example, from boston, we can go either to new york or to do to just, chicago.
01:01
So if we go to new york, then the distance that we had traveled is exactly 191.
01:08
And in parentheses is always used to put the note that we have passed until reach that the actual note.
01:22
In this case, is new york.
01:23
But the previous one was boston.
01:25
So this is like the path that we are following.
01:30
If we update the value for chicago in that case will be 860 and the path is from boston to chicago.
01:40
Okay, so this corresponds to the first step on the algorithm.
01:45
So we have already visited this note here that is boston and then we should continue with the next notes.
01:57
So the next notes are new york and chicago.
02:02
So let's, for example, are from new york.
02:06
So from new york, we can go to chicago.
02:09
And if we go to chicago, then we should sum, 860 to 151.
02:18
And i'm sorry, and then we should add, and we should add 722.
02:25
Okay, so this will be eight, will be nine, exactly if, 900, i'm sorry, 9, 220.
02:39
23 13 sorry 13 okay so clearly this distance is bigger than 860 okay so here 913 is bigger than 860 so we are going to to choose the smaller one so in this case it's 860 so we're going to live with that path and the other we are not going to take into account so we can erase this so this path is not good so we're not going to choose it okay what to what other node we can move well we can go to dallas following this edge and when we arrived to dallas we got a total distance of 1 ,563 and the path that we have the the notes that we have traveled are b and new york.
03:49
So these are the cities that we have visited until reach the dallas.
03:58
Fine.
04:00
Okay.
04:01
So there is not other path options to move from new york.
04:10
So we have already, we can discard this note.
04:13
Now let's see what happened with chicago.
04:16
From chicago we can move to three to three to three years.
04:19
Cities we can go directly to la we can go to san francisco or we can go to denver following this mode so i'm going to put this on a different color because otherwise it's hard to see so let's say that first we go from chicago to la following this path and then we are going to update the value of la it will be for us 1 ,036, so it's 2 ,000, so la is 2 ,596 and in parentheses the notes that we had travel is r .b.
05:16
And chicago and then we reach la.
05:18
So this is the total distance following that path.
05:23
We can go to denver.
05:25
However, i don't have enough space to draw to to draw there so i'm going to put here denver and the distance will be 860 plus 908 so if we go from denver from from chicago to denver following this edge the total distance until reach november is 1 ,768 and the path is from boston to chicago great.
06:05
So we can raise this infinite here.
06:09
And finally we can reach san francisco from chicago.
06:15
In that case, the total distance will be 1 ,941.
06:33
And the path is boston, chicago, and then san francisco.
06:40
Fine.
06:43
What other node we can visit now? so we have until now we have visited new york, chicago and boston.
06:53
Now we should go from dallas to directly to la.
07:00
And that distance, you can observe that is 1 ,563 plus 1 ,23535.
07:08
So clearly this will be bigger than 2 ,596.
07:14
So that path is not important in this case.
07:19
So we're not going to consider going from dallas to la.
07:23
What other path we can go from dallas? well, we can move to denver.
07:28
That distance, again, will be 1563 plus 798, which is clearly bigger than 1 ,07, 1768.
07:46
So we're going to keep the smaller one that corresponds to this distance so we can reach denver in its most, probably less distance going from chicago.
07:58
And that's it.
07:59
That's all the possible path to going from dallas to other cities.
08:05
So we have already trouble starting from dallas.
08:09
Now let's see what happened if we go from denver.
08:13
The only way to keep moving is going.
08:17
Go into san francisco but if we go from denver to san francisco then the total distance will be one one thousand seven hundred sixty eight plus nine hundred fifty seven and this clearly is bigger than one thousand one thousand nine hundred forty one so we're going to keep the smaller one so denver we're also not going to choose any path from denver.
08:55
And that's it.
08:56
So denver, we have already visited that note.
09:00
And the last note that we should visit is san francisco.
09:05
So what happened if we move, so the distance to denver is already on use.
09:12
It doesn't matter.
09:13
We are not going to reach any place.
09:16
If we go from san francisco to la, then we should add 1 ,900 ,000.
09:24
Plus 957 and this clearly is bigger than this previous distance that we reach la from chicago.
09:32
So in this case we're going to keep the smaller one and that corresponds to this shortest path.
09:39
So the shortest path go from boston to chicago and then directly to la and that corresponds to this distance here.
09:49
Great.
09:50
So for the part a, the distance between boston.
09:58
To la is 2 ,596 and the path corresponds to boston, chicago and directly la.
10:09
This is the shortest path.
10:14
Great.
10:15
So let's continue...