Dijkstras Algorithm
Dijkstras Algorithm
Dijkstra's algorithm
Dijkstra's algorithm - is a solution to the singlesource shortest path problem in graph theory.
Works on both directed and undirected graphs.
However, all edges must have nonnegative weights.
Approach: Greedy
Input: Weighted graph G={E,V} and source vertex
vV, such that all edge weights are nonnegative
Output: Lengths of shortest paths (or the shortest
paths themselves) from a given source vertex vV
to all other vertices
while Q
(while the queue is not empty)
do u mindistance(Q,dist) (select the element of Q with the min.
distance)
SS{u}
(add u to list of visited vertices)
for all v neighbors[u]
do if dist[v] > dist[u] + w(u, v)
(if new shortest path
found)
then d[v] d[u] + w(u, v)
(set new value of
shortest path)
(if desired, add traceback code)
return dist