This preview shows pages 1–8. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: Part III: Dynamic Programming Lecture 12: AllPairs Shortest Paths Lecture 12: AllPairs Shortest Paths Part III: Dynamic Programming Objective and Outline Objective : A third example of dynamic programming Different DP formulations possible for some problems. Reference : Chapter 25 of CLRS Outline The allpairs shortest path problem. A first dynamic programming solution. The FloydWarshall alogrithm Extracting shortest paths. Lecture 12: AllPairs Shortest Paths Part III: Dynamic Programming The AllPairs Shortest Paths Problem Given : a weighted digraph G = ( V , E ) with weight function w : E → R Determine : the length of the shortest path (i.e., distance ) between all pairs of vertices in G . we assume that there are no cycles with zero or negative cost. a b c d e 20 12 5 4 17 3 8 320 5 10 4 4 4 a b c d e without negative cost cycle with negative cost cycle 6 Lecture 12: AllPairs Shortest Paths Part III: Dynamic Programming Solution 1: Using Dijkstra’s Algorithm Where there are no negative cost edges. Apply Dijkstra’s algorithm to each vertex (as the source) of the digraph. Recall that Dijkstra algorithm runs in Θ( e log n ) n =  V  and e =  E  . This gives a Θ( ne log n ) time algorithm If the digraph is dense, this is a Θ( n 3 log n ) algorithm. When negativeweight edges are present: Run the BellmanFord algorithm from each vertex. O ( n 2 e ), which is O ( n 4 ) for dense graphs. Lecture 12: AllPairs Shortest Paths Part III: Dynamic Programming Outline The allpairs shortest path problem. A first dynamic programming solution. The FloydWarshall alogrithm Extracting shortest paths. Lecture 12: AllPairs Shortest Paths Part III: Dynamic Programming Input and Output Formats Input Format : To simplify the notation, we assume that V = { 1 , 2 , . . . , n } . Assume that the graph is represented by an n × n matrix with the weights of the edges: w ij = if i = j , w ( i , j ) if i 6 = j and ( i , j ) ∈ E , ∞ if i 6 = j and ( i , j ) / ∈ E . Output Format : an n × n matrix D = [ d ij ] where d ij is the length of the shortest path from vertex i to j . Lecture 12: AllPairs Shortest Paths Part III: Dynamic Programming Step 1: Space of Subproblems For m = 1 , 2 , . . . , n 1, Define d ( m ) ij to be the length of the shortest path from i to j that contains at most m edges . Let D ( m ) be the n × n matrix [ d ( m ) ij ]. Subproblems : Compute D ( m ) for m = 1 , . . . , n 1 ....
View
Full
Document
 Spring '07
 ARYA
 Algorithms, C Programming

Click to edit the document details