Let be a simple undirected graph, and be a particular vertex in it called the source. For , let denote the shortest distance in from to . A breadth first search (BFS) is performed starting at . Let be the resultant BFS tree. If is an edge of that is not in , then which one of the following CANNOT be the value of ?
View worked solution
Answer: D
In an unweighted, undirected graph , the shortest distance from a source vertex to any vertex is the minimum number of edges on a path between them.
For any edge (regardless of whether it is selected in the BFS tree or not), the triangle inequality for shortest path distances must hold:
- The shortest path to cannot be longer than the shortest path to plus the edge :
- Similarly, the shortest path to cannot be longer than the shortest path to plus the edge :
Combining these two inequalities, we get:
Since the distance function only takes non-negative integer values, the only possible values for are , , and .
Therefore, CANNOT be .
Free practice · Your answers on this page are not saved.
