Download presentation
Presentation is loading. Please wait.
Published byГавриил Марков Modified over 5 years ago
1
Discrete Mathematics and Its Applications (5th Edition)
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
Weighted Graphs Graphs that have a number assigned to each edge are called weighted graphs. SF LA DEN CHI ATL MIA BOS NY
3
Weighted Graphs MILES SF LA DEN CHI ATL MIA BOS NY 860 2534 191 1855
722 908 957 760 606 834 349 2451 1090 595
4
Weighted Graphs FARES SF LA DEN CHI ATL MIA BOS NY $129 $79 $39 $99
$59 $69 $89 $79 $99 $89 $39 $129 $69
5
Weighted Graphs FLIGHT TIMES SF LA DEN CHI ATL MIA BOS NY 4:05 2:10
0:50 2:55 1:50 2:10 2:20 1:55 1:40 2:00 3:50 2:45 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.
14
Dijkstra's Algorithm
15
Dijkstra Animation Demo
16
processed: fromNode: distance: # # # index: IndexOfMin 1 5 7 2 3 4 6 20 40 15 35 10 50 75
17
processed: fromNode: distance: # # # index: 1 5 7 2 3 4 6 20 40 15 35 10 50 75 Unprocessed node adjacent to 2 is 4. # > = 55 so replace # with 55
18
processed: fromNode: distance: # # index: IndexOfMin 1 5 7 2 3 4 6 20 40 15 35 10 50 75
19
processed: fromNode: distance: # # index: IndexOfMin 1 5 7 2 3 4 6 20 40 15 35 10 50 75 Unprocessed node adjacent to 5 is 3. 35 > = 30 so replace 35 with 30
20
processed: fromNode: distance: # # index: IndexOfMin 1 5 7 2 3 4 6 20 40 15 35 10 50 75 Unprocessed node adjacent to 5 is 6. # > = 70 so replace # with 70
21
processed: fromNode: distance: # index: IndexOfMin 1 5 7 2 3 4 6 20 40 15 35 10 50 75 Unprocessed node adjacent to 5 is 7. # > = 95 so replace # with 95
22
processed: fromNode: distance: index: IndexOfMin 1 5 7 2 3 4 6 20 40 15 35 10 50 75
23
processed: fromNode: distance: index: IndexOfMin 1 5 7 2 3 4 6 20 40 15 35 10 50 75 Unprocessed node adjacent to 3 is 4. 55 < = 65 no change in array
24
processed: fromNode: distance: index: IndexOfMin 1 5 7 2 3 4 6 20 40 15 35 10 50 75
25
processed: fromNode: distance: index: IndexOfMin 1 5 7 2 3 4 6 20 40 15 35 10 50 75 Unprocessed node adjacent to 4 is 6. 70 > = 65 so replace 70 with 65
26
processed: fromNode: distance: index: IndexOfMin 1 5 7 2 3 4 6 20 40 15 35 10 50 75
27
processed: fromNode: distance: index: IndexOfMin 1 5 7 2 3 4 6 20 40 15 35 10 50 75
28
processed: fromNode: distance: index: IndexOfMin 1 5 7 2 3 4 6 20 40 15 35 10 50 75 Unprocessed node adjacent to 6 is 7. 95 > = 80 so replace 95 with 80
29
processed: fromNode: distance: index: IndexOfMin 1 5 7 2 3 4 6 20 40 15 35 10 50 75
30
processed: fromNode: distance: index: IndexOfMin 1 5 7 2 3 4 6 20 40 15 35 10 50 75 All nodes have been processed Algorithm finishes.
31
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.
32
Problem f b d 5 5 4 7 3 4 1 2 a z 3 4 c 5 e 5 g
33
finished
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.