Skip to content
Official PYQ · 2026

GATE CS 2026 Set 1 Q31 — Graph Traversals (BFS, DFS)

Explain with AI

Let G(V,E)G(V, E) be an undirected, edge-weighted graph with integer weights. The weight of a path is the sum of the weights of the edges in that path. The length of a path is the number of edges in that path.

Let s∈Vs \in V be a vertex in GG. For every u∈Vu \in V and for every k≥0k \geq 0, let dk(u)d_{k}(u) denote the weight of a shortest path (in terms of weight) from ss to uu of length at most kk. If there is no path from ss to uu of length at most kk, then dk(u)=∞d_{k}(u)=\infty.

Consider the statements:

S1: For every k≥0k \geq 0 and u∈V,dk+1(u)≤dk(u)u \in V, d_{k+1}(u) \leq d_{k}(u).

S2: For every (u,v)∈E(u, v) \in E, if (u,v)(u, v) is part of a shortest path (in terms of weight) from ss to vv, then for every k≥0,dk(u)≤dk(v)k \geq 0, d_{k}(u) \leq d_{k}(v).

Which one of the following options is correct?

Choose one option
View worked solution

Answer: A

Statement S1: True

Let Pk(s,u)P_k(s, u) be the set of all paths from ss to uu of length at most kk. Any path of length at most kk is also a path of length at most k+1k+1. Therefore, we have the subset relation:

Pk(s,u)⊆Pk+1(s,u)P_k(s, u) \subseteq P_{k+1}(s, u)

Since dk(u)d_k(u) is the minimum weight over the set Pk(s,u)P_k(s, u), taking the minimum over a larger set Pk+1(s,u)P_{k+1}(s, u) cannot increase the minimum weight. Thus, dk+1(u)≤dk(u)d_{k+1}(u) \leq d_k(u) always holds.

Statement S2: False

We can disprove this statement using a counterexample with positive integer weights. Consider an undirected graph with vertices {s,a,u,v}\{s, a, u, v\} and the following edge weights:

  • (s,a)=2(s, a) = 2
  • (a,u)=2(a, u) = 2
  • (u,v)=2(u, v) = 2
  • (s,v)=7(s, v) = 7
  • (s,u)=8(s, u) = 8

The shortest path from ss to vv is s→a→u→vs \to a \to u \to v with a total weight of 2+2+2=62 + 2 + 2 = 6. The edge (u,v)(u, v) is part of this shortest path.

Now, let us evaluate dk(u)d_k(u) and dk(v)d_k(v) for k=1k = 1:

  • d1(u)=8d_1(u) = 8 (via the direct path s→us \to u of length 1)
  • d1(v)=7d_1(v) = 7 (via the direct path s→vs \to v of length 1)

Since d1(u)=8>d1(v)=7d_1(u) = 8 > d_1(v) = 7, the condition dk(u)≤dk(v)d_k(u) \leq d_k(v) is violated for k=1k = 1. Thus, S2\text{S2} is false.

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

Published
Report a correction
Keep exploringMore Graph Traversals (BFS, DFS) questions