GATE / CS ARCHIVE

GATE CSE 2014 SET 2 / QUESTION 14

GATE CSE 2014 Set 2 Q14

Algorithms · Graph Algorithms · Full GATE CSE 2014 Set 2 paper

GATE 2014 Set 2, Q14 1 mark · MCQ
Report issue

Graph Algorithms

Question 14, GATE 2014: Run BFS from W in a connected, undirected, unweighted graph and retain its tree edges in T. This tree supports which task? A shortest paths between every vertex pair; B shortest paths from W to every vertex; C shortest paths from W only to leaves of T; D a longest path in the graph.
Tap to enlarge
Your answer
Answer & solution

Official answer: B

1. Set up the reasoning. BFS assigns a vertex to the earliest reachable distance layer. When a vertex is first discovered, its parent is one layer closer to W, so following parents yields a path of exactly that shortest distance.

2. Derive the result. BFS explores vertices in increasing edge-distance from W. Parent pointers in the BFS tree therefore reconstruct a shortest path from W to every vertex. They need not preserve shortest paths between arbitrary other pairs. Thus B.

3. Check the interpretation. The guarantee is rooted at W and covers internal vertices as well as leaves. A non-tree edge may shorten the route between two other vertices, so one BFS tree is not an all-pairs shortest-path representation.

Original paper, page 32 · Answer key