---
title: "Degree Centrality"
description: "Overview of TigerGraph's implementation of an algorithm that calculates the degree centrality of vertices."
component: "graph-ml"
version: "3.10"
module: "centrality-algorithms"
html_url: "/graph-ml/3.10/centrality-algorithms/degree-centrality"
canonical_url: "https://www.tigergraph.com/docs/graph-ml/3.10/centrality-algorithms/degree-centrality"
markdown_url: "https://www.tigergraph.com/docs/graph-ml/3.10/centrality-algorithms/degree-centrality.md"
---

[View as HTML](https://www.tigergraph.com/docs/graph-ml/3.10/centrality-algorithms/degree-centrality)

# Degree Centrality

Supported Graph Characteristics

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

Algorithm link: [Degree Centrality](https://github.com/tigergraph/gsql-graph-algorithms/tree/master/algorithms/Centrality/degree)

**Degree centrality** is defined as the number of edges incident upon a vertex (i.e., the number of ties that a node has).

One major application of degree centrality is in cybersecurity, and more generally, network management.

The degree can be interpreted in terms of the immediate risk of a node for catching whatever is flowing through the network (such as a virus, or some information).

## Specifications

CREATE QUERY tg_degree_cent(SET<STRING> v_type_set, SET<STRING> e_type_set,
  SET<STRING> reverse_e_type_set, BOOL in_degree = TRUE, BOOL out_degree = TRUE,
  INT top_k=100, BOOL print_results = True, STRING result_attribute = "",
  STRING file_path = "")

### Parameters

| Name | Description | Default value |
| --- | --- | --- |
| `SET<STRING> v_type_set` | A set of vertex types. | (empty set of strings) |
| `SET<STRING> e_type_set` | A set of edge types. | (empty set of strings) |
| `SET<STRING> reverse_e_type_set` | A set of reverse edge types. If an edge is undirected, put the edge name in the set as well. | (empty set of strings) |
| `BOOL in_degree` | Boolean value that indicates whether to count the incoming edges as part of a vertex's degree centrality. | True |
| `BOOL out_degree` | Boolean value that indicates whether to count the outgoing edges as part of a vertex's degree centrality. | True |
| `INT top_k` | The number of vertices with the highest scores to return. | 100 |
| `BOOL print_results` | If true, print results to JSON output. | True |
| `STRING result_attribute` | If not empty, save the degree centrality score of each vertex to this attribute. | (empty string) |
| `STRING file_path` | If not empty, save results in CSV to this file. | (empty string) |

### Output

The vertices with the highest degree centrality scores along with their scores.

### Time complexity

The algorithm has a time complexity of \\(O(E)\\), where \\(E\\) is the total number of edges in the graph.

### Run commands

#### Schema-Free Query

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

#### Packaged Template Query

```gsql
CALL GDBMS_ALGO.centrality.degree_cent (<parameters>)
```

## Example

Suppose we have the following graph:

![social graph 2022 10](https://www.tigergraph.com/docs/graph-ml/3.10/centrality-algorithms/_images/social-graph-2022-10.png) 

Running the query on the graph will show that Dan has the highest degree centrality:

* Query
* Result

```gsql
RUN QUERY tg_degree_cent(["person"], ["friendship"],["friendship"])
```

```json
[
  {
    "top_scores": [
      {
        "Vertex_ID": "Dan",
        "score": 4
      },
      {
        "Vertex_ID": "Jenny",
        "score": 3
      },
      {
        "Vertex_ID": "Nancy",
        "score": 3
      },
      {
        "Vertex_ID": "Vicki",
        "score": 3
      },
      {
        "Vertex_ID": "Jack",
        "score": 3
      },
      {
        "Vertex_ID": "Juan",
        "score": 2
      },
      {
        "Vertex_ID": "Emily",
        "score": 2
      },
      {
        "Vertex_ID": "Kevin",
        "score": 2
      },
      {
        "Vertex_ID": "Tom",
        "score": 2
      },
      {
        "Vertex_ID": "Denise",
        "score": 1
      },
      {
        "Vertex_ID": "Ben",
        "score": 1
      }
    ]
  }
]
```
