Let be a simple undirected graph, and be a particular vertex in it called the source. For , let denote the shortest distance in from to . A breadth first search (BFS) is performed starting at . Let be the resultant BFS tree. If is an edge of that is not in , then which one of the following CANNOT be the value of ?
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…
- A
- B0
- C1
- D2Correct 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.