Connected components

In graph theory, the connected component is the subgraph that is any two vertices that are reachable using edge paths. The whole graph can be a single connected component as well. Consider the following example, which is an extension of examples provided in the Property Graph section:

Logical representation of a graph with two connected components

Here, we have two connected components. Nodes 1 to 5 form a connected component where every node is connected to each other using some edge path. Similarly, nodes 6 and 7 form another connected component.

The connectedComponents operations label each of the other nodes in the connected components of a graph with the vertex ID of its lowest-numbered vertex. Therefore, considering the example provided previously, nodes 1 to 5 will be labeled as 1 and nodes 6 and 7 will be labeled as 6.

The connectedComponents operation in a Spark graph can be executed as follows:

Graph<Object, string> connectedComponentsGraph = graph.ops().connectedComponents(); 

This operation will return a graph where the vertex property is the respective label of the vertex, which can be verified as follows:

connectedComponentsGraph.vertices().toJavaRDD().collect().forEach(System.out::println);
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.202.61