a. Dijkstra’s Algorithm
Dijkstra's algorithm solves the single-source shortest-paths problem on a weighted, directed graph G = (V, E) (Cormen 2001). Dijkstra's algorithm is faster than the Bellman-Ford algorithm. Bellman-Ford algorithm solves the single-source shortest-path problem in the general case. In this case the edges of a given digraph can have negative weight and produce a correct answer as long as no negative-weight cycles are reachable from the source. Like Dijkstra's algorithm, this algorithm uses the notion of edge relaxation but does not use with greedy method (Cormen 2001).
Dijkstra's algorithm maintains a set S of vertices whose final shortest-path weights from the source s have already been determined. The algorithm repeatedly selects the vertex u ϵV – S with the minimum shortest-path estimate, adds u to S, and relaxes all edges leaving u. In the following implementation, we use a min-priority queue Q of vertices, keyed by their d values. Figure 1 show an example for Dijkstra’s algorithm in steps.
DIJKSTRA(G, w, s)
- INITIALIZE-SINGLE-SOURCE(G, s)
- S ← Ø
- Q ← V[G]
- while Q ≠ Ø
- do u ← EXTRACT-MIN(Q)
- S ← S _{u}
- for each vertex v _ Adj[u]
- do RELAX(u, v, w)