GATE Computer ScienceHardGATE CS (PYQ pattern)

Johnson's algorithm reweights the directed graph with edges A→B 3, A→C 8, B→D −4, C→B 10, D→C −5, D→E 2, E→A 6, C→E 1. The potentials h(v) come from Bellman–Ford from an added source with 0-weight edges to all vertices, and w′(u,v) = w(u,v) + h(u) − h(v). What is the new weight of the edge A→C?

  1. A. 1
  2. B. 8
  3. C. 15
  4. D. 19

Correct answer: C. 15

Bellman–Ford from the virtual source gives h(A) = −2, h(B) = 0, h(C) = −9, h(D) = −4, h(E) = −8. So w′(A→C) = 8 + (−2) − (−9) = 15. Using h(v) − h(u) by mistake would give 1.

More Algorithms questions

Exams that ask this topic