Solution: Shortest Paths
Discuss the solution of the shortest path computations problem.
We'll cover the following...
Let's practice what we've learned so far.
Task
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 are 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 are 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 graph and compute the sum of the shortest path distances from ...