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: D→B (4), F→D (8), D→C (2), A→E (7), A→C (-1), B→F (7), A→D (5), B→A (8), F→A (9). 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 16
  2. B. 3 passes, dist 16
  3. C. 2 passes, dist 16
  4. D. 1 pass, dist 16

Correct answer: C. 2 passes, dist 16

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=9, C=-1, D=5, E=7, F=16.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic