edited by
17,879 views
65 votes
65 votes

In a depth-first traversal of a graph $G$ with $n$ vertices, $k$ edges are marked as tree edges. The number of connected components in $G$ is

  1. $k$
  2. $k+1$
  3. $n-k-1$
  4. $n-k$
edited by

12 Answers

0 votes
0 votes
In a graph G with n vertices and p component then G has n - p edges(k).
In this question, we are going to applying the depth first search traversal on each component of graph where G is conected (or) disconnected which gives minimum spanning tree
i.e., k = n-p
p = n - k
0 votes
0 votes
Total there will be N-1 edges in DFS graph of “N” vertices as DFS is acyclic. Since there are “k” edges for trees so we are left with “N-k-1” independent edges . Thus component wise total components are ( N-k-1 ) + 1. This last one is for the tree. Hence total N-k components.
0 votes
0 votes

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

Answer:

Related questions