Skip to main content

Dijkstra Algorithm

Definition​

Dijkstra's algorithm is a graph search algorithm that finds the shortest path between nodes in a graph, particularly for graphs with non-negative edge weights

Practice​

Dijkstra(Graph, source):
dist[source] := 0
for each vertex v in Graph:
if v ≠ source
dist[v] := infinity
add v to unvisited set

while unvisited set is not empty:
current := vertex in unvisited set with smallest distance
remove current from unvisited set
for each neighbor v of current:
alt := dist[current] + weight(current, v)
if alt < dist[v]:
dist[v] := alt

return dist