edited by
354 views
3 votes
3 votes
Let $G = (V, E)$ be a simple undirected graph with all edge weights being unity, 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 the number of possible values of $d(u) - d(v)$ is $\_\_\_\_\_\_\_.$
edited by

1 Answer

Best answer
3 votes
3 votes
Since graph is undirected either $(u,v)$ or $(v,u)$ can be visited first and these give $d(u) - d(v) = -1$ and $1$ respectively. This edge $(u,v)$ may not be in the BFS tree if say there is another edge $(t,v)$ in the BFS tree and both $t$ and $u$ are siblings.
   
   We can have $d(u) - d(v) = 0$ when both $u$ and $v$ have a common parent.
   
   Since, there is an edge $(u,v)$ in $G,$ and edge weights being unity, the shortest path from $s$ to $u$ and $v$ cannot differ by more than $1.$ So, there are only $3$ possible values for $d(u) - d(v).$
selected by
Answer:

Related questions

3 votes
3 votes
1 answer
2
gatecse asked Sep 7, 2020
170 views
Given any two vertices in an undirected finite graph, which of the two graph traversal algorithms BFS and DFS can be used to find if there is path between them?Only B...