shortest-paths trees
DESCRIPTION
Shortest-Paths Trees. Kun-Mao Chao ( 趙坤茂 ) Department of Computer Science and Information Engineering National Taiwan University, Taiwan E-mail: [email protected] WWW: http://www.csie.ntu.edu.tw/~kmchao. Shortest-Paths Trees. - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Shortest-Paths Trees](https://reader035.vdocuments.net/reader035/viewer/2022062407/56812c4a550346895d90cf3c/html5/thumbnails/1.jpg)
Shortest-Paths Trees
Kun-Mao Chao (趙坤茂 )Department of Computer Science an
d Information EngineeringNational Taiwan University, Taiwan
E-mail: [email protected]
WWW: http://www.csie.ntu.edu.tw/~kmchao
![Page 2: Shortest-Paths Trees](https://reader035.vdocuments.net/reader035/viewer/2022062407/56812c4a550346895d90cf3c/html5/thumbnails/2.jpg)
2
Shortest-Paths Trees
• The objective is to find the set of edges connecting all nodes such that the sum of the edge lengths from the source to each node is minimized.
• In order to minimize the total path lengths, the path from the source to each node must be a shortest path connecting them.
![Page 3: Shortest-Paths Trees](https://reader035.vdocuments.net/reader035/viewer/2022062407/56812c4a550346895d90cf3c/html5/thumbnails/3.jpg)
3
Shortest-Paths Trees
4 3
4
1
1
5
2
1 1
2
a b c
d
e f
g h
2
4 3
4
1
1
5
2
1 1
2
a b c
d
e f
g h
2
(a) (b)
![Page 4: Shortest-Paths Trees](https://reader035.vdocuments.net/reader035/viewer/2022062407/56812c4a550346895d90cf3c/html5/thumbnails/4.jpg)
4
Negative edges in an undirected graph
4 3
4
1
1
5
2
-1 1
2
a b c
d
e f
g h
2
![Page 5: Shortest-Paths Trees](https://reader035.vdocuments.net/reader035/viewer/2022062407/56812c4a550346895d90cf3c/html5/thumbnails/5.jpg)
5
Directed graphs
4 3
4
1
1
5
2
1 1
1
a b c
d
e f
g h
2
![Page 6: Shortest-Paths Trees](https://reader035.vdocuments.net/reader035/viewer/2022062407/56812c4a550346895d90cf3c/html5/thumbnails/6.jpg)
6
Dijkstra's Algorithm
![Page 7: Shortest-Paths Trees](https://reader035.vdocuments.net/reader035/viewer/2022062407/56812c4a550346895d90cf3c/html5/thumbnails/7.jpg)
7
Choose a
4 3
4
1
15
2
1
1
1
a b c
d
e f
g h
2
0 ∞ ∞
∞
∞ ∞
∞∞
![Page 8: Shortest-Paths Trees](https://reader035.vdocuments.net/reader035/viewer/2022062407/56812c4a550346895d90cf3c/html5/thumbnails/8.jpg)
8
Relax (a, b) and (a, g)
4 3
4
1
15
2
1
1
1
a b c
d
e f
g h
2
0 4
5
∞
∞
∞ ∞
∞
![Page 9: Shortest-Paths Trees](https://reader035.vdocuments.net/reader035/viewer/2022062407/56812c4a550346895d90cf3c/html5/thumbnails/9.jpg)
9
Choose b; Add (a, b) to T
4 3
4
1
15
2
1
1
1
a b c
d
e f
g h
2
0 4
5
∞
∞
∞ ∞
∞
![Page 10: Shortest-Paths Trees](https://reader035.vdocuments.net/reader035/viewer/2022062407/56812c4a550346895d90cf3c/html5/thumbnails/10.jpg)
10
Relax (b, c) and (b, d)
4 3
4
1
15
2
1
1
1
a b c
d
e f
g h
2
0 4
5
7
5
∞ ∞
∞
![Page 11: Shortest-Paths Trees](https://reader035.vdocuments.net/reader035/viewer/2022062407/56812c4a550346895d90cf3c/html5/thumbnails/11.jpg)
11
Choose g; Add (a, g) to T
4 3
4
1
15
2
1
1
1
a b c
d
e f
g h
2
0 4
5
7
5
∞ ∞
∞
![Page 12: Shortest-Paths Trees](https://reader035.vdocuments.net/reader035/viewer/2022062407/56812c4a550346895d90cf3c/html5/thumbnails/12.jpg)
12
Relax (g, e) and (g, h)
4 3
4
1
15
2
1
1
1
a b c
d
e f
g h
2
0 4
5
7
5
7 ∞
6
![Page 13: Shortest-Paths Trees](https://reader035.vdocuments.net/reader035/viewer/2022062407/56812c4a550346895d90cf3c/html5/thumbnails/13.jpg)
13
Choose d; Add (b, d) to T
4 3
4
1
15
2
1
1
1
a b c
d
e f
g h
2
0 4
5
7
5
7 ∞
6
![Page 14: Shortest-Paths Trees](https://reader035.vdocuments.net/reader035/viewer/2022062407/56812c4a550346895d90cf3c/html5/thumbnails/14.jpg)
14
Relax (d, e)
4 3
4
1
15
2
1
1
1
a b c
d
e f
g h
2
0 4
5
7
5
6 ∞
6
![Page 15: Shortest-Paths Trees](https://reader035.vdocuments.net/reader035/viewer/2022062407/56812c4a550346895d90cf3c/html5/thumbnails/15.jpg)
15
Choose h; Add (g, h) to T
4 3
4
1
15
2
1
1
1
a b c
d
e f
g h
2
0 4
5
7
5
6 ∞
6
![Page 16: Shortest-Paths Trees](https://reader035.vdocuments.net/reader035/viewer/2022062407/56812c4a550346895d90cf3c/html5/thumbnails/16.jpg)
16
Choose e; Add (d, e) to T
4 3
4
1
15
2
1
1
1
a b c
d
e f
g h
2
0 4
5
7
5
6 ∞
6
![Page 17: Shortest-Paths Trees](https://reader035.vdocuments.net/reader035/viewer/2022062407/56812c4a550346895d90cf3c/html5/thumbnails/17.jpg)
17
Relax (e, f)
4 3
4
1
15
2
1
1
1
a b c
d
e f
g h
2
0 4
5
7
5
6 7
6
![Page 18: Shortest-Paths Trees](https://reader035.vdocuments.net/reader035/viewer/2022062407/56812c4a550346895d90cf3c/html5/thumbnails/18.jpg)
18
Choose c; Add (b, c) to T
4 3
4
1
15
2
1
1
1
a b c
d
e f
g h
2
0 4
5
7
5
6 7
6
![Page 19: Shortest-Paths Trees](https://reader035.vdocuments.net/reader035/viewer/2022062407/56812c4a550346895d90cf3c/html5/thumbnails/19.jpg)
19
Relax (c, h)
4 3
4
1
15
2
1
1
1
a b c
d
e f
g h
2
0 4
5
7
5
6 7
6
![Page 20: Shortest-Paths Trees](https://reader035.vdocuments.net/reader035/viewer/2022062407/56812c4a550346895d90cf3c/html5/thumbnails/20.jpg)
20
Choose f; Add (e, f) to T
4 3
4
1
15
2
1
1
1
a b c
d
e f
g h
2
0 4
5
7
5
6 7
6
![Page 21: Shortest-Paths Trees](https://reader035.vdocuments.net/reader035/viewer/2022062407/56812c4a550346895d90cf3c/html5/thumbnails/21.jpg)
21
Relax (f, d) and (f, h)
4 3
4
1
15
2
1
1
1
a b c
d
e f
g h
2
0 4
5
7
5
6 7
6
![Page 22: Shortest-Paths Trees](https://reader035.vdocuments.net/reader035/viewer/2022062407/56812c4a550346895d90cf3c/html5/thumbnails/22.jpg)
22
The resulting SPT
4 3
1
1
5 1
1
a b c
d
e f
g h
![Page 23: Shortest-Paths Trees](https://reader035.vdocuments.net/reader035/viewer/2022062407/56812c4a550346895d90cf3c/html5/thumbnails/23.jpg)
23
Negative edge
2 2
4
1
1
5
-3
1 1
1
a b c
d
e f
g h
2
![Page 24: Shortest-Paths Trees](https://reader035.vdocuments.net/reader035/viewer/2022062407/56812c4a550346895d90cf3c/html5/thumbnails/24.jpg)
24
Choose a
2 2
4
1
15
-3
1
1
1
a b c
d
e f
g h
2
0 2 ∞
∞
∞ ∞
∞5
![Page 25: Shortest-Paths Trees](https://reader035.vdocuments.net/reader035/viewer/2022062407/56812c4a550346895d90cf3c/html5/thumbnails/25.jpg)
25
Choose b; Add (a, b) to T
2 2
4
1
15
-3
1
1
1
a b c
d
e f
g h
2
0 2 4
3
∞ ∞
∞5
![Page 26: Shortest-Paths Trees](https://reader035.vdocuments.net/reader035/viewer/2022062407/56812c4a550346895d90cf3c/html5/thumbnails/26.jpg)
26
Choose d; Add (b, d) to T
2 2
4
1
15
-3
1
1
1
a b c
d
e f
g h
2
0 2 4
3
4 ∞
∞5
![Page 27: Shortest-Paths Trees](https://reader035.vdocuments.net/reader035/viewer/2022062407/56812c4a550346895d90cf3c/html5/thumbnails/27.jpg)
27
Choose c; Add (b, c) to T
2 2
4
1
15
-3
1
1
1
a b c
d
e f
g h
2
0 2 4
3
4 ∞
85
![Page 28: Shortest-Paths Trees](https://reader035.vdocuments.net/reader035/viewer/2022062407/56812c4a550346895d90cf3c/html5/thumbnails/28.jpg)
28
Choose e; Add (d, e) to T
2 2
4
1
15
-3
1
1
1
a b c
d
e f
g h
2
0 2 4
3
4 5
85
![Page 29: Shortest-Paths Trees](https://reader035.vdocuments.net/reader035/viewer/2022062407/56812c4a550346895d90cf3c/html5/thumbnails/29.jpg)
29
Something went wrong
2 2
4
1
15
-3
1
1
1
a b c
d
e f
g h
2
0 2 4
3
4 5
65
![Page 30: Shortest-Paths Trees](https://reader035.vdocuments.net/reader035/viewer/2022062407/56812c4a550346895d90cf3c/html5/thumbnails/30.jpg)
30
A wrong SPT
2 2
1
1
5
1
a b c
d
e f
g h
1
![Page 31: Shortest-Paths Trees](https://reader035.vdocuments.net/reader035/viewer/2022062407/56812c4a550346895d90cf3c/html5/thumbnails/31.jpg)
31
A correct SPT
2 2
1
5
-3
1
a b c
d
e f
g h
2
![Page 32: Shortest-Paths Trees](https://reader035.vdocuments.net/reader035/viewer/2022062407/56812c4a550346895d90cf3c/html5/thumbnails/32.jpg)
32
The Bellman-Ford Algorithm
![Page 33: Shortest-Paths Trees](https://reader035.vdocuments.net/reader035/viewer/2022062407/56812c4a550346895d90cf3c/html5/thumbnails/33.jpg)
33
δ[b] and δ[g] modified
2 2
4
1
15
-3
1
1
1
a b c
d
e f
g h
2
0 2 ∞
∞
∞ ∞
∞5
![Page 34: Shortest-Paths Trees](https://reader035.vdocuments.net/reader035/viewer/2022062407/56812c4a550346895d90cf3c/html5/thumbnails/34.jpg)
34
δ[c], δ[d], δ[e] and δ[h] modified
2 2
4
1
15
-3
1
1
1
a b c
d
e f
g h
2
0 2 4
3
2 ∞
65
![Page 35: Shortest-Paths Trees](https://reader035.vdocuments.net/reader035/viewer/2022062407/56812c4a550346895d90cf3c/html5/thumbnails/35.jpg)
35
δ[f] modified
2 2
4
1
15
-3
1
1
1
a b c
d
e f
g h
2
0 2 4
3
2 3
65
![Page 36: Shortest-Paths Trees](https://reader035.vdocuments.net/reader035/viewer/2022062407/56812c4a550346895d90cf3c/html5/thumbnails/36.jpg)
36
δ[h] modified
2 2
4
1
15
-3
1
1
1
a b c
d
e f
g h
2
0 2 4
3
2 3
55
![Page 37: Shortest-Paths Trees](https://reader035.vdocuments.net/reader035/viewer/2022062407/56812c4a550346895d90cf3c/html5/thumbnails/37.jpg)
37
A correct SPT
2 2
4
1
15
-3
1
1
1
a b c
d
e f
g h
2
0 2 4
3
2 3
55
![Page 38: Shortest-Paths Trees](https://reader035.vdocuments.net/reader035/viewer/2022062407/56812c4a550346895d90cf3c/html5/thumbnails/38.jpg)
38
Try this in class
4 3
4
1
1
5
2
1 -3
1
a b c
d
e f
g h
2