2

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?

Shaido
  • 27,497
  • 23
  • 70
  • 73
ELI
  • 359
  • 1
  • 4
  • 20

1 Answers1

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