0

I wanted to find number of connected components in a directed graph but if we try using the general method that traverse nodes from 1 to n and for each node reach all its connected nodes and if we find any unreached node then we will take that node as another component.

enter image description here

.In this example , at least one of 4 or 7 can not be traversed as same (and will only be visited when started from there). So show me the algo that can consider it as the same component of a graph.

ravenspoint
  • 19,093
  • 6
  • 57
  • 103

1 Answers1

0

Nodes 4 and 7 are unreachable from each other, because their in-degrees are zero. That is, there are no directed edges point to them.

If you want to, for some reason, consider them "connected" because they have edges 'connecting' them to the rest of the graph even though the edges are directed the 'wrong' way, then you must modify the graph to replace all the directed edges with undirected and then run the "general method".

ravenspoint
  • 19,093
  • 6
  • 57
  • 103