2. One-To-All Shortest Path Problem
• We are given a weighted network (V, E, C) with node set V,
edge set E, and the weight set C specifying weights cij for the
edges (i, j) є E.
• We are also given a starting node s є V .
• The one-to-all shortest path problem is the problem of
determining the shortest path from node s to all the other
nodes in the network.
• The weights on the links are also referred as costs.
3. Algorithms Solving the Problem
• Dijkstra’s algorithm
• Solves only the problems with nonnegative costs,
i.e., cij ≥ 0 for all (i, j) є E
• Bellman-Ford algorithm
• Applicable to problems with arbitrary costs
• Floyd-Warshall algorithm
• Applicable to problems with arbitrary costs
• Solves a more general all-to-all shortest path problem
4. General Description
• Suppose we want to find a shortest path from a given node s to
other nodes in a network (one-to-all shortest path problem).
• Dijkstra’s algorithm solves such a problem.
• It finds the shortest path from a given node s to all other nodes in the
network.
• Node s is called a starting node or an initial node.
• How is the algorithm achieving this?
• Dijkstra’s algorithm starts by assigning some initial values for the
distances from node s and to every other node in the network.
• It operates in steps, where at each step the algorithm improves the
distance values.
• At each step, the shortest distance from node s to another node is
determined.
5. Formal Description
• The algorithm characterizes each node by its state.
• The state of a node consists of two features:
Distance value and status label.
1. Distance value of a node is a scalar representing an estimate of the its
distance from node s.
2. Status label is an attribute specifying whether the distance value of a
node is equal to the shortest distance to node s or not.
The status label of a node is Permanent if its distance value is equal to the
shortest distance from node s.
Otherwise, the status label of a node is Temporary.
• The algorithm maintains and step-by-step updates the
states of the nodes.
• At each step one node is designated as current.
6. Notation
In what follows:
• dl denotes the distance value of a node l.
• p or t denotes the status label of a node, where p stand for
permanent and t stands for temporary.
• cij is the cost of traversing link (i, j) as given by the problem.
The state of a node l is the ordered pair of its distance value dl
and its status label.
10. Step 1: First of all, define two sets-
1) One set will contain all those vertices which have been visited in the shortest path
tree. In the beginning, this set will be empty.
2) Other set will contain all those vertices which are not visited in the shortest path
tree. In the beginning, this set will contain all the vertices of the graph.
Step 2: For each vertex of the graph, define a three tuple as-
1) P[v] which denotes the parent (predecessor) of vertex ‘v’
2) d[v] which denotes the shortest path estimate of vertex ‘v’ from the source vertex.
3) St[v] which denotes the status of the vertex, whether visited ‘V’ or not ‘NV’.
Step 3: Initially, set the value of the tuple for each vertex as-
1) Set the value of variable ‘P’ for each vertex to NIL i.e. P[v] = NIL.
2) Set the value of variable ‘d’ for source vertex to 0 i.e. d[S] = 0.
3) Set the value of variable ‘d’ for rest of the vertices to ∞ i.e. d[v] = ∞.
4) Set the value of variable ‘St’ for source vertex to 0 i.e. St[S] = V.
5) Set the value of variable ‘St’ for rest of the vertices to NV i.e. St[v] = NV.
Step 4: Consider all outgoing edges from the visited vertex/vertices, and update the tuple of
the vertices on the outgoing edges.
Step 5: Now among not visited vertices, we choose a vertex with the minimum value of
variable ‘d’, accordingly change the status of the vertex to ‘V’.
Step 6: Repeat Step 4 and Step 5 until all the vertices of the graph are visited.
19. VERTEX – 1
1 2 3 4 5 6
S 1 D 0 ∞ ∞ ∞ ∞ ∞
S P T T T T T
S 2 D 0 7 9 ∞ ∞ 14 (nbrs of 1)
S P T P T T T T
S 3 D 0 7 Min{9,10} 22 ∞ 14 (nbrs of 2)
S P P T P T T T
S 4 D 0 7 9 Min{22,20} ∞ Min{14,11} (nbrs of 3)
S P P P T T T P
S 5 D 0 7 9 20 20 11 (nbrs of 6)
S P P P T P T P
S 6 D 0 7 9 20 Min{20, 22} 11 (nbrs of 4)
S P P p P P P
20. Applications of Dijkstra's Algorithm
- Traffic Information Systems are most prominent use
- Mapping (Map Quest, Google Maps)
- Routing Systems