Paths: Friday, September 21, 2012
Paths: Friday, September 21, 2012
10
7
B
5
3
10
7
C
15
4
D
6 3 F
Why is it a tree?
1 4
0
1 3
2 G
B
D
6
10 3 10
Topological order
(i, j) ∈ A ⇒ i < j
2 7 6
2
5
6
1 4
10 3 10
6
7
P[1]←1; d[1]←0;
for i←1,…,n-1 do
foreach (i,j) ∈ FS(i) do
if d[i]+cij < d[j] then P[j]← i
d[j] ← d[i]+cij
H doors and 8
windows
I wiring 2
J paint 3
0 discard object i
i − 1, k i, k
ci
i, k + ai select object i
http://www.dgp.toronto.edu/people/JamesStewart/
270/9798s/Laffra/DijkstraApplet.html
http://www.cs.utexas.edu/users/EWD/
-10
-6
1 -2 4 6
3
-5
3 4
3
Warning
What happens to Dijkstra algorithm with negative cost cycles?
What happens if we apply it to a graph without negative cost
cycles but with some negative cost arcs?