# Lecture 6 Shortest Path Problem. s t Dynamic Programming.

## Presentation on theme: "Lecture 6 Shortest Path Problem. s t Dynamic Programming."— Presentation transcript:

Lecture 6 Shortest Path Problem

s t

Dynamic Programming

Dijkstra’s Algorithm is motivated from a way to implement of this dynamic programming.

Dynamic Programming

Lemma Proof

Theorem 2 -1 2 1

Counterexample

Smart Implementation

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.

Update Step 2 3 4 5 6 2 4 2 1 3 4 2 3 2 2 4 0      1

Choose u such that N_(u) S 1 3 4 5 6 2 4 2 1 3 4 2 3 2 2 4 0 2   

Update Step 1 2 3 4 5 6 2 4 2 1 3 4 2 3 2 2 4 6 4 3 0    The predecessor of node 3 is now node 2

Choose u Such That N_(u) S 1 24 5 6 2 4 2 1 3 4 2 3 2 2 3 6 4 0  3

Update 1 24 5 6 2 4 2 1 3 4 2 3 2 0 d(5) is not changed. 3 2 3 6 4 

Choose u s.t. N_(u) S 1 24 6 2 4 2 1 3 4 2 3 2 0 3 2 3 6 4  5

Update 1 24 6 2 4 2 1 3 4 2 3 2 0 3 2 3 6 4  5 d(4) is not changed 6

Choose u s.t. N_(u) S 1 2 6 2 4 2 1 3 4 2 3 2 0 3 2 3 6 4 5 6 4

Update 1 2 6 2 4 2 1 3 4 2 3 2 0 3 2 3 6 4 5 6 4 d(6) is not updated

Choose u s.t. N_(u) S 1 2 2 4 2 1 3 4 2 3 2 0 3 2 3 6 4 5 6 4 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

Dijkstra’s Algorithm

Lemma

Proof of Lemma s u w S T

Theorem

Counterexample 3 -1 -2 2 1

Dijkstra’s Algorithm

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.

Update Step 2 3 4 5 6 2 4 2 1 3 4 2 3 2 2 4 0      1

Choose Minimum Temporary Label 1 3 4 5 6 2 4 2 1 3 4 2 3 2 2 4 0 2   

Update Step 1 2 3 4 5 6 2 4 2 1 3 4 2 3 2 2 4 6 4 3 0    The predecessor of node 3 is now node 2

Choose Minimum Temporary Label 1 24 5 6 2 4 2 1 3 4 2 3 2 2 3 6 4 0  3

Update 1 24 5 6 2 4 2 1 3 4 2 3 2 0 d(5) is not changed. 3 2 3 6 4 

Choose Minimum Temporary Label 1 24 6 2 4 2 1 3 4 2 3 2 0 3 2 3 6 4  5

Update 1 24 6 2 4 2 1 3 4 2 3 2 0 3 2 3 6 4  5 d(4) is not changed 6

Choose Minimum Temporary Label 1 2 6 2 4 2 1 3 4 2 3 2 0 3 2 3 6 4 5 6 4

Update 1 2 6 2 4 2 1 3 4 2 3 2 0 3 2 3 6 4 5 6 4 d(6) is not updated

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 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

Dijkstra’s Algorithm with simple buckets (also known as Dial’s algorithm)

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. 01234567 1  2 3 4 5 6 Initialize buckets.

Update Step 01234567 1  2 3 4 5 6 23 2 3 4 5 6 2 4 2 1 3 4 2 3 2 2 4 0      1

Choose Minimum Temporary Label 01234567  4 5 6 23 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   

Update Step 1 2 3 4 5 6 2 4 2 1 3 4 2 3 2 2 4 6 4 3 0    01234567  4 5 6 23 3 4 5

Choose Minimum Temporary Label 1 24 5 6 2 4 2 1 3 4 2 3 2 2 3 6 4 0  3 01234567  6 3 45 Find Min by starting at the leftmost bucket and scanning right till there is a non-empty bucket.

Update 1 24 5 6 2 4 2 1 3 4 2 3 2 0 3 2 3 6 4  01234567  6 3 45

Choose Minimum Temporary Label 1 24 6 2 4 2 1 3 4 2 3 2 0 3 2 3 6 4  5 01234567  6 45

Update 1 24 6 2 4 2 1 3 4 2 3 2 0 3 2 3 6 4  5 6 01234567  6 45 6

Choose Minimum Temporary Label 1 2 6 2 4 2 1 3 4 2 3 2 0 3 2 3 6 4 5 6 4 01234567 4 6

Update 1 2 6 2 4 2 1 3 4 2 3 2 0 3 2 3 6 4 5 6 4 01234567 4 6

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 01234567 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

Implementations With min-priority queue, Dijkstra algorithm can be implemented in time With Fibonacci heap, Dijkstra algorithm can be implemented in time With Radix heap, Dijkstra algorithm can be implemented in time