Data Structures & AlgorithmsVery hardProduct-company placement

Bellman–Ford runs from A on the directed graph whose edges are relaxed in EVERY pass in this fixed order: E→B (2), E→C (9), D→F (-3), F→A (9), B→C (5), C→D (-3), A→E (-2), E→D (9), A→D (1). It stops early after the first pass that changes nothing. How many passes change at least one distance, and what is the final distance to F?

  1. A. 5 passes, dist -2
  2. B. 3 passes, dist -2
  3. C. 2 passes, dist -2
  4. D. 1 pass, dist -2

Correct answer: C. 2 passes, dist -2

Simulate pass by pass in the given edge order: a change can travel along several edges in one pass when they appear in path order, so only 2 passes change something (then one pass confirms nothing changes). Final distances: A=0, B=0, C=5, D=1, E=-2, F=-2.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic