GATE CS 2015 · Set-1 · Shortest Path Algorithms

MCQ · 2 marks · Problem PROG-GRPH-0076

Let G = (V, E) be a simple undirected graph, and s be a particular vertex in it called the source. For \(x \in V\), let d(x) denote the shortest distance in G from s to x. A breadth first search (BFS) is performed starting at s. Let T be the resultant BFS tree. If (u,v) is an edge of G that is not in T, then which one of the following CANNOT be the value of d(u)-d(v)?
  1. A
    -1
  2. B
    0
  3. C
    1
  4. D
    2

Solve it on GATE DA practice →More Graph Theory & Algorithms problems

Show the worked solutionBFS finds shortest distances, so \(d\) is the BFS level. For any edge \((u,v)\) of \(G\), reaching one end gives a path of one more edge to the other:\[d(v)\le d(u)+1,\qquad d(u)\le d(v)+1\;\Rightarrow\;|d(u)-d(v)|\le 1.\]So \(d(u)-d(v)\in\{-1,0,1\}\) for every edge, tree or not.• \(0\): an edge between two vertices of the same level (e.g. a triangle on \(s\)). • \(\pm1\): an edge from a vertex to a second parent candidate one level up (e.g. a 4-cycle on \(s\)).A difference of 2 would contradict the inequality above.Answer: D

GATE DA practice: past exam problems by chapter, with worked solutions · gatedaprep.com