lecture18 - Introduction to Algorithms...

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

View Full Document Right Arrow Icon
Introduction to Algorithms 6.046J/18.401J/SMA5503 Lecture 18 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 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.
Background image of page 2
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
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 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 ∞∞
Background image of page 4
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
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 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∞
Background image of page 6
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∞
Background image of page 7

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

View Full DocumentRight Arrow Icon
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∞
Background image of page 8
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
Background image of page 9

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

View Full DocumentRight Arrow Icon
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 ∞∞∞∞
Background image of page 10
Image of page 11
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 Right Arrow Icon
Ask a homework question - tutors are online