lecture19 - Introduction to Algorithms...

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

View Full Document Right Arrow Icon
Introduction to Algorithms 6.046J/18.401J/SMA5503 Lecture 19 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 32 L19.2 © 2001 by Charles E. Leiserson Shortest paths Single-source shortest paths Nonnegative edge weights ± Dijkstra’s algorithm: O ( E + V lg V ) General ± Bellman-Ford: O ( VE ) DAG ± One pass of Bellman-Ford: O ( V + E ) All-pairs shortest paths Nonnegative edge weights ± Dijkstra’s algorithm | V | times: O ( VE + V 2 lg V ) General ± Three algorithms today.
Background image of page 2
Introduction to Algorithms Day 32 L19.3 © 2001 by Charles E. Leiserson All-pairs shortest paths Input: Digraph G = ( V , E ) , where | V | = n , with edge-weight function w : E R . Output: n × n matrix of shortest-path lengths δ ( i , j ) for all i , j V . I DEA #1: Run Bellman-Ford once from each vertex. Time = O( V 2 E ) . Dense graph O( V 4 ) time. Good first try!
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 32 L19.4 © 2001 by Charles E. Leiserson Dynamic programming Consider the n × n adjacency matrix A = ( a ij ) of the digraph, and define d ij (0) = 0 if i = j , if i j ; Claim: We have and for m = 1, 2, …, n –1 , d ij ( m ) = min k { d ik ( m– 1) + a kj } . d ij ( m ) = weight of a shortest path from i to j that uses at most m edges.
Background image of page 4
Introduction to Algorithms Day 32 L19.5 © 2001 by Charles E. Leiserson Proof of claim d ij ( m ) = min k { d ik ( m– 1) + a kj } i i j j M k ’s m 1 e d g s m –1 edges Relaxation!
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.

This note was uploaded on 07/09/2009 for the course CSE 6.046J/18. taught by Professor Piotrindykandcharlese.leiserson during the Fall '04 term at MIT.

Page1 / 14

lecture19 - Introduction to 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