ShortestPaths Trees KunMao Chao Department of Computer Science

  • Slides: 38
Download presentation
Shortest-Paths Trees Kun-Mao Chao (趙坤茂) Department of Computer Science and Information Engineering National Taiwan

Shortest-Paths Trees Kun-Mao Chao (趙坤茂) Department of Computer Science and Information Engineering National Taiwan University, Taiwan E-mail: kmchao@csie. ntu. edu. tw WWW: http: //www. csie. ntu. edu. tw/~kmchao

Shortest-Paths Trees • The objective is to find the set of edges connecting all

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. 2

Shortest-Paths Trees (source: vertex a) 3

Shortest-Paths Trees (source: vertex a) 3

Negative edges in an undirected graph 4

Negative edges in an undirected graph 4

Directed graphs 5

Directed graphs 5

Dijkstra's Algorithm 6

Dijkstra's Algorithm 6

Choose a 7

Choose a 7

Relax (a, b) and (a, g) 8

Relax (a, b) and (a, g) 8

Choose b; Add (a, b) to T 9

Choose b; Add (a, b) to T 9

Relax (b, c) and (b, d) 10

Relax (b, c) and (b, d) 10

Choose g; Add (a, g) to T 11

Choose g; Add (a, g) to T 11

Relax (g, e) and (g, h) 12

Relax (g, e) and (g, h) 12

Choose d; Add (b, d) to T 13

Choose d; Add (b, d) to T 13

Relax (d, e) 14

Relax (d, e) 14

Choose h; Add (g, h) to T 15

Choose h; Add (g, h) to T 15

Choose e; Add (d, e) to T 16

Choose e; Add (d, e) to T 16

Relax (e, f) 17

Relax (e, f) 17

Choose c; Add (b, c) to T 18

Choose c; Add (b, c) to T 18

Relax (c, h) 19

Relax (c, h) 19

Choose f; Add (e, f) to T 20

Choose f; Add (e, f) to T 20

Relax (f, d) and (f, h) 21

Relax (f, d) and (f, h) 21

The resulting SPT 22

The resulting SPT 22

Negative edge 23

Negative edge 23

Choose a 24

Choose a 24

Choose b; Add (a, b) to T 25

Choose b; Add (a, b) to T 25

Choose d; Add (b, d) to T 26

Choose d; Add (b, d) to T 26

Choose c; Add (b, c) to T 27

Choose c; Add (b, c) to T 27

Choose e; Add (d, e) to T 28

Choose e; Add (d, e) to T 28

Something went wrong 29

Something went wrong 29

A wrong SPT 30

A wrong SPT 30

A correct SPT 31

A correct SPT 31

The Bellman-Ford Algorithm 32

The Bellman-Ford Algorithm 32

δ[b] and δ[g] modified 33

δ[b] and δ[g] modified 33

δ[c], δ[d], δ[e] and δ[h] modified 34

δ[c], δ[d], δ[e] and δ[h] modified 34

δ[f] modified 35

δ[f] modified 35

δ[h] modified 36

δ[h] modified 36

A correct SPT 37

A correct SPT 37

Try this in class 38

Try this in class 38