Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 4: Finding the Shortest Path Lesson 1: Dijkstra’s Algorithm

Similar presentations


Presentation on theme: "Chapter 4: Finding the Shortest Path Lesson 1: Dijkstra’s Algorithm"— Presentation transcript:

1 Chapter 4: Finding the Shortest Path Lesson 1: Dijkstra’s Algorithm
Discrete Maths Chapter 4: Finding the Shortest Path Lesson 1: Dijkstra’s Algorithm

2 EXAMPLE 1: Find the shortest path from A to G

3 Dijkstra’s Algorithm Dijkstra’s algorithm is used in problems relating to finding the shortest path. Each node is given a temporary label denoting the length of the shortest path from the start node so far. This label is replaced if another shorter route is found. Once it is certain that no other shorter paths can be found, the temporary label becomes a permanent label. Eventually all the nodes have permanent labels. At this point the shortest path is found by retracing the path backwards.

4 Dijkstra’s Algorithm Aim: To find the shortest path connecting two nodes Step 1: Label the start node with zero and box this label. Step 2: Consider the node with the most recently boxed label. Suppose this node to be X and let D be its permanent label. Then, in turn, consider each node directly joined to X but not yet permanently boxed. For each such node, Y say, temporarily label it with the lesser of D + (the weight of arc XY) and its existing label (if any). Step 3: Choose the least of all temporary labels on the network. Make this label permanent by boxing it. Step 4: Repeat Steps 2 and 3 until the destination node has a permanent label. Step 5: Go backwards through the network, retracing the path of shortest length from the destination node to the start node.

5 EXAMPLE 1: Find the shortest path from A to G
3 5 2 3 3 5 4 6 1 8 / 7 / 6 7 17 19 / 18 / 17 5 9 6 14 12 / 9 15 / 14

6 EXAMPLE 2: Find the shortest path from A to G
3 6 6 6 16 5 11 16 15 / 14 / 11 1 7 18 2 3 4 8 28 / 20 / 18 3 8

7 EXAMPLE 3: Find the shortest path from A to D
4 15 2 8 15 8 6 24 1 25 / 24 3 15 5 20 15 20

8 EXAMPLE 1: Find the shortest path from A to G

9 EXAMPLE 2: Find the shortest path from A to G

10 EXAMPLE 3: Find the shortest path from A to D


Download ppt "Chapter 4: Finding the Shortest Path Lesson 1: Dijkstra’s Algorithm"

Similar presentations


Ads by Google