The Shortest Path Problem Dijkstras Algorithm Graph Theory
The Shortest Path Problem Dijkstra’s Algorithm Graph Theory Applications
Foundation With each edge e of G let there be associated a real number w(e), called its weight. Then G, together with these weights on its edges, is called a weighted graph. Weighted graphs occur frequently in applications of graph theory. In the friendship graph, for example, weights might indicate intensity of friendship; in communications graph they could represent the construction or maintenance of the various communications links.
If H is a subgraph of a weighted graph, the weight w(H) of H is the sum of the weights on its edges. Many optimization problems amount to finding, in a weighted graph, a subgraph of a certain type with minimum (or maximum) weight. One such is the shortest path problem: given a railway network connecting various towns, determine a shortest route between two specified towns in the network.
Here we must find, in a weighted graph, a path of minimum weight connecting two specified vertices u 0 and v 0 ; the weights represent distances by rail between directlylinked towns, and therefore non-negative. The path indicated in the next figure is a (u 0 , v 0) -path of minimum weight.
1 b 2 6 8 a 1 5 1 e 7 2 d 9 3 f 8 9 j 7 1 1 1 Shortest Path: d(a, h)= 12 k 9 2 g 4 2 i c h 4
For clarity of exposition, we shall refer to the weight of a path in a weighted graphs as its length; similarly the minimum weight of a (u , v)-path will be called the distance between u and v and denoted by d(u , v). We shall assume here that G is simple, and all weights are positive. We adopt the convention that w(uv) = if uv E.
The algorithm to be described was discovered by Dijkstra (1959). It finds not only the shortest (u 0 , v 0)-path, but shortest paths from u 0 to all other vertices in the graph (G).
Basic Idea The algorithm uses two sets of vertices, S and C. At every moment the set S contains those nodes that have already been chosen; as we shall see, the minimal distance from the source is already known for every node is S. The set C contains all the other nodes, whose minimal distance from the source is not known, and which are candidates to be chosen at some later stage. When the algorithm stops, S contains all the vertices of the graph and our problem is solved. At each step we choose the node in C whose distance to the source is least, and add it to S.
Dijkstra’s Shortest Path Algorithm l(v) - label of the vertex v 1. Set l(u 0) = 0, l(v) = for v u 0, S 0 ={u 0} and i = 0. 2. For each v not in Si, replace l(v) by min{l(v) , l(ui) + w(ui, v)}. Compute the minimum of the vertices not in Si and let ui+1 denote a vertex for which this minimum is attained. Set Si {ui+1}. 3. If i is one less than the number of vertices in a graph, stop. If i < v -1, replace i by i++ go to step 2.
Example 4 We begin at vertex 0 and modify the labels of the adjacent vertices. 0 1 2 3 4 - Ø Ø - 1 2 1 Ø 1 3 1 0 2 2 2 1 1 3 3 2
0 1 2 3 4 - Ø Ø 4 - 1 2 1 Ø - 1 2 3 1 0 2 2 2 1 1 3 3 2
0 1 2 3 4 - Ø Ø - 1 2 1 Ø - 4 1 2 2 2 3 1 0 2 2 2 1 1 3 3 2
0 1 2 3 4 - Ø Ø - 1 2 1 Ø - 4 1 2 2 2 2 3 1 0 2 2 2 1 1 3 3 2
0 1 2 3 4 - Ø Ø - 1 2 1 Ø - 4 1 2 2 2 2 3 0 2 2 2 Shortest path from d(0, 4) = 2 Path is: 0, 1, 4 1 1 1 3 3 2
- Slides: 14