Let \(G = (V, E)\) be a simple undirected graph, and \(s\) be a particular…

2015

Let \(G = (V, E)\) be a simple undirected graph, and \(s\) be a particular vertex in it called the source. For \(x ∈ V\) , let \(d(x)\) denote the shortest distance in \(G\) from sto \(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

Attempted by 178 students.

Show answer & explanation

Correct answer: D

Key idea: For any edge (u,v) in the graph, a breadth-first search rooted at s guarantees that the distances differ by at most 1, i.e. |d(u) - d(v)| ≤ 1.

Proof that a difference of 2 cannot occur:

  • Assume for contradiction that d(u) = d(v) + 2.

  • Let k = d(v). Then there is a shortest path from s to v of length k.

  • Because (u,v) is an edge, following that shortest path to v and then taking the edge to u gives a path from s to u of length k + 1 = d(v) + 1.

  • This implies d(u) ≤ d(v) + 1, contradicting the assumption d(u) = d(v) + 2. Hence a difference of 2 is impossible.

Why the values -1, 0, and 1 are possible:

  • -1: This indicates u is one level closer to the source than v. An edge between consecutive levels (other than the tree parent edge) is allowed and does not contradict shortest paths.

  • 0: This indicates u and v are at the same distance from s. Such cross edges between vertices on the same BFS level may exist and are simply not part of the BFS tree.

  • 1: This indicates u is one level farther from the source than v. As with -1, edges between adjacent levels are possible.

Conclusion: The only value among the choices that cannot occur for d(u) - d(v) is 2.

A video solution is available for this question — log in and enroll to watch it.

Explore the full course: Gate Guidance By Sanchit Sir