Slides4_5_color - Lecture 4/5 Shortest Path Problems...

Info iconThis preview shows pages 1–7. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Lecture 4/5 Shortest Path Problems Example Following your suggestions (based on MST), the executive board of your company built the connecting wires between the cities. However, they chose to include additional power lines (to have a reliable network). Now they approach you again hoping to get an answer for a somewhat different problem: A power plant has been built in Albany, and the produced power should be sent to Trenton. But there are different ways to achieve this in the constructed network. The specific question is: What is the shortest path in the network from Albany to Trenton?
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 Example 1 1 2 3 4 5 6 3 3 2 3 4 2 2 Albany Trenton (see Winston, Example 1, page 414) Given a graph with edge weights c ij 0. Find a shortest path from node 1 to node 6. Solution: Dijkstra’s algorithm Idea: Instead of computing the shortest path from node 1 to 6, we compute all shortest paths from node 1 to node i (i=2,. .,6).
Background image of page 2
3 Dijkstra’s algorithm (1) 1. (Initialization): Label all nodes incident to node 1 with a temporary label equal to their distance to 1. Node 1 gets a permanent label 0. All other nodes get the temporary label . Choose the least label (say for node i) and make the label permanent. 2. For each node j connected to i with no permanent label do the following: Replace the label of j by: min{label(j), label(i)+c ij } 3. Make the label of the node with the least temporary label permanent. Call this node (internally) i, and go to step 2. Dijkstra’s algorithm: Example 1 1 2 3 4 5 6 3 3 2 3 4 2 2 3 4 0 Init:
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4 Dijkstra’s algorithm: Example 1 1 2 3 4 5 6 3 3 2 3 4 2 2 3 4 6 0 Step 1: Dijkstra’s algorithm: Example 1 1 2 3 4 5 6 3 3 2 3 4 2 2 3 4 7 6 0 Step 2:
Background image of page 4
5 Dijkstra’s algorithm: Example 1 1 2 3 4 5 6 3 3 2 3 4 2 2 3 4 7 6 8 0 Step 3: Dijkstra’s algorithm: Example 1 1 2 3 4 5 6 3 3 2 3 4 2 2 3 4 7 6 8 0 Step 4:
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
6 Dijkstra’s algorithm: Example 1 1 2 3 4 5 6 3 3 2 3 4 2 2 3 4 7 6 8 0 Step 5: Dijkstra’s algorithm: Remark So, now we know that the lenght of the shortest path from node 1 to node 6 is 8 , but what nodes do we actually have to visit to get to node 6 on this shortest path? For this purpose you need to store one additional value for each node. Namely, whenever your update min{label(j), label(i)+c ij } yields label(i)+c ij , then you should store the value i. Because this tells you (you will see this later) that node i is the node on the shortest path to j that is visited immediately before j. At the end, you can follow this way backwards from node 6 to node 1.
Background image of page 6
Image of page 7
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 19

Slides4_5_color - Lecture 4/5 Shortest Path Problems...

This preview shows document pages 1 - 7. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online