Download presentation
Presentation is loading. Please wait.
Published byBryanna Farnsworth Modified over 9 years ago
1
Lecture 6 Shortest Path Problem
2
s t
3
Dynamic Programming
4
Dijkstra’s Algorithm is motivated from a way to implement of this dynamic programming.
5
Dynamic Programming
6
Lemma Proof
7
Theorem 2 -1 2 1
8
Counterexample
9
Smart Implementation
10
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.
11
Update Step 2 3 4 5 6 2 4 2 1 3 4 2 3 2 2 4 0 1
12
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
13
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
14
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
15
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
16
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
17
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
18
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
19
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
20
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
21
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
22
Dijkstra’s Algorithm
24
Lemma
26
Proof of Lemma s u w S T
27
Theorem
28
Counterexample 3 -1 -2 2 1
37
Dijkstra’s Algorithm
38
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.
39
Update Step 2 3 4 5 6 2 4 2 1 3 4 2 3 2 2 4 0 1
40
Choose Minimum Temporary Label 1 3 4 5 6 2 4 2 1 3 4 2 3 2 2 4 0 2
41
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
42
Choose Minimum Temporary Label 1 24 5 6 2 4 2 1 3 4 2 3 2 2 3 6 4 0 3
43
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
44
Choose Minimum Temporary Label 1 24 6 2 4 2 1 3 4 2 3 2 0 3 2 3 6 4 5
45
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
46
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
47
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
48
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
49
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
60
Dijkstra’s Algorithm with simple buckets (also known as Dial’s algorithm)
61
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.
62
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
63
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
64
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
65
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.
66
Update 1 24 5 6 2 4 2 1 3 4 2 3 2 0 3 2 3 6 4 01234567 6 3 45
67
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
68
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
69
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
70
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
71
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
72
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
76
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
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.