I have a boolean[][] 2D-array called matrix, which encodes a directed graph such that if matrix[i][j] == true, then vertex j is connected to vertex i (the inverse is not necessarily true).
I’m trying to create a Java method that will determine how many disjoint directed graphs I have.
So for Example, if vertex 0 was connected to vertex 1, and vertex 2 was connected to vertex 3
(<code>[{{0,0,0,0},{1,0,0,0},{0,0,0,0},{0,0,1,0}}]</code> would be the 2D array), I would have 2 disjoint digraphs.
If there are no connections, the number of disjoint digraphs would equal the number of vertices.
Start with a list of all of the nodes in the tree. Consider these your unvisited nodes.
Then repeat the following process until your list of unvisited nodes is gone.
Once this process is complete, your node-sets correspond to the nodes that uniquely exist in each disjoint graph, so the number of node-sets is the value you seek.