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 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.
Shortest-Paths Trees
Negative edges in an undirected graph
Directed graphs
Dijkstra's Algorithm
Choose a
Relax (a, b) and (a, g)
Choose b; Add (a, b) to T
Relax (b, c) and (b, d)
Choose g; Add (a, g) to T
Relax (g, e) and (g, h)
Choose d; Add (b, d) to T
Relax (d, e)
Choose h; Add (g, h) to T
Choose e; Add (d, e) to T
Relax (e, f)
Choose c; Add (b, c) to T
Relax (c, h)
Choose f; Add (e, f) to T
Relax (f, d) and (f, h)
The resulting SPT
Negative edge
Choose a
Choose b; Add (a, b) to T
Choose d; Add (b, d) to T
Choose c; Add (b, c) to T
Choose e; Add (d, e) to T
Something went wrong
A wrong SPT
A correct SPT
The Bellman-Ford Algorithm
δ[b] and δ[g] modified
δ[c], δ[d], δ[e] and δ[h] modified
δ[f] modified
δ[h] modified
A correct SPT
Try this in class