12 - All-Pairs Shortest Paths

12 - All-Pairs Shortest Paths - Part III Dynamic...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

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

Unformatted text preview: Part III: Dynamic Programming Lecture 12: All-Pairs Shortest Paths Lecture 12: All-Pairs 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 all-pairs shortest path problem. A first dynamic programming solution. The Floyd-Warshall alogrithm Extracting shortest paths. Lecture 12: All-Pairs Shortest Paths Part III: Dynamic Programming The All-Pairs 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 3-20 5 10 4 4 4 a b c d e without negative cost cycle with negative cost cycle 6 Lecture 12: All-Pairs 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 negative-weight edges are present: Run the Bellman-Ford algorithm from each vertex. O ( n 2 e ), which is O ( n 4 ) for dense graphs. Lecture 12: All-Pairs Shortest Paths Part III: Dynamic Programming Outline The all-pairs shortest path problem. A first dynamic programming solution. The Floyd-Warshall alogrithm Extracting shortest paths. Lecture 12: All-Pairs 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: All-Pairs 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

This note was uploaded on 10/18/2009 for the course COMP 271 taught by Professor Arya during the Spring '07 term at HKUST.

Page1 / 29

12 - All-Pairs Shortest Paths - Part III Dynamic...

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

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