Skip to content
Official PYQ · 2024

GATE CS 2024 Set 1 Q50 — Graph Traversals (BFS, DFS)

Explain with AI
The number of edges present in the forest generated by the DFS\text{DFS} traversal of an undirected graph GG with 100100 vertices is 4040. The number of connected components in GG is __________.
View worked solution

Answer: 60

A Depth-First Search (DFS\text{DFS}) traversal of an undirected graph G=(V,E)G = (V, E) produces a spanning forest (DFS forest) of the graph. This forest has the following properties:

  1. It contains all the vertices of the original graph GG. Thus, the number of vertices in the forest is V=100V = 100.
  2. The number of connected components (trees) in the DFS forest is exactly equal to the number of connected components in the original graph GG.

For any forest with VV vertices, EforestE_{\text{forest}} edges, and CC connected components, the relationship is given by:

V=Eforest+CV = E_{\text{forest}} + C

Rearranging the formula to find the number of connected components CC:

C=V−EforestC = V - E_{\text{forest}}

Substituting the given values:

C=100−40=60C = 100 - 40 = 60

Thus, the number of connected components in GG is 60.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Graph Traversals (BFS, DFS) questions