IAE Academy

GATE 2024 CS1 Q.60: solution and answer

GATE 2024 · CS1Q.60 · 2 marks · NAT

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)

See the question in the paper

Answer and solution

ANSWER

The number of connected components in G is 60.

Official answer: 60Source: Official answer key, GATE 2024 CS1 (IISc Bengaluru)

  1. 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.

  2. A spanning tree on a component with vertices has exactly tree edges.

  3. Summing over all connected components: total forest edges , where is the total number of vertices and is the number of connected components.

  4. Given and total forest edges :

  5. 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