Dynamic Programming
})(*{min )(*
Then . node to nodeorigin from
pathshortest oflength thedenote )(*Let
)(vu
uNvcvdud
us
ud
Dijkstra’s Algorithm is motivated from a way to implement of this dynamic programming.
Dynamic Programming
. if Stop
};{
}{
)},()(*{min)(* compute
.)(: find iteration,each In
.},{ Initially,
. to frompath shortest theoflength the)(* Define
)(
T
uTT
uSS
uvcvdud
SuNTu
SVTsS
usud
uNv
Lemma
S.(z)such that find ll we'Finally, forever. go
cannot process This .such that )(exist there
then,)( If .such that )(exist there
then ,)( If .)(,any for that Note
.)(such that exists Then there
. with ofpartition a is ),( Suppose . nodesink a and
node source a with ),(network acyclican Consider
NTz
TwvNw
SvNTvuNv
SuNuNTu
SuNTu
SsVTSt
sEVG
Proof
Smart Implementation
).()(*)( :markRe
. if Stop
;for )( update
}{
}{
.)(: find iteration,each In
.},{ Initially,
.for )},()(*{min)( Define)(
ududSuN
T
Twwd
uTT
uSS
SuNTu
SVTsS
TuuvcvdudSuNv
An Example
1
2
3
4
5
6
2
4
2 1
3
4
2
3
2
Initialize
1
0
Select the node with the minimum temporary distance label.
End of Algorithm
1
2
2
4
2 1
3
4
2
3
2
0
3
2
3
6
4
5
6
4
6
All nodes are now permanent
The predecessors form a tree
The shortest path from node 1 to node 6 can be found by tracing back predecessors
Dijkstra’s Algorithm
. if Stop
;for )( update
}{
}{
).(min)(: find iteration,each In
.},{ Initially,
.for )},()(*{min)( Define)(
T
Twwd
uTT
uSS
wdudTu
SVTsS
Tuuvcvdud
Tw
SuNv
Lemma
).()(*)( min)(
then e,nonnegativ are weights-arc If
. with ofpartition a is ),( Suppose . nodesink a and
node source a with ),(network aConsider
ududwdud
SsVTSt
sEVG
Tw
Lemma
).()(*)( min)(
then e,nonnegativ are weights-arc If
. with ofpartition a is ),( Suppose . nodesink a and
node source a with ),(network aConsider
ududwdud
SsVTSt
sEVG
Tw
Proof of Lemma
)(
)()(*)()()),(()(
e,nonnegativ are weights-arc all Since
. to from path of piece theis ),( where
)),(()(
Then .path on in nodefirst thebe Let
).()(*)(
such that to from path a exists Then there
).(*)(min)( suppose ion,contradictFor
plengthududwdwsplengthplength
wspwsp
wsplengthwd
pTw
ududplength
usp
udvdudTv
s
uw
S
T
An Example
1
2
3
4
5
6
2
4
2 1
3
4
2
3
2
Initialize
1
0
Select the node with the minimum temporary distance label.
End of Algorithm
1
2
2
4
2 1
3
4
2
3
2
0
3
2
3
6
4
5
6
4
6
All nodes are now permanent
The predecessors form a tree
The shortest path from node 1 to node 6 can be found by tracing back predecessors
An Example
1
2
3
4
5
6
2
4
2 1
3
4
2
3
2
Initialize distance labels
1
0
Select the node with the minimum temporary distance label.
0 1 2 3 4 5 6 7
1
23456
Initialize buckets.
Choose Minimum Temporary Label
0 1 2 3 4 5 6 7
4562 3
Find Min by starting at the leftmost bucket and scanning right till there is a non-empty bucket.
1
3
4
5
6
2
4
2 1
3
4
2
3
2
2
4
0
2
Choose Minimum Temporary Label
1
2 4
5
6
2
4
2 1
3
4
2
3
2
2
3
6
4
0
3
0 1 2 3 4 5 6 7
63 45
Find Min by starting at the leftmost bucket and scanning right till there is a non-empty bucket.
Choose Minimum Temporary Label
1
2
2
4
2 1
3
4
2
3
2
0
3
2
3
6
4
5
6
4
6
0 1 2 3 4 5 6 7
6
There is nothing to update
End of Algorithm
1
2
2
4
2 1
3
4
2
3
2
0
3
2
3
6
4
5
6
4
6
All nodes are now permanent
The predecessors form a tree
The shortest path from node 1 to node 6 can be found by tracing back predecessors