Dijkstra's Shortest Path

T: O((V + E) log V)
Feedback

Dijkstra's Shortest Path

Selecting node with minimum distance from priority queue...
5694959381A0BCDEFGVisitedCurrentRelaxingShortest Path
SpeedNormal (500ms)
Parameters

{ nodes: [{id, x, y, label}], edges: [{from, to, weight}], source: number }

Variables
visited0
1function Dijkstra(graph, source):
2 dist[source] = 0
3 PQ.insert(source, 0)
4 while PQ is not empty:
5 u = PQ.extractMin()
6 if u is visited: continue
7 mark u as visited
8 for each neighbor v of u:
9 if dist[u] + weight(u,v) < dist[v]:
10 dist[v] = dist[u] + weight(u,v)
11 PQ.insert(v, dist[v])
12 return dist
Output
Selecting node with minimum distance from priority queue...