Graph Theory37 sections · 1633 units
Open in Course

The Core Idea

Paths through intermediate ...

Floyd-Warshall's core insight: can I improve the path from ii to jj by routing through an intermediate vertex kk?

If dist[i][k] + dist[k][j] < dist[i][j], then going through kk is better. The algorithm considers vertices one at a time as potential intermediates. After processing vertex kk, all paths using vertices 0,1,,k0, 1, \ldots, k are optimal. This builds up the solution incrementally, which is the essence of dynamic programming.