Graph Connectivity Testing
excerpt: The BFS and DFS lead to graph connectivity testing with only minor modifications. tags: graphconnectivity
The [BFS]({% post_url 20210421breadthfirsttraversal %}) and [DFS]({% post_url 20210420depthfirsttraversal %}) traversal visits all the nodes that are reachable from the start node. For an undirected graph, that means it visits every node in the graph if the graph is connected.
Connectivity
The algorithm to determine whether an undirected graph is connected:


The connected? method uses the traverse method discussed in an earlier article and then checks if there are any node that has not been visited. This method can be extended to find all the connected components in a graph. Simply use the traversal method repeatedly until all the nodes are visited.