Exercise 1: Bellman-Ford on S-T-U-V — Possible Solution ==================================================================== GIVEN ------------------------------ Edges: S->T(6), S->U(7), T->U(-3), U->V(2) Source: S. Vertices: S,T,U,V (V=4, so 3 rounds maximum). ROUND 1 ------------------------------ Start: dist = {S:0, T:inf, U:inf, V:inf} Relax S->T: 0+6=6 < inf -> update dist[T]=6 Relax S->U: 0+7=7 < inf -> update dist[U]=7 Relax T->U: 6+(-3)=3 < 7 (U's current value) -> update dist[U]=3 Relax U->V: 3+2=5 < inf -> update dist[V]=5 After round 1: dist = {S:0, T:6, U:3, V:5} ROUND 2 ------------------------------ Relax S->T: 0+6=6, not < 6 (already equal) - no change Relax S->U: 0+7=7, not < 3 - no change Relax T->U: 6+(-3)=3, not < 3 (already equal) - no change Relax U->V: 3+2=5, not < 5 (already equal) - no change No changes this round - the algorithm has already converged after just one round. (Round 3 would also produce no changes, so it can be skipped once a round makes zero updates.) RESULT ------------------------------ Final distances from S: {S:0, T:6, U:3, V:5} U was updated twice within round 1 itself - first to 7 via the direct edge S->U, then immediately corrected to 3 once T->U was relaxed later in that same round (since S->T happens to be listed before T->U in the edge order here). It converged in a single round only because the edges happened to be listed in a convenient order - a different order could have taken an extra round to reach the same final answer, exactly as this chapter's own warn-box describes. WHY THIS WORKS AS AN ANSWER ------------------------------ Every edge relaxation across each round is shown explicitly, including the within-round correction to U, and the trace correctly recognizes convergence (a round producing zero updates) as the signal that no further rounds are needed, rather than mechanically running all V-1 rounds regardless.