UltipaDocs
Products
Solutions
Resources
Company
Start Free Trial
UltipaDocs
Start Free Trial
  • Introduction
  • Running Algorithms
    • Degree Centrality
    • Closeness Centrality
    • Harmonic Centrality
    • Eccentricity Centrality
    • Betweenness Centrality
    • Bridges
    • Articulation Points
    • Eigenvector Centrality
    • Katz Centrality
    • CELF
    • PageRank
    • ArticleRank
    • TextRank
    • HITS
    • SybilRank
    • Jaccard Similarity
    • Overlap Similarity
    • Cosine Similarity
    • Pearson Correlation Coefficient
    • Euclidean Distance
    • KNN
    • Vector Similarity
    • Bipartite Graph
    • HyperANF
    • Weakly Connected Components (WCC)
    • Strongly Connected Components (SCC)
    • k-Edge Connected Components
    • Local Clustering Coefficient
    • Triangle Count
    • Clique Count
    • k-Core
    • k-Truss
    • p-Cohesion
    • Induced Subgraph
    • Topological Sort
    • Breadth-First Search (BFS)
    • Depth-First Search (DFS)
    • Dijkstra's Shortest Path
    • A* Shortest Path
    • Yen's K-Shortest Paths
    • Shortest Path (BFS)
    • Delta-Stepping SSSP
    • Shortest Path Faster Algorithm (SPFA)
    • All-Pairs Shortest Path (APSP)
    • Minimum Spanning Tree (MST)
    • K-Spanning Tree
    • Steiner Tree
    • Prize-Collecting Steiner Tree (PCST)
    • Minimum Cost Flow
    • Maximum Flow
    • K-Hop Fast
    • Longest Path (DAG)
    • Random Walk
    • Adamic-Adar Index
    • Common Neighbors
    • Preferential Attachment
    • Resource Allocation
    • Total Neighbors
    • Same Community
    • Louvain
    • Leiden
    • Modularity Optimization
    • Label Propagation
    • HANP
    • SLPA
    • k-Means
    • HDBSCAN
    • K-1 Coloring
    • Modularity
    • Conductance
    • Max k-Cut
      • Node2Vec
      • Struc2Vec
      • LINE
      • Fast Random Projection
      • Summary of Graph Embedding
      • Gradient Descent
      • Backpropagation
      • Skip-gram
      • Skip-gram Optimization
  1. Docs
  2. /
  3. Graph Algorithms
  4. /
  5. Graph Structure

Local Clustering Coefficient

Overview

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, 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. Conversely, a low local clustering coefficient indicates a more dispersed ego network.

Concepts

Local Clustering Coefficient

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.

Example Graph

GQL
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)

Parameters

NameTypeDefaultDescription
directionSTRINGbothEdge direction: in, out, or both.
limitINT-1Limits the number of results returned (-1 = all).
orderSTRING/Sorts the results by coefficient: asc or desc.

Run Mode

Returns:

ColumnTypeDescription
nodeIdSTRINGNode identifier (_id)
coefficientFLOATLocal clustering coefficient
trianglesINTNumber of triangles containing the node
degreeINTDegree of the node
GQL
CALL algo.localclusteringcoefficient({
  order: "desc"
}) YIELD nodeId, coefficient, triangles, degree

Result:

nodeIdcoefficienttrianglesdegree
Choi112
John112
Mia0.666666666666666623
Park0.666666666666666623
Fiona0.666666666666666623
Lee0.2666666666666666646
Chang001

Stream Mode

Returns the same columns as run mode, streamed for memory efficiency.

GQL
CALL algo.localclusteringcoefficient.stream({direction: "in"}) YIELD nodeId, coefficient
RETURN nodeId, coefficient

Result:

nodeIdcoefficient
Choi0
Mia0.5
Lee0
Park0
Chang0
John0
Fiona0

Stats Mode

Returns:

ColumnTypeDescription
nodeCountINTTotal number of nodes
avgCoefficientFLOATAverage local clustering coefficient
globalClusteringCoefficientFLOATGlobal clustering coefficient (3 * triangles / triples)
GQL
CALL algo.localclusteringcoefficient.stats() YIELD nodeCount, avgCoefficient, globalClusteringCoefficient

Result:

nodeCountavgCoefficientglobalClusteringCoefficient
70.60952380952380950.46153846153846156

Write Mode

Computes results and writes them back to node properties. The write configuration is passed as a second argument map.

Write parameters:

NameTypeDescription
db.propertySTRING or MAPNode property to write results to. String: writes the coefficient column in results to a property. Map: explicit column-to-property mapping (e.g., {coefficient: 'lcc', triangles: 'tri'}).

Writable columns:

ColumnTypeDescription
coefficientFLOATLocal clustering coefficient
trianglesINTTriangle count
degreeINTNode degree

Returns:

ColumnTypeDescription
task_idSTRINGTask identifier for tracking via SHOW TASKS
nodesWrittenINTNumber of nodes with properties written
computeTimeMsINTTime spent computing the algorithm (milliseconds)
writeTimeMsINTTime spent writing properties to storage (milliseconds)
GQL
CALL algo.localclusteringcoefficient.write({}, {
  db: {
    property: "lcc"
  }
}) YIELD task_id, nodesWritten, computeTimeMs, writeTimeMs