You run DFS / BFS on graph , all the nodes that are connected will form one DFT / BFT. Non Connected vertices are left. We rerun DFS / BFS on them to get another DFT/BFT.
DFT/BFT in itself a connected Graph => if there are x nodes then there will be x-1 edges for sure.
Given DFT has k edges => k=x-1 => x=k+1 nodes k+1 nodes in DFT => 1 connected component
We do not need to think about the forward backward or cross edges . Why???? Bcoz we have already got the no of nodes and that’s it.
Left vertices – n-(k+1) => n-k-1 nodes that were not part of DFT => n-k-1 components
Total = 1+ n-k-1 = n-k connected components