How Dijkstra's Algorithm Works

lo-fi, ambient, dreamy, relaxed

Listen on 93

Lyrics

[Verse 1]
Five nodes scattered like stars on the map
A through E connected with weighted paths
Start at A, mark distance as zero clean
Set infinity for every node unseen
Build a table, track the shortest route
Greedy choices, no disputes or disputes

[Chorus]
Pick the closest, lock it down
Update neighbors all around
Dijkstra's method, step by step
Shortest paths with no regret
Distance table tells the tale
Optimal routes that never fail

[Verse 2]
A to B costs three, A to C costs one
Choose node C, the smallest sum has won
Lock C tight, it's permanent now
Update D through C, six total somehow
B gets cheaper through this new connection
Two beats three in our inspection

[Chorus]
Pick the closest, lock it down
Update neighbors all around
Dijkstra's method, step by step
Shortest paths with no regret
Distance table tells the tale
Optimal routes that never fail

[Verse 3]
B comes next at distance two
Lock it solid, we're breaking through
From B to D costs four more steps
Six total beats our previous best
E gets touched at distance five
Keep the table sharp and live

[Bridge]
Greedy algorithm, locally smart
Global optimum, mathematical art
No negative edges, that's the rule
Positive weights make this our tool

[Verse 4]
D locks in at distance six
E follows at five, the final fix
Every vertex visited once
Shortest tree built without stunts
From source A to every destination
Mathematical navigation

[Outro]
Priority queue keeps order tight
Relaxation makes distances right
Dijkstra solved the shortest way
Graph traversal holds the day

← Graph Theory Basics for Shortest Paths | Dijkstra vs Other Path-Finding Algorithms →