~/ learn/ comp-372/ cards/ All-pairs shortest paths: Floyd-Warshall
1 of 4

Type the Floyd-Warshall core recurrence loop

Type the Floyd-Warshall core recurrence loop

Answer

for k = 1 to n: for i = 1 to n: for j = 1 to n: if d[i][k] + d[k][j] < d[i][j]: d[i][j] = d[i][k] + d[k][j]

k is the outermost loop: it activates each vertex as a permitted intermediate, building d[i][j]^(k) from d[i][j]^(k-1). After all n vertices are allowed, d holds the all-pairs shortest distances in Θ(V³).

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/50b0ebf0-80e0-444e-9070-6a0a1607ea20/flashcard utf-8 LF