learngraphtheory.org

Guest

Sign in to keep your graphs and progress.

Algorithm Selection

Select an algorithm and generate steps to begin visualization

k-Core Decomposition Visualizer

Peel the weak ties until the dense centre shows

Peels away vertices with fewer than k neighbours, round after round, to give every vertex its core number and reveal the dense centre of a network

Time: O(n + m)
Space: O(n + m)
Use Case: Finding influential spreaders, network visualisation, community cores, protein interaction networks
Showing the example graph for this algorithm.
Algorithm Execution

Select an algorithm and generate steps to begin visualization

About k-Core Decomposition

The k-core of a graph is the largest part of it in which every vertex has at least k neighbours inside that part. The 1-core drops isolated vertices, the 2-core also drops the trees hanging off the graph, and higher cores close in on its densest region. The core number of a vertex is the largest k for which it belongs to the k-core, and the largest core number in the graph is its degeneracy. Stephen Seidman introduced k-cores in 1983 to describe cohesive groups in social networks.

How it works

The algorithm peels. With the bar at k, any vertex with fewer than k neighbours left is removed, and its neighbours lose one edge each, so some of them may fall below k too and go in the same sweep. When no vertex is below k, what remains is the k-core, and every vertex peeled on the way has core number k − 1. Then the bar rises to k + 1. Batagelj and Zaveršnik showed in 2003 that buckets of vertices of equal degree make the whole decomposition O(n + m). The visualizer shows how many neighbours each vertex has left, greys out peeled edges, writes the core number on each vertex as it goes and colours the shells from the outside in.

Applications

Core numbers rank how embedded a vertex is: a study of epidemic spreading found that vertices in the innermost cores spread an infection further than high-degree vertices on the edge of the network. Network visualisations draw the shells as rings, biologists look for the cores of protein interaction networks, and the degeneracy order, peeling one minimum-degree vertex at a time, speeds up clique search and shows that a graph can be coloured greedily with degeneracy + 1 colours. The k-core is also a quick first filter before slower dense-subgraph or community methods.

Pseudocode

Peeling with a rising bar. The inner loop is what lets one removal set off others.

CoreNumbers(G):
    deg[v] = degree of v for every vertex
    k = 1
    while vertices remain:
        while some remaining v has deg[v] < k:
            remove v, core[v] = k - 1
            for each remaining neighbour u of v:
                deg[u] = deg[u] - 1
        // what remains now is the k-core
        k = k + 1
    return core                    // degeneracy = max core[v]

A vertex removed while the bar is k has fewer than k neighbours among the vertices left, but it survived the bar k − 1, so its core number is k − 1. Batagelj and Zaveršnik avoid the repeated search with buckets of vertices by current degree, always removing from the lowest bucket, which gives O(n + m).

Worked example, step by step

The eleven-vertex example on this page.

Example graph: A, B, C and D form a complete K4. E is joined to A, B and C, D is joined to F, and F, G, H form a triangle. J hangs on E, I hangs on J and K hangs on H.

  1. The 1-core. Every vertex has a neighbour, so the 1-core is the whole graph and no vertex has core number 0.
  2. Bar 2. I and K have one neighbour each and go. Without I, J is left with E alone, so J goes in the same sweep. I, J and K get core number 1, and the 2-core has 8 vertices.
  3. Bar 3. G and H now have two neighbours each, the triangle, and go. That leaves F with D alone, so F goes too. F, G and H get core number 2.
  4. The 3-core. A, B, C, D and E remain. D has A, B and C, E has A, B and C, and A, B and C have four neighbours each. This is the 3-core.
  5. Bar 4. D and E have only three neighbours and go, which leaves A, B and C with two each, so they go as well. All five get core number 3, and nothing is left.

Degeneracy 3. Core numbers: 3 for A, B, C, D and E, 2 for F, G and H, 1 for I, J and K. Degree alone would mislead: F and H have degree 3, but each relies on neighbours that are peeled before the 3-core forms, so they stay in the 2-shell.

Complexity, and where it comes from

Time: O(n + m) · Space: O(n + m)

Every vertex is removed once and every edge lowers a degree once, so the work is O(n + m) if the next vertex to remove is found in constant time. Buckets indexed by degree do that: a vertex whose degree drops moves one bucket down. The visualizer scans all vertices instead, O(n²), which is easy to follow on small graphs.

When to use k-Core Decomposition, and when not to

Other ways to find the dense part of a network.

AlternativePrefer it whenCost
Ranking by degreeA quick ranking is enough. It ignores where the neighbours are, so a hub tied to many leaves ranks high although it sits on the edge.O(n + m)
Maximum clique (Bron–Kerbosch)Everyone in the group must know everyone else. Cliques are much stricter than cores and exponential to find in the worst case.O(3^(n/3)) worst case
Densest subgraphThe subgraph with the highest average degree is wanted exactly. The innermost core is within a factor of 2 of it.Polynomial, through maximum flow

Common pitfalls

  • Removing only one round of low-degree vertices. After the first removals other vertices lose neighbours and may fall below k too. The loop must continue until no vertex is below k, as J shows here: it only drops below 2 once I is gone.
  • Confusing a k-core with a clique or a component. A k-core need not be connected, and its vertices need not all be adjacent. It only guarantees every member at least k neighbours inside it.
  • Directed networks. k-cores are defined for undirected graphs. For directed networks decide first whether to count arcs in, arcs out or both, since each gives a different decomposition.

Frequently asked questions

What is the degeneracy of a graph?
The largest core number, 3 in this example. Equivalently, the smallest d such that every subgraph has a vertex of degree at most d. A d-degenerate graph can be coloured greedily with d + 1 colours, and planar graphs are 5-degenerate.
Why do k-cores find influential spreaders?
A vertex in an inner core has many neighbours that are themselves well connected, so an infection or a rumour that starts there keeps finding new paths. Studies of epidemic models found the core number a better predictor of spreading than degree.
Is the k-core unique?
Yes. The union of two subgraphs in which every vertex has at least k neighbours has the same property, so there is one largest such subgraph, and every order of removals ends at it.

Related algorithms: Clustering Coefficient, Betweenness Centrality, Louvain Community Detection, Maximal Clique, Graph Coloring

An example graph: you can change it, or start blank.

Zoom Controls

30%
Nodes: 11
Edges: 16