Graph Algorithms

Answer & solution
Official answer: B, C, D
A is false. In a triangle with edges s–u,u–v,s–v, DFS may choose tree edges s–u and u–v. Its tree distance from s to v is then 2 even though the graph contains a length-1 path s–v. DFS prioritizes depth, not distance.
B is true for undirected DFS. If an edge from a currently explored vertex reaches an unvisited vertex, DFS follows it before finishing that subtree. Consequently an undirected non-tree edge cannot join two completely separate DFS subtrees; its endpoints have an ancestor-descendant relationship. It is usually called a back edge when oriented toward the ancestor. The question's “forward/back” wording refers to that relationship, not to a separate undirected cross-edge type.
C follows from shortest-path distances. For any edge u–v, a shortest route to u followed by that edge shows d(s,v)≤d(s,u)+1. Reversing the roles gives d(s,u)≤d(s,v)+1. BFS tree levels equal these distances, so their difference is at most one.
D is true: traverse from an unvisited vertex, mark its entire component, and repeat while any vertex remains unvisited. This works with either BFS or DFS, including isolated vertices. Select B,C,D.



