← Back to All Algorithms

🔄 Floyd-Warshall (All-Pairs Shortest Paths)

How It Works (Dynamic Programming)

For each intermediate vertex k, check if path i→k→j is shorter than current i→j:

dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])

Time: O(V³) | Space: O(V²)

Intermediate Vertex k = -

Distance Matrix

Click "Start" to compute all-pairs shortest paths