Floyd-Warshall algorithm

symphonic, cinematic, dramatic, orchestral

Listen on 93

Lyrics

[Verse 1]
Started with a graph, nodes connected tight
Distance matrix filled, but paths ain't right
Direct connections show, but missing the whole
Shortest routes hiding when you dig for gold
K-I-J triple nested, that's the Floyd way
Check if detour beats the price you pay
If distance K plus K-J is less
Than I-J direct, then we got success

[Chorus]
All pairs shortest path, that's the mission we chase
Floyd-Warshall running, every node gets its place
Triple loop foundation, K-I-J in line
Dynamic programming, shortest paths we define
Update when it's better, keep the minimum clear
O-n-cubed complexity, but results crystal sheer

[Verse 2]
Initialize the matrix, adjacency base
Infinity for gaps where connections don't trace
Diagonal stays zero, self-loops cost none
Now the algorithm dance has just begun
Outer loop through vertices, each one intermediate
Test if routing through beats going straight
Relaxation principle, edges getting tight
Warshall meets Floyd, distance done right

[Chorus]
All pairs shortest path, that's the mission we chase
Floyd-Warshall running, every node gets its place
Triple loop foundation, K-I-J in line
Dynamic programming, shortest paths we define
Update when it's better, keep the minimum clear
O-n-cubed complexity, but results crystal sheer

[Bridge]
Negative cycles? Algorithm breaks down
Detect with diagonal, negative found
Applications everywhere, network routing calls
Social graphs, game maps, breaking distance walls
Simple but powerful, classic and clean
Matrix transformation, shortest path machine

[Outro]
When you need all distances, Floyd's got your back
Cubic time investment, no shortest path lacks
From every source vertex to every destination
Floyd-Warshall delivers optimal navigation

← Bellman-Ford algorithm | A* search →