Please tell me if my proof is correct or not
We have a connected graph, and specific vertex u in V(G).
Suppose we compute the dfs tree of G rooted at u and obtain tree T.
Now imagine we compute the bfs tree of G rooted at u and we obtain the same tree T.
Prove that the only way this is possible is if G=T
Proof by contradiction.
Assume that dfs tree and bfs tree are equal to T, but G is not equal to T.
This implies that G contains at least one edge not in T.
We also know that any such edges are part of a cycle, otherwise they would have been in T.
So there is at least one Cycle C= p1, p2, p3, p_{k}
with p_{k} = p1
, consisting of distinct nodes k>= 3
, in G.
Assume that dfs and bfs algorithms will encounter the cycle at node p1
.
Dfs will add the following edges to its tree (p1, p2)
, ...., (p_{k-2}
,(p_{k-1})
whereas bfs begins by adding edges (p1,p2)
, (p1,p_{k})
to its tree.
Already we see that dfs tree is not equal to bfs tree since bfs contains (p1,p_{k})
and dfs doesn’t contain this edge.
This contradicts our assumption that dfs and bfs have equal trees, and shows it must be the case that G=T.