Shortest Paths: Discrete Mathematics and Its Applications
Shortest Paths: Discrete Mathematics and Its Applications
Text
Kenneth H. Rosen
Chapter 9.6
Based on slides from Chuck Allison,
Michael T. Goodrich, and Roberto Tamassia
Weighted Graphs
Graphs that have a number assigned to
each edge are called weighted graphs.
BOS
NY
CHI
SF
DEN
ATL
LA
MIA
Weighted Graphs
MILES
BOS
1855
349
LA
83
DEN
NY
908
606
2451
ATL
595
MIA
1090
957
722
CHI
760
SF
191
86 0
2534
Weighted Graphs
FARES
BOS
SF
$89
$39
$69
$12 9
$59
ATL
$69
LA
$8 9
DEN
CHI
$79
$99
MIA
$39
NY
$99
$79
$129
Weighted Graphs
FLIGHT
TIMES
BOS
4:05
2:55
1:15
2:10
3:50
1:4
ATL
1: 3
LA
2:00
DEN
1:50
MIA
2:45
2:20
CHI
0:50
NY
1:55
SF
2:10
Weighted Graphs
Dijkstra's Algorithm
Dijkstra Animation
Demo
b 5
4
a
d 5
1
4
c
e 5
4(a) 3(a)
a,c
15(1)
35(1)
20(1)
1,2
20
15
35
10
2
3
40
35
75
50
15
4
10
Theorems
Dijkstras algorithm finds the length of a shortest
path between two vertices in a connected simple
undirected weighted graph G=(V,E).
The time required by Dijkstra's algorithm is O(|V|2).
It will be reduced to O(|E|log|V|) if heap is used to keep
{vV\Si : L(v) < }, where Si is the set S after iteration i.
traveling salesman wants to visit a number of cities and then return to his
starting point. Of course he wants to save time and energy, so he wants to
determine the shortest cycle for his trip.
We
can represent the cities and the distances between them by a weighted,
complete, undirected graph.
The
problem then is to find the shortest cycle (of minimum total weight
that visits each vertex exactly one).
Finding
Importance:
40
25
35
50
40
50
4
45
65
30
80
Home
Solution approaches
Enumeration of all possible cycles.
This results in (m-1)! cycles to enumerate for a graph with m
nodes.
Only small problems can be solved with this approach.
Possible cycles
Cycle
Total Cost
1. H-O1-O2-O3-O4-H
2. H-O1-O2-O4-O3-H
3. H-O1-O3-O2-O3-H
4. H-O1-O3-O4-O2-H
For this problem we have
5. H-O1-O4-O2-O3-H
6. H-O1-O4-O3-O2-H(5-1)! / 2 = 12 cycles.
7. H-O2-O3-O1-O4-HSymmetrical problems
8. H-O2-O1-O3-O4-Hneed to enumerate only
9. H-O2-O4-O1-O3-H(m-1)! / 2 cycles.
10. H-O2-O1-O4-O3-H
11. H-O3-O1-O2-O4-H
12. H-O3-O1-O2-O4-H
210
195
240
200
225
200
265
235
250
220
260
260
Minimum
2
25
40
50
40
50
30
45
35
4
65
80
Home