Challenge: Shortest Paths

Test the knowledge of shortest path computations in graphs by solving this challenge.

Let's practice what we've learned so far.

Task

We just discovered our best friend from elementary school on Twitbook. We both want to meet as soon as possible, but we live in two different cites that are far apart. To minimize travel time, we agree to meet at an intermediate city, and then we simultaneously hop in our cars and start driving toward each other. But where exactly should we meet? We are given a weighted graph G=(V,E)G = (V, E), where the vertices VV represent cities and the edges EE represent roads that directly connect cities. Each edge ee has a weight w(e)w(e) equal to the time required to travel between the two cities. We’re also given a vertex pp, representing our starting location, and a vertex qq, representing our 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 pp and qq ...

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy