I know graphx's connectedComponents()
method will label each connected component of the graph with the ID of its lowest-numbered vertex. Is there a method call to count the number of connected components in graphx?
Asked
Active
Viewed 1,388 times
2
1 Answers
4
You could use the connectedComponents()
to get this count. First run the method on your graph, then count the number of unique VertexId
that is in the result. In Scala:
graph.connectedComponents().vertices.map{ case(_,cc) => cc}.distinct.count()

Shaido
- 27,497
- 23
- 70
- 73