Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disconnected node during Graph traversal

I have been going through Breadth First Traversal at this link
Breadth First Traversal

Now what if the graph structure is changed to this

Graph

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?

like image 807
Pradeep Avatar asked Nov 24 '14 11:11

Pradeep


People also ask

Can a graph have a disconnected node?

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.

What is a disconnected graph in graph theory?

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, ...


1 Answers

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.

like image 129
Codor Avatar answered Sep 30 '22 18:09

Codor