Lec 11 - Graph Algorithms
Lec 11 - Graph Algorithms
V d π
S 0 NIL
Q = {s , t , y , x , z} T NIL
S= Y NIL
X NIL
z NIL
V d π
S 0 NIL
Extract-MIN(Q) s T
10 S
NIL
Q = {s, t , y , x , z} Y
5 S
NIL
S = {s} X NIL
z NIL
V d π
Extract-MIN(Q) y S 0 NIL
Q = { y, t , x, z } T 8
10 Y
S
S = {s, y} Y 5 S
X
14 Y
NIL
Zz
7 Y
NIL
V d π
Extract-MIN(Q) z S 0 NIL
Q = { z, t , x } T 8 Yy
S = {s, y, z} Y 5 S
X 13
14 YZ
z 7 Yy
V d π
Extract-MIN(Q) t S 0 NIL
Q = { t , x} T 8 y
S = {s, y, z, t} Y 5 S
X 9
13 ZT
z 7 y
V d π
Extract-MIN(Q) x S 0 NIL
Q={x} T 8 y
S = {s, y, z, t, x} Y 5 S
X 9 T
z 7 y
O(V lg V)
The total running time is
O(V lg V)
O(E lg V)
V
in the typical case that
E O(E lg V)
E = Ω (V)
O(lg V)
▪ The goal is to find, for every pair of vertices u,v ϵ V , a shortest (least-weight)
path from u to v.
O(VE lg V).
▪Is there an algorithm that guarantee a much better asymptotic running time??
Example :
Because for any path, all intermediate vertices belong to the set {1, 2, … , n) ,
the matrix D(n) = dij(n) gives the final answer.
Example:
d3,2(1) is the min (d3,2 (0) , d3,1(0) + d1,2(0) )
∞ 12
D(1):
D(4):
D(3)
Final
Answer
O(1)
▪ The running time of the Floyd-Warshall algorithm is determined by the triply nested
for loops.
▪ The algorithm runs in Θ(n3) time.