Sie sind auf Seite 1von 2

{

S= { 1 };
for (i = 2; i < n; i++)
D[i] = C[1,i];
for (i=1; i < = n-1; i++)
{
choose a vertex w V-S such that D[w] is a minimum;
S = S {w };
for each vertex v V-S
D[v] = min (D[v], D[w] + C[w, v])
}
}



Initially:
S = {1} D[2] = 10 D[3] = D[4] = 30 D[5] = 100
Iteration 1
Select w = 2, so that S = {1, 2}
D[3] =
min( , D[2] + C[2, 3]) = 60
(7.2)
D[4] = min(30, D[2] + C[2, 4]) = 30 (7.3)
D[5] = min(100, D[2] + C[2, 5]) = 100
Iteration 2
Select w = 4, so that S = {1, 2, 4}
D[3] = min(60, D[4] + C[4, 3]) = 50 (7.4)
D[5] = min(100, D[4] + C[4, 5]) = 90
Iteration 3
Select w = 3, so that S = {1, 2, 4, 3}
D[5] = min(90, D[3] + C[3, 5]) = 60
Iteration 4
Select w = 5, so that S = {1, 2, 4, 3, 5}
D[2] = 10 (7.5)
D[3] = 50 (7.6)
D[4] = 30 (7.7)
D[5] = 60
Complexity of Dijkstra's Algorithm
With adjacency matrix representation, the running time is O(n2) By using an adjacency list
representation and a partially ordered tree data structure for organizing the set V - S, the
complexity can be shown to be
O(elog n)
where e is the number of edges and n is the number of vertices in the digraph.

Das könnte Ihnen auch gefallen