19 - Dynamic Programming II Data Structures and Algorithms...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
Dynamic Programming II Data Structures and Algorithms Andrei Bulatov
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Algorithms – Dynamic Programming 18-2 Shortest Path Suppose that every arc e of a digraph G has length (or cost, or weight, or …) len(e) But now we allow negative lengths (weights) Then we can naturally define the length of a directed path in G, and the distance between any two nodes The s-t-Shortest Path Problem Instance : Digraph G with lengths of arcs, and nodes s,t Objective : Find a shortest path between s and t
Background image of page 2
Algorithms – Dynamic Programming 18-3 Shortest Path: Dynamic Programming We will be looking for a shortest path with increasing number of arcs Let OPT(i,v) denote the minimum weight of a path from v to t using at most i arcs Shortest v – t path can use i – 1 arcs. Then OPT(i,v) = OPT(i – 1,v) Or it can use i arcs and the first arc is vw. Then OPT(i,v) = len(vw) + OPT(i – 1,w) v t w )}} ( ) , 1 ( { min ), , 1 ( min{ ) , ( vw len w i OPT v i OPT v i OPT V w + - - =
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Algorithms – Dynamic Programming 18-4 Shortest Path: Bellman-Ford Algorithm Shortest-Path(G,s,t) set n:=|V| /*number of nodes in G array M[0. .n-1,V] set M[0,t]:=0 and M[0,v]:= for each v V-{t} for i=1 to n-1 do for v V do set M[i,v]:=min{M[i-1,v],min {M[i-1,w]+len(vw)}} endfor endfor return m[n-1,s] w V
Background image of page 4
Programming 18-5 Shortest Path: Soundness and Running Time Theorem The ShortestPath algorithm correctly computes the minimum cost of an s-t path in any graph that has no negative cycles, and runs in O( ) time 3 n Proof . Soundness follows by induction from the recurrent relation for the optimal value. DIY.
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 17

19 - Dynamic Programming II Data Structures and Algorithms...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online