GATE Computer ScienceVery hardGATE CS (PYQ pattern)

Bellman–Ford is run from S on a directed graph with edges S→A 2, A→B 3, B→C −4, C→A 0, C→D 5, D→E 1, E→H 2, S→F 7, F→G −2, S→I 4, I→F 1, J→B 1. For how many vertices is the shortest distance from S equal to −∞?

  1. A. 3
  2. B. 4
  3. C. 6
  4. D. 7

Correct answer: C. 6

The cycle A→B→C→A has weight 3 − 4 + 0 = −1, so it is a reachable negative cycle. Its vertices A, B, C and everything reachable from them (D, E, H) have distance −∞: that is 6 vertices. F, G and I have finite distances (5, 3, 4) and J is unreachable from S.

More Algorithms questions

Exams that ask this topic