lecture18

# lecture18 - Introduction to Algorithms...

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

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

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

View Full Document
Introduction to Algorithms Day 31 L18.2 © 2001 by Charles E. Leiserson Negative-weight cycles Recall: If a graph G = ( V , E ) contains a negative- weight cycle, then some shortest paths may not exist. Example: u u v v < 0 Bellman-Ford algorithm: Finds all shortest-path lengths from a source s V to all v V or determines that a negative-weight cycle exists.
Introduction to Algorithms Day 31 L18.3 © 2001 by Charles E. Leiserson Bellman-Ford algorithm d [ s ] 0 for each v V –{ s } do d [ v ] ←∞ for i 1 to | V | –1 do for each edge ( u , v ) E do if d [ v ] > d [ u ] + w ( u , v ) then d [ v ] d [ u ] + w ( u , v ) for each edge ( u , v ) E do if d [ v ] > d [ u ] + w ( u , v ) then report that a negative-weight cycle exists initialization At the end, d [ v ] = δ ( s , v ) . Time = O ( VE ) . relaxation step

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

View Full Document
Introduction to Algorithms Day 31 L18.4 © 2001 by Charles E. Leiserson Example of Bellman-Ford A A B B E E C C D D –1 4 1 2 –3 2 5 3 ABCD E 0 ∞∞∞∞ 0 ∞∞
Introduction to Algorithms Day 31 L18.5 © 2001 by Charles E. Leiserson –1 0– 1 ∞∞ Example of Bellman-Ford A A B B E E C C D D –1 4 1 2 –3 2 5 3 ABCD E 0 ∞∞∞∞ 0

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

View Full Document
Introduction to Algorithms Day 31 L18.6 © 2001 by Charles E. Leiserson –1 0– 1 ∞∞ Example of Bellman-Ford A A B B E E C C D D –1 4 1 2 –3 2 5 3 ABCD E 0 ∞∞∞∞ 0 4 1 4∞
Introduction to Algorithms Day 31 L18.7 © 2001 by Charles E. Leiserson 4 0– 12 ∞∞ 2 –1 1 Example of Bellman-Ford A A B B E E C C D D –1 4 1 2 –3 2 5 3 ABCD E 0 ∞∞∞∞ 0 1 4∞

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

View Full Document
Introduction to Algorithms Day 31 L18.8 © 2001 by Charles E. Leiserson –1 Example of Bellman-Ford A A B B E E C C D D –1 4 1 2 –3 2 5 3 0 2 0– 12 ∞∞ 1 ABCD E 0 ∞∞∞∞ 1 4∞
Introduction to Algorithms Day 31 L18.9 © 2001 by Charles E. Leiserson –1 Example of Bellman-Ford A A B B E E C C D D –1 4 1 2 –3 2 5 3 0 2 0– 12 ∞∞ 1 ABCD E 0 ∞∞∞∞ 1 4∞ 1 1

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

View Full Document
Introduction to Algorithms Day 31 L18.10 © 2001 by Charles E. Leiserson 0– 12 1 1 1 –1 Example of Bellman-Ford A A B B E E C C D D –1 4 1 2 –3 2 5 3 0 2 ∞∞ 1 ABCD E 0 ∞∞∞∞
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 / 25

lecture18 - Introduction to Algorithms...

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

View Full Document
Ask a homework question - tutors are online