I have been going through Breadth First Traversal at this link
Breadth First Traversal
Now what if the graph structure is changed to this
The node 3 is now disconnected from the graph. When traversal program is now used, it does'nt display vertex 3. Is there a way where we can dispaly this vertex as well?
An undirected graph G is therefore disconnected if there exist two vertices in G such that no path in G has these vertices as endpoints. A graph with just one vertex is connected. An edgeless graph with two or more vertices is disconnected.
A graph is said to be disconnected if it is not connected, i.e., if there exist two nodes in such that no path in has those nodes as endpoints. The numbers of disconnected simple unlabeled graphs on. , 2, ... nodes are 0, 1, 2, 5, 13, 44, 191, ...
To my understanding, BFS would keep looking for unvisited nodes as long as they exist; however, if this is not done, BFS only visits nodes in the connected component of the initial vertex. This seems to be more a matter of definition than an actual programming problem; simply restart the BFS implementation on unvisited nodes as long as they exist - if visiting of all connected components is desired.
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