1 / 32

Shortest Paths

Shortest Paths. Text Discrete Mathematics and Its Applications (5 th Edition) Kenneth H. Rosen Chapter 8.6 Based on slides from Chuck Allison, Michael T. Goodrich, and Roberto Tamassia By Longin Jan Latecki. BOS. NY. CHI. SF. DEN. ATL. LA. MIA. Weighted Graphs.

Download Presentation

Shortest Paths

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Shortest Paths Text Discrete Mathematics and Its Applications(5th Edition) Kenneth H. Rosen Chapter 8.6 Based on slides from Chuck Allison, Michael T. Goodrich, and Roberto Tamassia By Longin Jan Latecki

  2. BOS NY CHI SF DEN ATL LA MIA Weighted Graphs Graphs that have a number assigned to each edge are called weighted graphs.

  3. BOS NY CHI SF DEN ATL LA MIA Weighted Graphs MILES 860 2534 191 1855 722 908 957 760 606 834 349 2451 1090 595

  4. BOS NY CHI SF DEN ATL LA MIA Weighted Graphs FARES $129 $79 $39 $99 $59 $69 $89 $79 $99 $89 $39 $129 $69

  5. BOS NY CHI SF DEN ATL LA MIA Weighted Graphs FLIGHT TIMES 4:05 2:10 0:50 2:55 1:50 2:10 2:20 1:55 1:40 2:45 2:00 3:50 1:15 1:30

  6. Weighted Graphs • A weighted graph is a graph in which each edge (u, v) has a weight w(u, v). Each weight is a real number. • Weights can represent distance, cost, time, capacity, etc. • The length of a path in a weighted graph is the sum of the weights on the edges. • Dijkstra’s Algorithm finds the shortest path between two vertices.

  7. Dijkstra's Algorithm

  8. Dijkstra Animation • Demo

  9. processed: 1 0 0 0 0 0 0 fromNode: 1 1 1 distance: 0 15 35 # 20 # # index: 1 2 3 4 5 6 7 1 20 15 5 IndexOfMin 35 75 10 2 3 7 50 40 35 15 4 6 10

  10. processed: 1 1 0 0 0 0 0 fromNode: 1 1 1 distance: 0 15 35 # 20 # # index: 1 2 3 4 5 6 7 1 20 15 5 35 75 10 2 3 7 50 40 35 15 4 6 10 Unprocessed node adjacent to2 is 4. # > 15+40 = 55 so replace # with 55

  11. processed: 1 1 0 0 0 0 0 fromNode: 1 1 2 1 distance: 0 15 35 55 20 # # index: 1 2 3 4 5 6 7 1 20 15 5 IndexOfMin 35 75 10 2 3 7 50 40 35 15 4 6 10

  12. processed: 1 1 0 0 1 0 0 fromNode: 1 1 2 1 distance: 0 15 35 55 20 # # index: 1 2 3 4 5 6 7 1 20 15 5 IndexOfMin 35 75 10 2 3 7 50 40 35 15 4 6 10 Unprocessed node adjacent to5 is 3. 35 > 20+10 = 30 so replace 35 with 30

  13. processed: 1 1 0 0 1 0 0 fromNode: 1 5 2 1 distance: 0 15 30 55 20 # # index: 1 2 3 4 5 6 7 1 20 15 5 IndexOfMin 35 75 10 2 3 7 50 40 35 15 4 6 10 Unprocessed node adjacent to5 is 6. # > 20+50 = 70 so replace # with 70

  14. processed: 1 1 0 0 1 0 0 fromNode: 1 5 2 1 5 distance: 0 15 30 55 20 70 # index: 1 2 3 4 5 6 7 1 20 15 5 IndexOfMin 35 75 10 2 3 7 50 40 35 15 4 6 10 Unprocessed node adjacent to5 is 7. # > 20+75 = 95 so replace # with 95

  15. processed: 1 1 0 0 1 0 0 fromNode: 1 5 2 1 5 5 distance: 0 15 30 55 20 70 95 index: 1 2 3 4 5 6 7 1 20 15 5 IndexOfMin 35 75 10 2 3 7 50 40 35 15 4 6 10

  16. processed: 1 11 0 1 0 0 fromNode: 1 5 2 1 5 5 distance: 0 15 30 55 20 70 95 index: 1 2 3 4 5 6 7 1 20 15 5 IndexOfMin 35 75 10 2 3 7 50 40 35 15 4 6 10 Unprocessed node adjacent to3 is 4. 55 < 30 + 35 = 65 no change in array

  17. processed: 1 11 0 1 0 0 fromNode: 1 5 2 1 5 5 distance: 0 15 30 55 20 70 95 index: 1 2 3 4 5 6 7 1 20 15 5 IndexOfMin 35 75 10 2 3 7 50 40 35 15 4 6 10

  18. processed: 1 1111 0 0 fromNode: 1 5 2 1 5 5 distance: 0 15 30 55 20 70 95 index: 1 2 3 4 5 6 7 1 20 15 5 IndexOfMin 35 75 10 2 3 7 50 40 35 15 4 6 10 Unprocessed node adjacent to4 is 6. 70 > 55 + 10 = 65 so replace 70 with 65

  19. processed: 1 1111 0 0 fromNode: 1 5 2 1 4 5 distance: 0 15 30 55 20 65 95 index: 1 2 3 4 5 6 7 1 20 15 5 IndexOfMin 35 75 10 2 3 7 50 40 35 15 4 6 10

  20. processed: 1 1111 0 0 fromNode: 1 5 2 1 4 5 distance: 0 15 30 55 20 65 95 index: 1 2 3 4 5 6 7 1 20 15 5 IndexOfMin 35 75 10 2 3 7 50 40 35 15 4 6 10

  21. processed: 1 11111 0 fromNode: 1 5 2 1 4 5 distance: 0 15 30 55 20 65 95 index: 1 2 3 4 5 6 7 1 20 15 5 IndexOfMin 35 75 10 2 3 7 50 40 35 15 4 6 10 Unprocessed node adjacent to6 is 7. 95 > 65 + 15 = 80 so replace 95 with 80

  22. processed: 1 11111 0 fromNode: 1 5 2 1 4 6 distance: 0 15 30 55 20 65 80 index: 1 2 3 4 5 6 7 1 20 15 IndexOfMin 5 35 75 10 2 3 7 50 40 35 15 4 6 10

  23. processed: 1 111111 fromNode: 1 5 2 1 4 6 distance: 0 15 30 55 20 65 80 index: 1 2 3 4 5 6 7 1 20 15 IndexOfMin 5 35 75 10 2 3 7 50 40 35 15 4 6 10 All nodes have been processed Algorithm finishes.

  24. Theorems Dijkstra’s algorithm finds the length of a shortest path between two vertices in a connected simple undirected weighted graph. Dijkstra’s algorithm uses O(n2) operations (additions and comparisons) to find the length of the shortest path between two vertices in a connected simple undirected weighted graph.

  25. Problem: shortest path from a to z f b d 5 5 4 7 3 4 1 2 a z 3 4 c 5 e 5 g

More Related