GATE / CS ARCHIVE

GATE CSE 2001 / QUESTION 2.14

BFS order and shortest-path distances

Algorithms · Graph Algorithms · Full GATE CSE 2001 paper

GATE 2001, Q2.14 2 marks · MCQ
Report issue

Graph Algorithms

Question 2.14, GATE 2001: In BFS from r in an undirected unweighted graph, vertex u is visited before v. Must d(r,u)<d(r,v), >, ≤, or none of these?
Question 2.14, GATE 2001: In BFS from r in an undirected unweighted graph, vertex u is visited before v. Must d(r,u)<d(r,v), >, ≤, or none of these?
Tap to enlarge
Your answer
Answer & solution

Answer: C (no official key was published)

Step 1: Breadth-first search’s FIFO queue processes all vertices at distance k before any vertex at distance k+1. Thus dequeue/discovery order is nondecreasing in distance from r.

Step 2: Two distinct vertices in the same layer can occur in either order, so visiting u first does not imply a strict inequality. A star centered at r supplies such an equal-distance example.

Therefore d(r,u)≤d(r,v), C, for vertices reached by this BFS. Unreachable vertices are not visited by the traversal from r.

Original paper, page 5