Skip to content
Official PYQ · 2015

GATE CS 2015 Set 1 Q45 — Graph Traversals (BFS, DFS)

Explain with AI

Let G=(V,E)G = (V, E) be a simple undirected graph, and ss be a particular vertex in it called the source. For x∈Vx \in V, let d(x)d(x) denote the shortest distance in GG from ss to xx. A breadth first search (BFS) is performed starting at ss. Let TT be the resultant BFS tree. If (u,v)(u, v) is an edge of GG that is not in TT, then which one of the following CANNOT be the value of d(u)−d(v)d(u) - d(v)?

Choose one option
View worked solution

Answer: D

In an unweighted, undirected graph G=(V,E)G = (V, E), the shortest distance d(x)d(x) from a source vertex ss to any vertex xx is the minimum number of edges on a path between them.

For any edge (u,v)extinE(u, v) ext{ in } E (regardless of whether it is selected in the BFS tree TT or not), the triangle inequality for shortest path distances must hold:

  1. The shortest path to uu cannot be longer than the shortest path to vv plus the edge (u,v)(u, v): d(u)≤d(v)+1  ⟹  d(u)−d(v)≤1d(u) \le d(v) + 1 \implies d(u) - d(v) \le 1
  2. Similarly, the shortest path to vv cannot be longer than the shortest path to uu plus the edge (u,v)(u, v): d(v)≤d(u)+1  ⟹  d(u)−d(v)≥−1d(v) \le d(u) + 1 \implies d(u) - d(v) \ge -1

Combining these two inequalities, we get:

−1≤d(u)−d(v)≤1-1 \le d(u) - d(v) \le 1

Since the distance function d(x)d(x) only takes non-negative integer values, the only possible values for d(u)−d(v)d(u) - d(v) are −1-1, 00, and 11.

Therefore, d(u)−d(v)d(u) - d(v) CANNOT be 22.

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

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