How does DFS(G,v) behaves for disconnected graphs ?
Suppose a graph has 3 connected components and DFS is applied on one of these 3 Connected components, then do we visit every component or just the on whose vertex DFS is applied.
Means Is it correct to say that
DFS on a graph having many components covers only 1 component.
I also tried online DFS visualization tools for disconnected graphs and they also support that it covers only 1 component. But still I want to confirm
In fact, DFS is often used to determine whether or not a graph is disconnected or not - if we run DFS and do not reach all of the nodes in the graph, the graph must be disconnected.
Kruskal Algorithm on disconnected graph - Codeforces.
Disconnected graph is a Graph in which one or more nodes are not the endpoints of the graph i.e. they are not connected. Now, the Simple BFS is applicable only when the graph is connected i.e. all vertices of the graph are accessible from one node of the graph.
Depth First Search (DFS) is a systematic way of visiting the nodes of either a directed or an undirected graph. As with breadth first search, DFS has a lot of applications in many problems in Graph Theory. It comprises the main part of many graph algorithms. DFS visits the vertices of a graph in the following manner.
Starting a search on a single component of a disconnected graph will search only that component; how could it be otherwise? There's no information to make a decision about when, how or where to move the search to a different component.
If you want to perform a complete search over a disconnected graph, you have two high level options:
Note that the same reasoning applies to breadth first searches as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With