---
title: "Local Clustering Coefficient"
component: "graph-ml"
version: "3.10"
module: "community-algorithms"
html_url: "/graph-ml/3.10/community-algorithms/local-clustering-coefficient"
canonical_url: "https://www.tigergraph.com/docs/graph-ml/3.10/community-algorithms/local-clustering-coefficient"
markdown_url: "https://www.tigergraph.com/docs/graph-ml/3.10/community-algorithms/local-clustering-coefficient.md"
---

[View as HTML](https://www.tigergraph.com/docs/graph-ml/3.10/community-algorithms/local-clustering-coefficient)

# Local Clustering Coefficient

Supported Graph Characteristics

| Unweighted edges |
| --- |
| Undirected edges |
| Homogeneous vertex types |

Algorithm link: [Local Clustering Coefficient](https://github.com/tigergraph/gsql-graph-algorithms/tree/master/algorithms/Community/local%5Fclustering%5Fcoefficient)

The _local clustering coefficient_ of a vertex in a graph quantifies how close its neighbors are to being a complete graph. In a complete graph, every two distinct vertices are connected.

This algorithm computes the local clustering coefficient of every vertex in a graph.

It is obtained by dividing the number of edges between a vertex's neighbors by the number of edges that could possibly exist.

For more information, see [Clustering Coefficient](https://en.wikipedia.org/wiki/Clustering%5Fcoefficient).

## Notes

The algorithm does not report the local clustering coefficient for vertices that have only one neighbor.

Local Clustering Coefficient only works with directed graphs if reverse edges are included.

## Specifications

```gsql
tg_lcc(STRING v_type, STRING e_type,INT top_k=100,
  BOOL print_results = True, STRING result_attribute = "",
  STRING file_path = "", BOOL display_edges = FALSE)
```

### Time complexity

\\$O(V)\\$, where \\$V\\$ is the number of vertices in the graph.

### Parameters

| Parameter | Description | Data type |
| --- | --- | --- |
| `STRING v_type` | Vertex type to calculate local clustering coefficient for | (empty string) |
| `STRING e_type` | Edge type to traverse. Only vertices that are connected by edges of this type are treated as connected in this algorithm. | (empty string) |
| `INT top_k` | Number of the highest local clustering coefficients to report. | 100 |
| `BOOL print_results` | If `true`, output JSON to standard output. | True |
| `STRING result_attribute` | If provided, the local clustering coefficient of a vertex will be saved to this attribute. | (empty string) |
| `STRING file_path` | If provided, write output to this file in CSV. | (empty string) |
| `BOOL display_edges` | If true, the algorithm will also return edges, which help produce better visualized results in GraphStudio. | False |

### Run commands

#### Schema-Free Query

```gsql
RUN QUERY tg_lcc (<parameters>)
```

#### Packaged Template Query

```gsql
CALL GDBMS_ALGO.community.lcc (<parameters>)
```

## Example

Using the `social` graph below as an example, Jenny has three neighbors - Tom, Dan and Amily, but only Tom and Dan are connected. Between the three neighbors, the maximum number of edges that could exist is 3\. Therefore, the local clustering coefficient for Jenny is 1/3.

On the other hand, Tom has two neighbors that are connected by one edge. Since the maximum number of edges that could exist between two vertices is 1, Tom has a local clustering coefficient of 1/1 = 1.

![image (78)](https://www.tigergraph.com/docs/graph-ml/3.10/community-algorithms/_images/image%20(78).png) 

By running the algorithm in GSQL, we can confirm that Tom has the highest local clustering coefficient with a score of 1 and Jenny has a score of 1/3.

```bash
RUN QUERY tg_lcc("person", "friendship", _, _, _, _, _)

{
  "error": false,
  "message": "",
  "version": {
    "schema": 0,
    "edition": "enterprise",
    "api": "v2"
  },
  "results": [{"top_scores": [
    {
      "score": 1,
      "Vertex_ID": "Tom"
    },
    {
      "score": 0.33333,
      "Vertex_ID": "Jenny"
    },
    {
      "score": 0.16667,
      "Vertex_ID": "Dan"
    },
    {
      "score": 0,
      "Vertex_ID": "Nancy"
    }
  ]}]
}
```
