Data Structures & AlgorithmsVery hardGATE CS · Product-company placement

Bellman–Ford runs from A on the directed graph whose edges are relaxed in EVERY pass in this fixed order: C→D (1), A→F (8), F→C (3), D→A (5), B→A (-3), E→B (7), C→A (3), A→E (1), D→F (7). 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 8
  2. B. 2 passes, dist 8
  3. C. 3 passes, dist 8
  4. D. 1 pass, dist 8

Correct answer: B. 2 passes, dist 8

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=8, C=11, D=12, E=1, F=8.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic