Question

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
Official answer and solution
Official answer
D
From
Official GATE 2015 answer key

Solution

Apply the level property of breadth-first search trees in undirected graphs.

  1. In an unweighted undirected graph GG, the BFS tree TT rooted at ss partitions the vertices into levels L0,L1,L2,…L_0, L_1, L_2, \dots, where level LkL_k contains all vertices at shortest distance d(x)=kd(x) = k from ss.

  2. For every edge (u,v)∈E(G)(u, v) \in E(G):
    Since there is a direct edge connecting uu and vv, the shortest path distance from ss satisfies the triangle inequality:

    d(u)≤d(v)+1andd(v)≤d(u)+1.d(u) \le d(v) + 1 \quad \text{and} \quad d(v) \le d(u) + 1.

    This implies:

    −1≤d(u)−d(v)≤1.-1 \le d(u) - d(v) \le 1.
  3. Therefore, for any non-tree edge (u,v)(u, v):

    • If uu and vv are in the same level, d(u)−d(v)=0d(u) - d(v) = 0.
    • If uu is in level kk and vv is in level k+1k+1, d(u)−d(v)=−1d(u) - d(v) = -1.
    • If uu is in level k+1k+1 and vv is in level kk, d(u)−d(v)=1d(u) - d(v) = 1.
  4. An edge cannot connect vertices whose levels differ by 2 or more, because if d(u)−d(v)=2d(u) - d(v) = 2, then d(u)=d(v)+2d(u) = d(v) + 2. However, following the edge from vv would give a path of length d(v)+1d(v) + 1 to uu, contradicting that d(u)=d(v)+2d(u) = d(v) + 2.

Thus, d(u)−d(v)d(u) - d(v) CANNOT be 22 (option D).

Final answer

D

Common trap

Confusing undirected graph BFS properties with directed graph BFS, where cross edges can jump backwards by more than 1 level.

The answer is the one in the official GATE answer key. The solution is this site's own explanation.

Source

Paper
GATE 2015 Computer Science and Information Technology (CS) Session 1
Question
55 of 65, printed as CS Q.45
Section
Computer Science and Information Technology

Report an error in this question

GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.