GATE / CS ARCHIVE

GATE CSE 2020 / QUESTION 40

GATE CSE 2020 Q40

Algorithms · Graph Algorithms · Full GATE CSE 2020 paper

GATE 2020, Q40 2 marks · MCQ
Report issue

Graph Algorithms

Question 40, GATE 2020: A directed weighted graph has reweighted edges w′(u,v)=w(u,v)+f(u)−f(v), with f:V→R. Shortest paths are preserved: A for every f; B iff f is everywhere positive; C iff f is everywhere negative; D iff f gives shortest distances from a new source joined to all vertices by zero-weight edges.
Tap to enlarge
Your answer
Answer & solution

Official answer: A

Worked explanation

For a path v0=s,v1,…,vk=t, summing the added terms gives f(v0)−f(v1)+f(v1)−f(v2)+…+f(vk−1)−f(vk)=f(s)−f(t). Intermediate contributions cancel pairwise. Thus for two s-t paths P,Q, w′(P)−w′(Q)=w(P)−w(Q), preserving strict inequalities and ties. The signs of individual potentials do not matter. Choosing shortest-distance potentials is useful in Johnson’s algorithm to make edge weights nonnegative, but that is an additional goal; it is not necessary for path-order preservation. This argument compares common endpoints, not unrelated paths with different sources or destinations.

Derivation and answer

For any path from s to t, the added potentials telescope: sum[w(u, v)+f(u)−f(v)]=original path weight+f(s)−f(t). All paths with the same endpoints receive the same constant, so their relative order and shortest paths are unchanged for every real-valued f, A. Cycle weights are unchanged too; this does not create finite shortest paths where reachable negative cycles originally prevented them.

Original paper, page 13 · Answer key