Title-2.gif (7411 bytes)(single source)  

Ball.gif (922 bytes)Uneighted GraphBreath - First Search
Ball.gif (922 bytes)Weighted Graph : Dijkstra's algorithm
 

        Sassignl.gif (77 bytes) {v0};    for each vbelong.gif (100 bytes) V do D[v] assignl.gif (77 bytes) d(v0,v);                       *
        while  S ~equ.gif (93 bytes) V do{
                  choose w ~belong.gif (122 bytes)S , D[w] min;
                  S assignl.gif (77 bytes)S U {w};
                  for each v belong.gif (100 bytes)V-S  do                        *
                         D[v] assignl.gif (77 bytes) min(D[v] , D[w]+d[w,v]);
        }

Property : Map6.gif (3505 bytes)

        v belong.gif (100 bytes)imply.gif (911 bytes) D[v] = shortest path from v0 to v
        v imply.gif (911 bytes) D[v] = shortest path from v0 to v through x (in S)
            proof : othewise ,exist.gif (879 bytes) a path which is the combination of the path
                                               from v0 to v and from v to w

Ball.gif (922 bytes)Example

 Map7.gif (2606 bytes)  

S

A B C D E F G
A 0 1 infinte.gif (82 bytes) infinte.gif (82 bytes) infinte.gif (82 bytes) 2 6
A   B 0 1 2 3 5 2 6
A   B   F 0 1 2 3 4 2 6
A   B   C    F 0 1 2 3 4 2 6
A   B   C    D   F 0 1 2 3 4 2 6
A   B   C    D   E   F 0 1 2 3 4 2 5
A   B   C    D   E   F   G 0 1 2 3 4 2 5

 

Ball.gif (922 bytes)For both directed and undirected graph
 

Ball.gif (922 bytes)T = O(N2)
 

Ball.gif (922 bytes)Priority-First-Search implementation : Priority = D[w]+d(w , v)
 

Ball.gif (922 bytes)Priority queue = nullset.gif (85 bytes) ; put(S);
 

Ball.gif (922 bytes)Only modify D[v] , for w assignr.gif (891 bytes) v