lecture 10: shortest path advanced...
TRANSCRIPT
ADVANCED ALGORITHMS LECTURE 10: SHORTEST PATH
�1
LECTURE 10
ANNOUNCEMENTS
▸ Homework 2 due next Friday
▸ Contacting the TAs: [email protected]
▸ Notes for this class: http://jeffe.cs.illinois.edu/teaching/algorithms/notes/21-sssp.pdf
�2
LECTURE 10
LAST CLASS
�3
▸ Local search and gradient descent
▸ Shortest path problem
if 2 approx formatching
LECTURE 10
GRAPH ALGORITHMS
�4
LECTURE 10
SHORTEST PATH PROBLEM
�5
Shortest path: given a (possibly directed) graph G = (V, E), and two vertices u, v, find the length of the shortest path from u to v
▸ What if the graph is not weighted? — breadth first search
▸ Negative weight edges?
all lengths 101mm
Problem is notFell ifu
grapmhtfsdes.ve
LECTURE 10
BFS + DISTANCE UPDATES?
�6
▸ Maintain array dist[w] for all vertices w
▸ Initialize using BFS
▸ For each edge ij, if dist[j] < dist[i] + length(i,j), update dist[j]
▸ Repeat until the dist[] values stop changing
OU O W
ListEw
i
oj
dhe w
w
LECTURE 10
OBSERVATIONS
�7
▸ At every point of the algorithm, dist[w] is an upper bound on true shortest path length d(u, w)
▸ dist[w] is monotone
Claim: when the algorithm terminates, dist[w] = d(u, w) for all w
true because dist w is thelengthof sp to w found
so far
LECTURE 10
PROOF
�8
Suppose we did k iterations of the algorithm. Is there something nice to be said about dist[w] values?
Owof
itt o o
Consider all vertices w for awhich shortest path from
Ito u w has lingulatek
a ti i
LECTURE 10
PROOF (CONTINUED)
�9
Prone claim by induction
k 0 is trivialSuppose it holds for k now connider htt
IrmasutEf for all vertices w s't hops in shortestpathEk
Owe found the path
Consider any w s t shortest pathfrom u has
htt hops go ee
affirmedIttihadw
THEcorrectvalue ftp.estfwI
Optimum path from a to w has hops
Ek
Reach Optimal sub structure property ofshortest paths
LECTURE 10
RUNNING TIME BOUND (SHIMBEL’S ALGORITHM)
�10
BellmanforTalgorithm
Previous claim aftern iterationswe havefoundthortestpaths toll w
iterations In
Time for each iteration 0cm
Overall runtime Ofm nIt also works when some edgewts are
we
LECTURE 10
BETTER THAN M*N?
�11
▸ Remember, this is an algorithm that also works when there are negative edges
▸ Can we use positivity in a nicer way?
▸ Can we “fix” BFS?
▸ Recall: main idea of BFS — find all vertices at certain distance from u
▸ Problem: in BFS, vertex at distance 2 is nbr of vertex at distance 1
LECTURE 10
MAIN IDEA — DIJKSTRA’S ALGORITHM
�12
1958Dijkstra
u
xm
ooo
9K
LECTURE 10
EXTENDING BFS
�13W
WIKes
winIntuitiveidas
Grow a ball of a certainradiusaround u
Add one vertex at a time Iqq joformalitalgorithmi start with vertex n
Add vertex that has min distancetofu
Add vertex l st u
via u Eiti E
tou via E EE't
LECTURE 10
PRIORITY QUEUE
�14
Want a data structure that
maintains 6h dist w pair
distfw is defined quicklyobtain the
w thathas minimumt.be dstme distf value
to a via the sitar quickly thedisowns
Oflog n
Read in notes Offmtn loginfm 7 nlognl
LECTURE 10
CORRECTNESS
�15
Claim whenever we add a vertex to the setball
we are maintainingthe distt value is indeed
the shortest distance to n
i
LECTURE 10
RUNNING TIME
�16
LECTURE 10
RUNNING TIME
�17
LECTURE 10
SHORTEST PATHS — SUMMARY
�18
▸ Shimbel/Bellman-Ford algorithm — can handle negative weights, but is slower
▸ Dijkstra’s algorithm — (m+n) log n
▸ Don’t know if log n is necessary!