 In this video, we provide the solution to question number 14 for practice exam number one for math 1030, in which case a weighted graph is provided and we need to use Dijkstra's algorithm to find the shortest path from C to G. Now C is over here, G is over here and Dijkstra's algorithm tells us we move through the graph backward. All right, so what we're going to do is we start at the very end. What is the path from G to G? Well, that costs zero, so we're going to fill that one in there. Next, we're going to look at the closest neighbors to, well, all of the neighbors to G here. So there's F, which is a distance of 21 from G, so we write 21 right there. There's H right here, which is 22, like so. So that means we're now done at G. We visited everything there. The next closest, the smallest number I should say is F, so we're going to come over here to F. Who is connected to F, okay? So F could go up to E. That's 20 more, so 20 plus 21 gives us 41, like so. We could go down here to H, right, but you get 21 plus 18, which is bigger than 22. So it turns out we're not going to use that edge. So now we're done with F. The next smallest number is going to be H right here. We've already decided going through F would be slower because we already have a faster path from F to G there. So the only one we need to visit would be A right here. A gets to H by 10 more, so 10 plus 22 gives us 32, like so. That then finishes off H for us. The next smallest number is going to be A at 32. The neighbors of A that we haven't visited already is D and B. So going to D, we take 30 plus 32, that's going to give us 62, like so. If you go from A to B, you're going to take 32 plus 25, which is going to give you 57. And so that then visits everything connected to A. After A, the next smallest number is going to be 41 right here at E. So let's see what happens here. So going from E to B is 35. 41 plus 35 is bigger than 57, so we're not going to use that edge. But notice here that going from D to E, 41 plus 9 is 50, which is smaller than 62. So 50 is actually a better one, which means we don't want to use that one at all. So so far we have two options basically. We either go on the top from D to G or we go along the bottom through B to G, right? Which of those is going to happen here? Of course, with this distance of 40, because I guess we've now finished E, so the next smallest one to consider would be D. So the people who are connected to D, we could go through B, but that's 40 plus 50 is bigger than 57, so we're not going to use that edge. But we can get to the end right there, 50 plus 80, that's going to give you 130. So that's one way we could get to it. So if you go across the top, that's going to be 130. We've now finished D. We come here to B, 57 plus 60 in that situation that actually gives us 117. That's a little bit shorter. And so that's going to be the path we want. We don't want this one. And so therefore the path we're going to take is this one right here. So the shortest path looks like C to B to A to H to G. And that's going to cost 117 to do that path.