Introduction to All-Pairs Shortest Paths
Explore the all-pairs shortest paths problem to understand how to find the shortest distances between every pair of vertices in a graph. Learn basic concepts, analyze complexity of common algorithms, and grasp edge reweighting techniques to handle negative edges for efficient path computation.
Shortest path tree
Previously, we discussed several algorithms to find the shortest paths from a single source vertex to every other vertex of the graph by constructing the shortest path tree rooted at . The shortest path tree specifies two pieces of information for each node in the graph:
- is the length of the shortest path from to .
- is the second-to-last vertex in the shortest path from to .
Now, we consider the more general all-pairs shortest path problem, which asks for the shortest path from every possible source to every possible destination. For every pair of vertices and , we want to compute the following information:
- is the length of the shortest path from to .
- is the second-to-last vertex on the shortest path from to .
These intuitive definitions exclude a few boundary cases, all of which we’ve already seen previously.
- If there is no path from to , then there is no shortest path from to ; in this case, we define