The number of edges present in the forest generated by the DFS traversal of an undirected graph with 100 vertices is 40. The number of connected components in is _____ (answer in integer)
GATE 2024 CS1 Q.60: solution and answer
Answer and solution
ANSWER
The number of connected components in G is 60.
Official answer: 60Source: Official answer key, GATE 2024 CS1 (IISc Bengaluru)
DFS traversal of an undirected graph produces a spanning forest: it visits every vertex, and within each connected component the DFS tree edges form a spanning tree of that component.
A spanning tree on a component with vertices has exactly tree edges.
Summing over all connected components: total forest edges , where is the total number of vertices and is the number of connected components.
Given and total forest edges :
Solving:
KEY IDEA
A DFS (or BFS) traversal of an undirected graph produces a spanning forest with exactly one tree per connected component, and a spanning tree on vertices has exactly edges.
WATCH OUT FOR
Treating the graph's total edge count as equal to the forest's edge count (ignoring that non-tree/back edges are excluded from the DFS forest), or forgetting the per component and computing instead of .
From the GATE 2024 CS1 paper. Every question of this paper · Download the full paper · All 28 Graph algorithms questions, with notes
More Graph algorithms questions
- GATE 2024 CS2 Q.59 · NAT · 2 marksThe number of distinct minimum-weight spanning trees of the following graph is.
- GATE 2024 DA Q.14 · MCQ · 1 markConsider performing depth-first search (DFS) on an undirected and unweighted graph G starting at vertex s.
- GATE 2024 DA Q.51 · MSQ · 2 marksConsider the directed acyclic graph (DAG) below. Which of the following is/are valid vertex orderings that…
- GATE 2023 CS Q.56 · NAT · 2 marksLet U = 1, 2, 3. Let 2^U denote the powerset of U. Consider an undirected graph G whose vertex set is 2^U.
