lecture17 - Introduction to Algorithms...

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

View Full Document Right Arrow Icon
Introduction to Algorithms 6.046J/18.401J/SMA5503 Lecture 17 Prof. Erik Demaine
Background image of page 1

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

View Full DocumentRight Arrow Icon
Introduction to Algorithms Day 29 L17.2 © 2001 by Charles E. Leiserson Paths in graphs Consider a digraph G = ( V , E ) with edge-weight function w : E R . The weight of path p = v 1 v 2 L v k is defined to be = + = 1 1 1 ) , ( ) ( k i i i v v w p w . v 1 v 1 v 2 v 2 v 3 v 3 v 4 v 4 v 5 v 5 4– 2 51 Example: w ( p ) = –2
Background image of page 2
Introduction to Algorithms Day 29 L17.3 © 2001 by Charles E. Leiserson Shortest paths A shortest path from u to v is a path of minimum weight from u to v . The shortest- path weight from u to v is defined as δ ( u , v ) = min{ w ( p ) : p is a path from u to v } . Note: δ ( u , v ) = if no path from u to v exists.
Background image of page 3

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

View Full DocumentRight Arrow Icon
Introduction to Algorithms Day 29 L17.4 © 2001 by Charles E. Leiserson Optimal substructure Theorem. A subpath of a shortest path is a shortest path. Proof. Cut and paste:
Background image of page 4
Introduction to Algorithms Day 29 L17.5 © 2001 by Charles E. Leiserson Triangle inequality Theorem. For all u , v , x V , we have δ ( u , v ) ≤δ ( u , x ) + δ ( x , v ) . u u Proof. x x v v δ ( u , v ) δ ( u , x ) δ ( x , v )
Background image of page 5

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

View Full DocumentRight Arrow Icon
Introduction to Algorithms Day 29 L17.6 © 2001 by Charles E. Leiserson Well-definedness of shortest paths If a graph G contains a negative-weight cycle, then some shortest paths may not exist. Example: u u v v < 0
Background image of page 6
Introduction to Algorithms Day 29 L17.7 © 2001 by Charles E. Leiserson Single-source shortest paths Problem. From a given source vertex s V , find the shortest-path weights δ ( s , v ) for all v V . If all edge weights w ( u , v ) are nonnegative , all shortest-path weights must exist. I DEA : Greedy. 1. Maintain a set S of vertices whose shortest- path distances from s are known. 2. At each step add to S the vertex v V S whose distance estimate from s is minimal. 3. Update the distance estimates of vertices adjacent to v .
Background image of page 7

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

View Full DocumentRight Arrow Icon