ADVANCED ALGORITHMS
LECTURE 10: SHORTEST PATH
1
ADVANCED ALGORITHMS 2 LECTURE 10 ANNOUNCEMENTS Homework 2 due - - PowerPoint PPT Presentation
1 LECTURE 10: SHORTEST PATH ADVANCED ALGORITHMS 2 LECTURE 10 ANNOUNCEMENTS Homework 2 due next Friday Contacting the TAs: utah-algo-ta@googlegroups.com Notes for this class: http://jeffe.cs.illinois.edu/teaching/algorithms/
LECTURE 10: SHORTEST PATH
1
LECTURE 10
ANNOUNCEMENTS
▸ Homework 2 due next Friday ▸ Contacting the TAs: utah-algo-ta@googlegroups.com ▸ 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 1
01mm
Problem is not
Fell if
u
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
List
Ew
dhe 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 the lengthof 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?
Ow
vertices w for a
which shortest path from
u
w
has lingulatek
a
LECTURE 10
PROOF (CONTINUED)
9
Prone claim byinduction
k
is
trivial
Suppose it holds for
k
now
connider htt
IrmasutEf for
all vertices
w
s't
hops in shortestpath Ek
O
we found the path
Consider any
w
s t
shortest pathfrom u has
htt
hops
go
ee
w
THE
correctvalue ftp.estfwI
Optimum
path from
a
to w has
hops
Ek
Reach
Optimal sub structure
property of
shortest paths
LECTURE 10
RUNNING TIME BOUND (SHIMBEL’S ALGORITHM)
10
Bellman
algorithm
Previous
claim
we havefoundthortest
paths
w
iterations In
Time
for each iteration
0cm
Overall runtime
Ofm n It
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
1958
Dijkstra
u
x
m
LECTURE 10
EXTENDING BFS
13
W
WI
Kes
win
Intuitiveidas
Grow a ball of a certainradiusaround
u
Add one vertex at
a time
Iqqjo
formalitalgorithmi
start
with
vertex
n
Add
vertex
that has
min distancetofu
Add
vertex
l
st
u
via
u E
it
i
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 minimum
t.be dstme
distf
value
to
a
via the sitar
the
n
Read
in
notes
Offmtn login
fm 7 nlognl
LECTURE 10
CORRECTNESS
15
whenever
we add
a vertex to the set
ball
we
are
maintaining the 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!