













Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!














Overview
Shortest Path – Dijkstra’s Algorithm^ Maintain
Nodes with known shortest path from start
Cost of shortest path to node K from start
Only for paths through nodes in S Predecessor to K on shortest path
Updated whenever new (lower) C[K] discovered Remembers actual path with lowest cost
Shortest Path – Intuition for Dijkstra’s^ At each step inthe algorithm
Shortest pathsare known fornodes in
Store in
length ofshortest path tonode K (for allpaths throughnodes in { S } ) Add to { S } nextclosest node
Shortest Path – Djikstra’s Algorithm^ Algorithm
Add starting node to S Repeat until all nodes in S
Find node K not in S with smallest C[ K ] Add K to S Examine C[J] for all neighbors J of K not in S
If ( C[K] + weight for edge (K,J) ) < C[J]
New shortest path by first going to K, then J Update C[J]
←←←←^
C[K] + weight for edge (K,J)
Update P[J]
←←←←^
K
Shortest Path – Dijkstra’s Algorithm S = {}
C[start] = 0, C[ ] =
for all other nodes
while ( not all nodes in S
find node K not in S with smallest C[K] add K to Sfor each node J not in S adjacent to K if ( C[K] + cost of (K,J) < C[J] )C[J] = C[K] + cost of (K,J)P[J] = K
Dijkstra’s Shortest Path Example Find shortest paths starting from node 1 S = 1
none ∞∞∞∞ 5
none ∞∞∞∞ 4
none ∞∞∞∞ 3
none ∞∞∞∞ 2
none 0 1
Djikstra’s Shortest Path Example Update C[K] for all neighbors of 1 not in { S } S = { 1 }
none ∞∞∞∞ 5
none ∞∞∞∞ 4
1 8 3
1 5 2
none 0 1
Dijkstra’s Shortest Path Example Update C[K] for all neighbors of 2 not in S S = { 1, 2 }
none ∞∞∞∞ 5
2 15 4
2 6 3
1 5 2
none 0 1
Dijkstra’s Shortest Path Example Find node K with smallest C[K] and add to S S = { 1, 2, 3 }
none ∞∞∞∞ 5
2 15 4
2 6 3
1 5 2
none 0 1
Dijkstra’s Shortest Path Example Find node K with smallest C[K] and add to S { S } = 1, 2, 3, 4
none ∞∞∞∞ 5
3 9 4
2 6 3
1 5 2
none 0 1
Dijkstra’s Shortest Path Example Update C[K] for all neighbors of 4 not in S S = { 1, 2, 3, 4 }
4 18 5
3 9 4
2 6 3
1 5 2
none 0 1
Dijkstra’s Shortest Path Example All nodes in S, algorithm is finished S = { 1, 2, 3, 4, 5 }
4 18 5
3 9 4
2 6 3
1 5 2
none 0 1
Dijkstra’s Shortest Path Example Find shortest path from start to K^ Start at K^ Trace back predecessors in P[ ] Example paths (in reverse)^2
4 18 5
3 9 4
2 6 3
1 5 2
none 0 1