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

k-Core

Overview

The k-Core algorithm performs k-core decomposition, computing the coreness of each node — the maximum k for which the node belongs to a k-core subgraph. It is commonly employed to identify tightly connected groups in a graph for further analysis. Common applications include financial risk control, social network analysis, and biological studies. The algorithm runs in linear time, making it efficient for large graphs.

The widely accepted concept of k-core was first introduced by Seidman:

  • S.B. Seidman, Network Structure And Minimum Degree. Soc Netw 5:269-287 (1983)

Concepts

k-Core

The k-core of a graph is the largest subgraph where every node has at least degree k. It is computed through iterative pruning: nodes with degree less than k are successively removed until all remaining nodes have degrees ≥ k.

Below is the pruning process to get the 3-core of the graph. In the first round, nodes {a, d, f} with degree less than 3 are removed, which then affects the removal of node b in the second round. After the second round, all remaining nodes have a degree of at least 3. Therefore, the pruning process ends, and the 3-core of this graph is induced by nodes {c, e, g, h}.

Coreness

The coreness of a node is the maximum k for which the node belongs to a k-core. For example, if a node is in the 3-core but not in the 4-core, its coreness is 3. This algorithm computes the coreness for every node in the graph.

The algorithm computes coreness across all connected components independently.

Considerations

  • The algorithm ignores self-loops when calculating degree.
  • The algorithm treats all edges as undirected.

Example Graph

GQL
INSERT (A:default {_id: "A"}), (B:default {_id: "B"}),
       (C:default {_id: "C"}), (D:default {_id: "D"}),
       (E:default {_id: "E"}), (F:default {_id: "F"}),
       (G:default {_id: "G"}), (H:default {_id: "H"}),
       (I:default {_id: "I"}),
       (A)-[:default]->(C), (B)-[:default]->(B),
       (B)-[:default]->(D), (C)-[:default]->(B),
       (C)-[:default]->(D), (E)-[:default]->(D),
       (E)-[:default]->(F), (E)-[:default]->(G),
       (E)-[:default]->(H), (F)-[:default]->(D),
       (G)-[:default]->(D), (G)-[:default]->(F),
       (I)-[:default]->(A)

Parameters

NameTypeDefaultDescription
limitINT-1Limits the number of results returned (-1 = all).
orderSTRING/Sorts the results by coreness: asc or desc.

Run Mode

Returns:

ColumnTypeDescription
nodeIdSTRINGNode identifier (_id)
corenessINTThe maximum k-core the node belongs to
degreeINTThe node's degree
GQL
CALL algo.kcore() YIELD nodeId, coreness, degree

Result:

nodeIdcorenessdegree
E34
D35
G33
F33
A12
C23
B22
I11
H11

Stream Mode

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

GQL
CALL algo.kcore.stream() YIELD nodeId, coreness
FILTER coreness >= 3
RETURN nodeId, coreness

Result:

nodeIdcoreness
E3
D3
G3
F3

Stats Mode

Returns:

ColumnTypeDescription
nodeCountINTTotal number of nodes
maxCorenessINTMaximum coreness value
avgCorenessFLOATAverage coreness value
GQL
CALL algo.kcore.stats() YIELD nodeCount, maxCoreness, avgCoreness

Result:

nodeCountmaxCorenessavgCoreness
932.111111111111111

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 coreness column in results to a property. Map: explicit column-to-property mapping (e.g., {coreness: 'core', degree: 'deg'}).

Writable columns:

ColumnTypeDescription
corenessINTCoreness value
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.kcore.write({}, {
  db: {
    property: "coreness"
  }
}) YIELD task_id, nodesWritten, computeTimeMs, writeTimeMs