{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

lec18 - Introduction to Algorithms 6.046J/18.401J LECTURE...

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

November 16, 2005 Copyright © 2001-5 by Erik D. Demaine and Charles E. Leiserson L18.1 Introduction to Algorithms 6.046J/18.401J L ECTURE 18 Shortest Paths II Bellman-Ford algorithm Linear programming and difference constraints VLSI layout compaction Prof. Erik Demaine

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

View Full Document
November 16, 2005 Copyright © 2001-5 by Erik D. Demaine and Charles E. Leiserson L18.2 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
November 16, 2005 Copyright © 2001-5 by Erik D. Demaine and Charles E. Leiserson L18.3 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.

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

View Full Document
November 16, 2005 Copyright © 2001-5 by Erik D. Demaine and Charles E. Leiserson L18.4 Bellman-Ford algorithm d [ s ] 0 for each v V –{ s } do d [ v ] ←∞ initialization 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 relaxation step At the end, d [ v ] = δ ( s , v ) , if no negative-weight cycles. Time = O ( VE ) .
November 16, 2005 Copyright © 2001-5 by Erik D. Demaine and Charles E. Leiserson L18.5 Example of Bellman-Ford A A B B E E C C D D –1 4 1 2 –3 2 5 3

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

View Full Document
November 16, 2005 Copyright © 2001-5 by Erik D. Demaine and Charles E. Leiserson L18.6 Example of Bellman-Ford A A B B E E C C D D –1 4 1 2 –3 2 5 3 0 ∞∞ Initialization.
November 16, 2005 Copyright © 2001-5 by Erik D. Demaine and Charles E. Leiserson L18.7 Example of Bellman-Ford A A B B E E C C D D –1 4 1 2 –3 2 5 3 0 ∞∞ 1 2 3 4 5 7 8 6 Order of edge relaxation.

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

View Full Document
November 16, 2005 Copyright © 2001-5 by Erik D. Demaine and Charles E. Leiserson L18.8 Example of Bellman-Ford A A B B E E C C D D –1 4 1 2 –3 2 5 3 0 ∞∞ 1 2 3 4 5 7 8 6
November 16, 2005 Copyright © 2001-5 by Erik D. Demaine and Charles E. Leiserson L18.9 Example of Bellman-Ford A A B B E E C C D D –1 4 1 2 –3 2 5 3 0 ∞∞ 1 2 3 4 5 7 8 6

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

View Full Document
November 16, 2005 Copyright © 2001-5 by Erik D. Demaine and Charles E. Leiserson L18.10 Example of Bellman-Ford A A B B E E C C D D –1 4 1 2 –3 2 5 3 0 ∞∞ 1 2 3 4 5 7 8 6
November 16, 2005 Copyright © 2001-5 by Erik D. Demaine and Charles E. Leiserson L18.11 Example of Bellman-Ford −1 A A B B E E C C D D –1 4 1 2 –3 2 5 3 0 ∞∞ 1 2 3 4 5 7 8 6

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

View Full Document
November 16, 2005 Copyright © 2001-5 by Erik D. Demaine and Charles E. Leiserson L18.12 Example of Bellman-Ford 4 −1 A A B B E E C C D D –1 4 1 2 –3 2 5 3 0 1 2 3 4 5 7 8 6
November 16, 2005 Copyright © 2001-5 by Erik D. Demaine and Charles E. Leiserson L18.13 Example of Bellman-Ford 4 −1 A A B B E E C C D D –1 4 1 2 –3 2 5 3 0 1 2 3 4 5 7 8 6

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

View Full Document
November 16, 2005 Copyright © 2001-5 by Erik D. Demaine and Charles E. Leiserson L18.14 Example of Bellman-Ford 4 2 −1 A A B B E E C C D D –1 4 1 2 –3 2 5 3 0 1 2 3 4 5 7 8 6
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 45

lec18 - Introduction to Algorithms 6.046J/18.401J LECTURE...

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

View Full Document
Ask a homework question - tutors are online