chap24-solutions - Selected Solutions for Chapter 24...

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

View Full Document Right Arrow Icon
Selected Solutions for Chapter 24: Single-Source Shortest Paths Solution to Exercise 24.1-3 If the greatest number of edges on any shortest path from the source is m , then the path-relaxation property tells us that after m iterations of BELLMAN-FORD, every vertex ± has achieved its shortest-path weight in ±: d . By the upper-bound property, after m iterations, no d values will ever change. Therefore, no d values will change in the .m C 1/ st iteration. Because we do not know m in advance, we cannot make the algorithm iterate exactly m times and then terminate. But if we just make the algorithm stop when nothing changes any more, it will stop after m C 1 iterations. BELLMAN-FORD-(M+1) .G;w;s/ INITIALIZE-SINGLE-SOURCE .G; s/ changes D TRUE while changes == TRUE changes D FALSE for each edge .u; ±/ 2 G: E RELAX-M .u;±;w/ RELAX-M .u;±; w/ if ±: d > u: d C w.u; ±/ ±: d D u: d C w.u;±/ ±:² D u changes D TRUE The test for a negative-weight cycle (based on there being a d value that would change if another relaxation step was done) has been removed above, because this version of the algorithm will never get out of the while loop unless all d values stop changing. Solution to Exercise 24.3-3 Yes, the algorithm still works. Let u be the leftover vertex that does not get extracted from the priority queue Q . If u is not reachable from s , then
Background image of page 1

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

View Full DocumentRight Arrow Icon
24-2 Selected Solutions for Chapter 24: Single-Source Shortest Paths u: d D ı.s; u/ D 1 . If u is reachable from s , then there is a shortest path p D s a x ! u . When the node x was extracted, x: d D ı.s; x/ and then the edge .x;u/ was relaxed; thus, u: d D ı.s;u/ .
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/20/2010 for the course IE ie200 taught by Professor . during the Spring '10 term at 카이스트, 한국과학기술원.

Page1 / 4

chap24-solutions - Selected Solutions for Chapter 24...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online