Skip to content
Official PYQ · 2020

GATE CS 2020 Q40 — Shortest Paths (Dijkstra, Bellman-Ford)

Explain with AI

Let G=(V,E)G = (V,E) be a directed, weighted graph with weight function w:E→Rw: E \rightarrow \mathbb{R}. For some function f:V→Rf: V \rightarrow \mathbb{R}, for each edge(u,v)∈E(u,v)\in E, define w′(u,v){w}'(u,v) as w(u,v)+f(u)−f(v)w(u,v)+f(u)-f(v).

Which one of the options completes the following sentence so that it is TRUE?

“The shortest paths in GG under ww are shortest paths under w′{w}' too,_____________”.

Choose one option
View worked solution

Answer: A

Let P=(v0,v1,…,vk)P = (v_0, v_1, \dots, v_k) be any path from a start vertex u=v0u = v_0 to an end vertex v=vkv = v_k. The weight of the path PP under the new weight function w′w' is given by:

w′(P)=∑i=1kw′(vi−1,vi)=∑i=1k(w(vi−1,vi)+f(vi−1)−f(vi))w'(P) = \sum_{i=1}^{k} w'(v_{i-1}, v_i) = \sum_{i=1}^{k} \left( w(v_{i-1}, v_i) + f(v_{i-1}) - f(v_i) \right)

Expanding this sum, the terms involving ff form a telescoping series:

w′(P)=∑i=1kw(vi−1,vi)+(f(v0)−f(v1)+f(v1)−f(v2)+⋯+f(vk−1)−f(vk))w'(P) = \sum_{i=1}^{k} w(v_{i-1}, v_i) + \left( f(v_0) - f(v_1) + f(v_1) - f(v_2) + \dots + f(v_{k-1}) - f(v_k) \right) w′(P)=w(P)+f(u)−f(v)w'(P) = w(P) + f(u) - f(v)

For any two vertices uu and vv, the term f(u)−f(v)f(u) - f(v) is a constant that depends only on the endpoints uu and vv, and not on the specific path chosen between them.

Therefore, for any two paths P1P_1 and P2P_2 from uu to vv:

w′(P1)<w′(P2)  ⟺  w(P1)<w(P2)w'(P_1) < w'(P_2) \iff w(P_1) < w(P_2)

This preservation of relative path weights ensures that a path is a shortest path under ww if and only if it is a shortest path under w′w'. Since this property holds regardless of the values assigned by ff, it is true for every f:V→Rf: V \rightarrow \mathbb{R}.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Shortest Paths (Dijkstra, Bellman-Ford) questions