lecture19

# lecture19 - Introduction to Algorithms...

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

Introduction to Algorithms 6.046J/18.401J/SMA5503 Lecture 19 Prof. Erik Demaine

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

View Full Document
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.
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!

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

View Full Document
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.
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!

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

View Full Document
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
Ask a homework question - tutors are online