Open In App

GATE | Gate IT 2005 | Question 14

Like Article
Like
Save
Share
Report

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
(A) k
(B) k + 1
(C) n – k – 1
(D) n – k


Answer: (D)

Explanation: Tree edges are the edges that are part of DFS tree.  If there are x tree edges in a tree, then  x+1 vertices in the tree.

The output of DFS is a forest if the graph is disconnected.  Let us see below simple example where graph is disconnected.

example

 

The above example matches with D option

More Examples:

1) All vertices  of Graph are connected.  k must be n-1.  We get number of connected components  = n- k =  n – (n-1) = 1

2) No vertex is connected. k must be 0.  We get number of connected components  = n- k =  n – 0 = n

Quiz of this Question


Last Updated : 28 Jun, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads