Skip to main content

GATE CSE 2015Algorithms › Graph AlgorithmsVerified

GATE CSE 2015 PYQ: Let G = ( V , E ) G = (V, E) G = ( V , E ) be a simple undirected graph, and s s s be a particular vertex in…

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)?

  1. A
    −1-1
  2. B
    0
  3. C
    1
  4. D
    2
    Correct answer

Answer

(D) 2 2 2

Approach

Use the fundamental BFS property that, for every edge (u,v) of an undirected graph, the shortest distances from the source differ by at most 1: $|d(u)-d(v)|\le 1$. This kills the value 2 immediately. Then verify by explicit small graphs that $-1, 0$ and 1 really do occur for a non-tree edge, so the only impossible value is 2.

For any edge of an undirected graph, BFS shortest distances from the source differ by at most 1, so $d(u)-d(v)$ can only be $-1$, 0 or 1. Constructions show all three of these values are attainable by non-tree edges, hence the value that CANNOT occur is 2 (option D). All three community answers agree that the answer is 2.

Reviewed by GateIQ Editorial Team: IIT & IISc Alumni.