Let be the graph obtained by reversing the directions of all the edges in without changing the set of vertices.
Assume that Breadth First Search (BFS) or Depth First Search (DFS) from any given vertex of a graph visits only the reachable vertices from in that graph.
Which of the following statements must always be true, regardless of the structure of ?
D
Step-by-Step Solution
Insight: BFS/DFS on from finds exactly the set of vertices that can reach in . BFS/DFS on from finds exactly the set of vertices reachable from in .
Exam route: Translate each option into reachability language in .
Learning route:
- Let = vertices reachable from in . This is what DFS/BFS on from returns.
- Let = vertices that can reach in . This is what DFS/BFS on from returns.
- Option A: . False. Counter-example: only. can reach but cannot reach .
- Option B: . False. Same counter-example.
- Option C: BFS order is reverse of DFS order. False. BFS is level-by-level, DFS is deep-first; no reason for reversal.
- Option D: in in .
If is reachable from in , there is a path .
Reversing all edges gives in .
So is reachable from in . This is exactly in (which is computed by BFS on from ).
True.
Answer: D.