The Local Clustering Coefficient algorithm calculates the density of connection among the immediate neighbors of a node. It quantifies the ratio of actual connections among the neighbors to the maximum possible connections.
The local clustering coefficient provides insights into the cohesion of a node's ego network. In the context of a social network, the local clustering coefficient helps understand the degree of interconnectedness among an individual's friends or acquaintances. A high local clustering coefficient suggests that the person's friends are likely to be connected to each other, indicating the presence of a closely-knit social group, such as a family. Conversely, a low local clustering coefficient indicates a more dispersed or loosely interconnected ego network, where the person's friends do not have strong connections with each other.
Mathematically, the local clustering coefficient of a node in an undirected graph is calculated as the ratio of the number of connected neighbor pairs to the total number of possible neighbor pairs:

where n is the number of nodes contained in the 1-hop neighborhood of node v (denoted as N(v)), i and j are any two distinct nodes within N(v), δ(i,j) is equal to 1 if i and j are connected, and 0 otherwise.

In this example, the local clustering coefficient of the red node is 1/(5*4/2) = 0.1.

Run the following statements on an empty graph to define its structure and insert data:
ALTER GRAPH CURRENT_GRAPH ADD EDGE { knows ()-[]->() }; INSERT (Lee:default {_id: "Lee"}), (Choi:default {_id: "Choi"}), (Mia:default {_id: "Mia"}), (Fiona:default {_id: "Fiona"}), (Chang:default {_id: "Chang"}), (John:default {_id: "John"}), (Park:default {_id: "Park"}), (Choi)-[:knows]->(Park), (Choi)-[:knows]->(Lee), (Park)-[:knows]->(Lee), (Park)-[:knows]->(Mia), (Lee)-[:knows]->(Mia), (Mia)-[:knows]->(Fiona), (Fiona)-[:knows]->(Lee), (Lee)-[:knows]->(Chang), (Lee)-[:knows]->(John), (John)-[:knows]->(Fiona);
To load the entire graph to the HDC server hdc-server-1 as my_hdc_graph:
CREATE HDC GRAPH my_hdc_graph ON "hdc-server-1" OPTIONS { nodes: {"*": ["*"]}, edges: {"*": ["*"]}, direction: "undirected", load_id: true, update: "static" }
Algorithm name: clustering_coefficient
Name | Type | Spec | Default | Optional | Description |
|---|---|---|---|---|---|
ids | []_id | / | / | Yes | Specifies nodes for computation by their _id. If unset, computation includes all nodes. |
uuids | []_uuid | / | / | Yes | Specifies nodes for computation by their _uuid. If unset, computation includes all nodes. |
return_id_uuid | String | uuid, id, both | uuid | Yes | Includes _uuid, _id, or both to represent nodes in the results. |
limit | Integer | ≥-1 | -1 | Yes | Limits the number of results returned; -1 includes all results. |
order | String | asc, desc | / | Yes | Sorts the results by local clustering coefficient clce_centrality. |
CALL algo.clustering_coefficient.write("my_hdc_graph", { ids: ["Lee", "Choi"], return_id_uuid: "id" }, { file: { filename: "lcc" } })
Result:
File: lcc_id,clce_centrality Lee,0.266667 Choi,1
Writes the clce_centrality values from the results to the specified node property. The property type is float.
CALL algo.clustering_coefficient.write("my_hdc_graph", {}, { db: { property: "lcc" } })
CALL algo.clustering_coefficient.run("my_hdc_graph", { return_id_uuid: "id", order: "desc" }) YIELD r RETURN r
Result:
| _id | clce_centrality |
|---|---|
| John | 1 |
| Choi | 1 |
| Park | 0.666667 |
| Fiona | 0.666667 |
| Mia | 0.666667 |
| Lee | 0.266667 |
| Chang | 0 |
CALL algo.clustering_coefficient.stream("my_hdc_graph", {}) YIELD r FILTER r.clce_centrality = 1 RETURN count(r)
Result: 2