Single Source Shortest Path
Single Source Shortest Path
• The algorithm keeps track of the set of vertices for which the
distance has been computed, called the cloud C
• Every vertex has a label D associated with it. For any vertex u, D[u]
stores an approximation of the distance between v and u. The
algorithm will update a D[u] value when it finds a shorter path from
v to u.
• When a vertex u is added to the cloud, its label D[u] is equal to the
actual (final) distance between the starting vertex v and vertex u.
3
Example
Example
Example
Example
Example
Example
Example
Example
Example
Example
4 1 3 10
2 2 ∞
∞ C D E
5 8 ∞ 4 6
1
F G
∞ ∞
13
Dijkstra’s Algorithm
• Graph G, weight function w, root s
relaxing
edges
14
Time Complexity: Using List
The simplest implementation of the Dijkstra's algorithm
stores vertices in an ordinary linked list or array
– Good for dense graphs (many edges)