AllPairsShortestPath
All-Pairs Shortest Path (APSP) is the problem of finding the minimum-distance paths between every pair of vertices in a weighted graph. Given a directed or undirected graph G=(V,E) with edge weights w, the objective is to compute the matrix D where D[u,v] is the length of the shortest path from u to v. If no path exists, D[u,v] is typically infinity. In addition to distances, a corresponding predecessor or next-hop matrix can be produced to reconstruct the paths.
Floyd-Warshall is the canonical solution for dense graphs. It uses dynamic programming to allow intermediate vertices
For sparse graphs, Johnson's algorithm is common: reweight edges to remove negatives, then run Dijkstra from
Output and variants: The main output is a distance matrix D, with optional next-hop or predecessor information