Title: Shortest Paths
1Shortest 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
2Weighted Graphs
Graphs that have a number assigned to each edge
are called weighted graphs.
3Weighted Graphs
MILES
860
2534
191
1855
722
908
957
760
606
834
349
2451
1090
595
4Weighted Graphs
FARES
129
79
39
99
59
69
89
79
99
89
129
39
69
5Weighted Graphs
FLIGHT TIMES
405
210
050
255
150
210
220
155
140
245
350
200
115
130
6Weighted 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. - Dijkstras Algorithm finds the shortest path
between two vertices.
7(No Transcript)
8(No Transcript)
9(No Transcript)
10(No Transcript)
11(No Transcript)
12(No Transcript)
13(No Transcript)
14Dijkstra's Algorithm
15Dijkstra Animation
16(No Transcript)
17Unprocessed node adjacent to2 is 4. gt 1540
55 so replace with 55
18(No Transcript)
19Unprocessed node adjacent to5 is 3. 35 gt 2010
30 so replace 35 with 30
20Unprocessed node adjacent to5 is 6. gt 2050
70 so replace with 70
21Unprocessed node adjacent to5 is 7. gt 2075
95 so replace with 95
22(No Transcript)
23Unprocessed node adjacent to3 is 4. 55 lt 30 35
65 no change in array
24(No Transcript)
25Unprocessed node adjacent to4 is 6. 70 gt 55 10
65 so replace 70 with 65
26(No Transcript)
27(No Transcript)
28Unprocessed node adjacent to6 is 7. 95 gt 65 15
80 so replace 95 with 80
29(No Transcript)
30All nodes have been processed Algorithm finishes.
31Theorems
Dijkstras algorithm finds the length of a
shortest path between two vertices in a connected
simple undirected weighted graph.
Dijkstras 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.
32Problem shortest path from a to z
f
b
d
5
5
4
7
3
1
4
2
a
z
4
3
c
e
g
5
5
a b c d e f g z
0 8 8 8 8 8 8 8
x 4(a) 3(a) 8 8 8 8 8
x x