Professional Documents
Culture Documents
27 Graph Shortest Paths
27 Graph Shortest Paths
Graph Algorithms
Shortest Paths
● Formulation:
dist(s,v) = min(dist(s,u)+1)
for all (u,v) in E
● Order of Computation:
Break dependence cycle: Closest Vertex First
● Complexity: O(m+n)
2
Single Source Shortest Path (Unweighted)
3
Single Source Longest Path (Unweighted)
● Formulation:
dist(s,v) = max(dist(s,u)+1)
for all (u,v) in E
● Order of Computation:
Unclear without repeating edge/vertices
● Complexity:
Exponential (Reduction from HamCycle)
4
Single Source Shortest Path (No negative edges)
● Formulation: 5 5
5
14
dist(s,v) = min(dist(s,u)+w(u,v)) 2 2
5
for all (u,v) \in E 10
10
5
10 10
● Order of Computation:
Break dependence cycle, Closest Vertex First
5
Single Source Shortest Path (No negative edges)
6
Single Source Shortest Path (No negative edges)
7
Single Source Shortest Path (No negative cycles)
10
Single Source Shortest Path (No negative cycles)
forEach((u,v) in E){
if(dist[v] > dist[u]+w(u,v))
dist[v]=dist[u]+w(u,v);
}
}
11
Single Source Longest Path (No positive cycles)
13
Single Source Shortest/Longest Path (General)
Problem?
14
Single Source Shortest/Longest Path (Summary)
Unweighted
No opp weight
SP = Only Pos
LP = Only Neg
No opp cycle
SP = Only Pos
LP = Only Neg
General Case
15
All Pairs Shortest Paths in a Graph (APSP)
25