1

Which approach should we use to find all disconnected graphs and why ?

As BFS and DFS traversal both are traversal methods and by multiple traversals. We can find all disconnected components.
And another approach can be Disjoint Sets as used in kruskal (MST) to find disconnected components.

c0der
  • 18,467
  • 6
  • 33
  • 65
Aadish Goel
  • 451
  • 1
  • 4
  • 12

1 Answers1

0

Simply because you stated that you need to find all disconnected graphs, I would recommend using BFS as it is complete, depth-first search is not. When applied to infinite graphs represented implicitly, BFS will find the goal state, in your scenario, will find all disconnected graphs. DFS, on the other hand, may get lost in parts of the graph that contain no goal state, and essentially, may get lost.

Luke Garrigan
  • 4,571
  • 1
  • 21
  • 29