Question
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 ?
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.
-
In an unweighted undirected graph , the BFS tree rooted at partitions the vertices into levels , where level contains all vertices at shortest distance from .
-
For every edge :
Since there is a direct edge connecting and , the shortest path distance from satisfies the triangle inequality:This implies:
-
Therefore, for any non-tree edge :
- If and are in the same level, .
- If is in level and is in level , .
- If is in level and is in level , .
-
An edge cannot connect vertices whose levels differ by 2 or more, because if , then . However, following the edge from would give a path of length to , contradicting that .
Thus, CANNOT be (option D).
D
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.