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. Centrality

Degree Centrality

Overview

The Degree Centrality finds important nodes in the network, it measures the number of incoming and/or outgoing edges incident to the node, or the sum of weights of those edges. Degree is the simplest and most efficient graph algorithm since it only considers the 1-hop neighborhood of nodes. Degree plays a vital role in scientific computing, feature extraction, supernode recognition and other fields.

Concepts

In-Degree and Out-Degree

The number of incoming edges a node has is called its in-degree; accordingly, the number of outgoing edges is called out-degree. If ignores edge direction, it is degree.

In this graph, the red node has in-degree of 4 and out-degree of 3, and its degree is 7. A directed self-loop is regarded as both an incoming and an outgoing edge.

Weighted Degree

In many applications, each edge of a graph has an associated numeric value, called weight. In weighted graph, weighted degree of a node is the sum of weights of all its neighbor edges. Unweighted degree is equivalent to when all edge weights are 1.

In this weighted graph, the red node has weighted in-degree of 0.5 + 0.3 + 2 + 1 = 3.8 and weighted out-degree of 1 + 0.2 + 2 = 3.2, and its weighted degree is 3.2 + 3.8 = 7.

Considerations

  • The degree of an isolated node depends only on its self-loop. If it has no self-loop, degree is 0.
  • Every self-loop is counted as two edges attaching to its node. Directed self-loop is viewed as an incoming edge and an outgoing edge.

Example Graph

GQL
INSERT (Mike:user {_id: "Mike"}), (Cathy:user {_id: "Cathy"}),
       (Anna:user {_id: "Anna"}), (Joe:user {_id: "Joe"}),
       (Sam:user {_id: "Sam"}), (Bob:user {_id: "Bob"}),
       (Bill:user {_id: "Bill"}), (Tim:user {_id: "Tim"}),
       (Mike)-[:follow {score: 1.9}]->(Cathy), (Cathy)-[:follow {score: 1.8}]->(Mike),
       (Mike)-[:follow {score: 1.2}]->(Anna), (Cathy)-[:follow {score: 2.6}]->(Anna),
       (Cathy)-[:follow {score: 0.2}]->(Joe), (Joe)-[:follow {score: 4.2}]->(Anna),
       (Bob)-[:follow {score: 1.7}]->(Joe), (Sam)-[:follow {score: 3.5}]->(Bob),
       (Sam)-[:follow {score: 0.8}]->(Anna), (Bill)-[:follow {score: 2.3}]->(Anna)

Parameters

NameTypeDefaultDescription
idsLIST/_ids of nodes to compute (empty = all nodes).
directionSTRINGbothEdge direction: in, out, or both.
normalizedBOOLfalseWhether to normalize scores. When true, uses scoreBase to determine the denominator.
scoreBaseSTRINGmaxNormalization base, only effective when normalized is true. max divides by the max degree; count divides by node count - 1.
weightSTRING or LIST/Edge property name(s) for weighted degree.
limitINT-1Limits the number of results returned (-1 = all).
orderSTRING/Sorts the results by score: asc or desc.

Run Mode

Returns:

ColumnTypeDescription
nodeIdSTRINGNode identifier (_id)
degreeFLOATDegree count (or weighted sum)
scoreFLOATDegree score (normalized if normalized is true)
inDegreeINTIn-degree count
outDegreeINTOut-degree count
weightScoresMAPPer-property weighted degree breakdown (only present when weight is used)

Normalized degree for all nodes:

GQL
CALL algo.degree({
  normalized: true,
  order: "desc"
}) YIELD nodeId, degree, score, inDegree, outDegree

Result:

nodeIddegreescoreinDegreeoutDegree
Anna5150
Cathy40.813
Joe30.621
Mike30.612
Bob20.411
Sam20.402
Bill10.201
Tim0000

Out-degree top 3:

GQL
CALL algo.degree({
  direction: "out",
  order: "desc",
  limit: 3
}) YIELD nodeId, degree

Result:

nodeIddegree
Cathy3
Mike2
Sam2

Weighted degree:

GQL
CALL algo.degree({
  weight: "score",
  order: "desc"
}) YIELD nodeId, degree, weightScores

Result:

nodeIddegreeweightScores
Anna11.1{score: 11.1}
Cathy6.5{score: 6.5}
Joe6.1{score: 6.1}
Bob5.2{score: 5.2}
Mike4.9{score: 4.9}
Sam4.3{score: 4.3}
Bill2.3{score: 2.3}
Tim0{score: 0}

Stream Mode

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

Find neighbors of the node with the highest out-degree:

GQL
CALL algo.degree.stream({
  direction: "out",
  order: "desc",
  limit: 1
}) YIELD nodeId, degree
MATCH (src WHERE src._id = nodeId)-(neigh)
RETURN DISTINCT neigh._id

Result:

neigh._id
Anna
Joe
Mike

Stats Mode

Returns:

ColumnTypeDescription
nodeCountINTTotal number of nodes
minScoreFLOATMinimum degree score
maxScoreFLOATMaximum degree score
avgScoreFLOATAverage degree score
GQL
CALL algo.degree.stats() YIELD nodeCount, minScore, maxScore, avgScore

Result:

nodeCountminScoremaxScoreavgScore
8052.5

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 score column to a property. Map: explicit column-to-property mapping (e.g., {score: 'deg_score', inDegree: 'in_deg'}).

Writable columns:

ColumnTypeDescription
degreeFLOATDegree count
scoreFLOATDegree score
inDegreeINTIn-degree count
outDegreeINTOut-degree count

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.degree.write({}, {
  db: {
    property: "deg_score"
  }
}) YIELD task_id, nodesWritten, computeTimeMs, writeTimeMs