{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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 A B C D 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 A B C D 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 A B C D E 0 0 4 0 –1 4
Introduction to Algorithms Day 31 L18.7 © 2001 by Charles E. Leiserson 0 –1 2 2 –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 A B C D E 0 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 –1 2 0 –1 A B C D E 0 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 –1 2 0 –1 A B C D E 0 0 –1 4 1 0 –1 2 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 –1 2 1 1 1 –1 Example of Bellman-Ford A A B B E E C C D D
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### 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