Download as pdf
Download as pdf
You are on page 1of 5
2. Shortest-Path Problems Many problem can be modeled using graphs with weights assigned to their edges. As an illustration, consider how an airline system can be modeled. We set up the basic graph model by representing cities by vertices and flight by edges. Problem involving distances can be modeled by assigning distances between cities to the edges. Problem involving fares can be modeled by assigning fares to the edges. Definition 2.1. Weighted Graph: A graph each of whose edges bears a weight is called weighted graph. Weight of the path: ‘The sum of the weights of all the edges in a path is called weight of the path. Shortest Path between two vertices: Among all paths connecting two vertices u and v, the path having the minimum weight is called shortest path between u and v. Several types of problems involving weighted graphs arises frequently. One such prob- lem is to find out the shortest path between vertices. For instance, in the airline system represented by the weighted graph shown in the figure, what is the shortest path in air distance between Boston and Los Angeles? What is the cheapest fare between these two: cities? A Shortest-Path Problem Algorithm: There are several different algorithms that find a shortest path betwoen two vertices in a weighted graph. We will discuss an algorithm discovered by the Duch mathematician Edsger Dijkstra in 1959. Dijkstra’s Algorithm: This algorithm computes a single-source shortest path from a graph G = (V,B) with non-negative edge weights. Step 1: Discard all selloops, if any. Stop 2: If G has parallel edges betwoon any two vertices, then discard them all except the one with least: we Step 3: Assign label 0 to the initial vertex (permanent label) and assign label oo to all other remaining vertices (temporary label). Step 4: Reassign each vertex which is in temporary label with again a temporary label L(v) by the following rule Lv) = minfold L(v), L(x) +(x, )} ‘the weight of the edge where 1 is the permanent vertex in the previous stage and w Step 5: The smallest among all temporary labels is marks as permanent. In case of tie, select: any one. Step 6: Repeat steps 4 and 6 until the terminal vertex is permanently assigned. ‘The shortest path is found by backward technique: Starting at the permanent label of the destination vertex we go back along the previously assigned temporary label of the vertex until we get a change. Next we move to the vertex which is newly labelled permanently, then do a similar backtrack along its previously assigned temporary labels until we find a change and so on. the vertices fond in this way give us the shortest path. Example 2.2. Find the shortest path from the vertex a to f in the following graph using Dijkstra's algorithm: Here a is the initial vertex and f is the terminal vertex. ‘This graph has self loop at a, so discard this first. Also the graph has parallel edges between c and ¢, One edge having maximum weight 12 is deleted. The algorithm is displayed in the following table. é © a © i [Resuck ~ = = ~ ce | Hee inital ertcx ee permanently Inbal 0. Oren: are temporarily alle oo. of aitccor a |mintenor af a = we _| teste sage the vor es permancnalylabled 2 “4 2 ss minim abl aang ll the tempor able wert in thi rom: of mma] 2 = info ce [te itiesage 6 parmancaty net 3 2 2 ofa 2 fminfae-e) | in(i2.0 8) | co | Inshie stage permanently labeled 8 ‘ein 12) 10 minfs.8 6) =u Te this mage «permanently abled 1 0 1013 a1 To hie sags J permanently Lala 3 Weight of the shortest path is 13. To find shortest path first start from the destination vertex f. In last stage f is assigned 13. If we go back upward along the column f, this 13 is changed to 14 in the previous stage and in this stage ¢ is labelled. So select e. Similarly L(e) = 10 is changed to 11 in its previous stage and in this stage d is assigned. Therefore next vertex will be d. By similar manner next vertex will be 6 and then c and then a. ‘Therefore required shortest path is a —b-d-e-f.

You might also like