Data Structures & AlgorithmsHardProduct company OA

Bellman–Ford from S relaxes the directed edges in this fixed order in every pass: C→D (1), B→C (2), A→B (3), S→A (4). How many passes are needed until a pass makes NO change (count that final quiet pass too)?

  1. A. 4
  2. B. 5
  3. C. 2
  4. D. 1

Correct answer: B. 5

Edges are listed against the path order, so each pass extends the known path by just one edge: pass 1 sets A, pass 2 B, pass 3 C, pass 4 D, and pass 5 changes nothing. With the order S→A, A→B, B→C, C→D everything would settle in pass 1, and pass 2 would be the quiet one.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic