Challenge: Shortest Paths
Challenge yourself by solving a problem related to shortest path computations in graphs.
We'll cover the following...
Let's practice what we have learned so far.
Task
Imagine you just discovered your best friend from elementary school on Twitbook. You both want to meet as soon as possible, but you live in two different cites that are far apart. To minimize travel time, you agree to meet at an intermediate city, and then you simultaneously hop in your cars and start driving toward each other. But where exactly should you meet? You’re given a weighted graph , where the vertices represent cities and the edges represent roads that directly connect cities. Each edge has a weight equal to the time required to travel between the two cities. You’re also given a vertex , representing your starting location,= and a vertex , representing your friend’s starting location.
To find the optimal meeting point for two people traveling along a weighted graph, we can use Dijkstra’s algorithm. We start by computing the shortest paths from both the starting vertices and to every other vertex in the graph. Then, we iterate through all the vertices in the ...