0% found this document useful (0 votes)
75 views1 page

Example Dijkstra Algorithm

The document describes the Dijkstra algorithm for finding the shortest path between vertices in a graph. It provides pseudocode that initializes all vertex labels to infinity except the starting vertex which is set to 0. It then iteratively selects the unprocessed vertex with the smallest label and updates the labels of neighboring unprocessed vertices if a shorter path is found. This process continues until all vertices are processed and the final label of the target vertex z represents the shortest path distance from the starting vertex a.

Uploaded by

hanimsofia
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
75 views1 page

Example Dijkstra Algorithm

The document describes the Dijkstra algorithm for finding the shortest path between vertices in a graph. It provides pseudocode that initializes all vertex labels to infinity except the starting vertex which is set to 0. It then iteratively selects the unprocessed vertex with the smallest label and updates the labels of neighboring unprocessed vertices if a shorter path is found. This process continues until all vertices are processed and the final label of the target vertex z represents the shortest path distance from the starting vertex a.

Uploaded by

hanimsofia
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 1

EXAMPLE - DIJKSTRA ALGO.

Iterations

b 3 (a,c) 5 d 8 (a,c,b) Vertices 1 2 3 4 5 6


a (0,a) - - - - -
4 6 b (4,a) (3,c) (3,c) - - -
0 c (2,a) (2,a) - - - -
a 1 8 2 z (10,c)
d ∞ (8,d) (8,d) - -
13 (a,c,b,d,e,z) e ∞ (12,c) (12,c) (10,d) (10,d)
-
2 3 z ∞ ∞ ∞ (14,d) (13,e) (13,e)

c 2(a) 10 e S = { a,c,b,d,e,z }
10 (a,c,b,d)
procedure Dijkstra (G: weighted connected simple
graph, with all
Legend weights positive)
{G has vertices a = v0, v1, …, vn = z and weights w(vi,vj) where w(vi,vj) =
Processed……. ∞ if {vi,vj} is not an edge of G}
for i := 1 to n
L(vi) := ∞
L(a) := 0

Processing… S := ∅
{the labels are now initialized so that the label of a is 0 and all other
labels are ∞, and S is the empty set}
while z not belong to S

Next…….….. Discovering new path… Begin


u := a vertex not in S with L(u)
minimal
S := S ∪ {u}

Unprocessed Path taken…………..….. for all vertices v not in S


if L(u) + w(u,v) < L(v) then
L(v) := L(u) + w(u,v)
{this adds a vertex to S with
minimal label and updates the labels
of vertices not
in S}
end
{L(z) = length of a shortest path from a to z}

5/9/2012 45

You might also like