Algo Dijkstra Basics Typed
Algo Dijkstra Basics Typed
Primi*ves
Dijkstras
Algorithm:
The
Basics
Length of path
= sum of edge lengths
Path length = 6
Tim Roughgarden
Source
vertex
Dijkstras Algorithm
This array
only to help
explanation!
Ini*alize:
X
=
[s]
[ver*ces
processed
so
far]
A[s]
=
0
[computed
shortest
path
distances]
B[s]
=
empty
path
[computed
shortest
paths]
Main
Loop
while
XV:
-need
to
grow
x
by
one
node
Tim Roughgarden
Example
Dijkstras greedy
score for (v, w):
A[v] + lvw
Tim Roughgarden
Non-Example
Question: why not reduce computing shortest paths with negative
edge lengths to the same problem with non negative lengths? (by
adding large constant to edge lengths)
Problem: doesnt preserve shortest paths !
Also: Dijkstras algorithm incorrect on this graph !
(computes shortest s-t distance to be -2 rather than -4)
Tim
Roughgarden