KCoreComponents[g,k]
gives the k-core components of the underlying simple graph of g.
KCoreComponents[g,k,"In"]
gives the k-core components with vertex in-degrees at least k.
KCoreComponents[g,k,"Out"]
gives the k-core components with vertex out-degrees at least k.
KCoreComponents[{vw,…},…]
uses rules vw to specify the graph g.
KCoreComponents
KCoreComponents[g,k]
gives the k-core components of the underlying simple graph of g.
KCoreComponents[g,k,"In"]
gives the k-core components with vertex in-degrees at least k.
KCoreComponents[g,k,"Out"]
gives the k-core components with vertex out-degrees at least k.
KCoreComponents[{vw,…},…]
uses rules vw to specify the graph g.
Details
- A k-core component is a maximal weakly connected subgraph in which all vertices have degree at least k.
- KCoreComponents returns a list of components {c1,c2,…}, where each component ci is given as a list of vertices.
- For a directed graph g, KCoreComponents[g,k] gives the k-core components of the underlying undirected simple graph of g.
- KCoreComponents works with undirected graphs, directed graphs, multigraphs, and mixed graphs.
Examples
open all close allBasic Examples (2)
Find the 3-core components of a graph:
g = [image];KCoreComponents[g, 3]HighlightGraph[g, Subgraph[g, %]]Find the 4-core components in a social network:
g = ExampleData[{"NetworkGraph", "ZacharyKarateClub"}];KCoreComponents[g, 4]Scope (10)
KCoreComponents works with undirected graphs:
KCoreComponents[[image], 2]KCoreComponents[[image], 2]KCoreComponents[[image], 2]KCoreComponents[[image], 2]KCoreComponents finds core components of any size:
Table[KCoreComponents[[image], k], {k, 1, 3}]Find k-core components with vertex in-degrees at least k:
KCoreComponents[[image], 2, "In"]Find k-core components with vertex out-degrees at least k:
KCoreComponents[[image], 2, "Out"]Use rules to specify the graph:
KCoreComponents[{1 -> 2, 1 -> 3, 2 -> 1, 2 -> 3, 3 -> 1, 3 -> 2, 3 -> 4, 4 -> 5, 5 -> 6, 6 -> 7, 7 -> 5}, 2]KCoreComponents gives an empty list if there is no k-core:
KCoreComponents[[image], 3]KCoreComponents works with large graphs:
g = GridGraph[{10, 10, 10, 10}];KCoreComponents[g, 4]//Short//TimingApplications (3)
Highlight the k-cores of a graph:
g = [image];Table[HighlightGraph[g, Subgraph[g, Join@@KCoreComponents[g, k]], GraphHighlightStyle -> "DehighlightHide", PlotLabel -> "k=" <> ToString[k]], {k, 1, 3}]Find the degeneracy of a graph g, being the largest k such that g has a k-core:
degeneracy[g_] := Module[{i = 1}, While[KCoreComponents[g, i] ≠ {}, ++i];i - 1]degeneracy[[image]]Trees and forests are 1-degenerate graphs:
KaryTree[15, 3]degeneracy[%]The Barabasi–Albert model with k edges added at each step is k-degenerate:
RandomGraph[BarabasiAlbertGraphDistribution[30, 5]]degeneracy[%]g = [image];a = Table[Complement[Flatten[KCoreComponents[g, i]], Flatten[KCoreComponents[g, i + 1]]], {i, 1, 4}]h = HighlightGraph[g, Table[Style[a[[i]], ColorData["TemperatureMap"][i / 4]], {i, 4}]]Properties & Relations (8)
Find k-core components by repeatedly removing vertices of out-degree less than k:
k = 3;g = [image];vlist[0] = VertexList[g];vlist[i_] := Cases[vlist[i - 1], v_ /; VertexDegree[Subgraph[g, vlist[i - 1]], v] ≥ k]HighlightGraph[g, vlist[1], GraphHighlightStyle -> "DehighlightFade"]HighlightGraph[g, vlist[2], GraphHighlightStyle -> "DehighlightFade"]No more vertices are removed by further iteration:
vlist[3] === vlist[2]Use ConnectedComponents to obtain the components of the k-core:
ConnectedComponents[Subgraph[g, vlist[2]]]The obtained k-cores of undirected graphs are connected:
g = [image];KCoreComponents[g, 3]ConnectedGraphQ[Subgraph[g, #]]& /@ %A vertex in a k-core component ci has at least k neighbors in ci:
g = [image];KCoreComponents[g, 3]EdgeList[g, 1_]EdgeList[g, 5_]For an undirected graph, the vertex in-degree and out-degree are equal to the vertex degree:
g = Graph[Range[5], {23, 21, 31, 52}]VertexInDegree[g] == VertexOutDegree[g] == VertexDegree[g]The k-core vertex in-degree and out-degree components are equal to the k-core components:
KCoreComponents[g, 2]KCoreComponents[g, 2, "In"]KCoreComponents[g, 2, "Out"]The maximum clique of size
is contained in a
-core component:
g = [image];FindClique[g]KCoreComponents[g, Length[First[%]] - 1]A k-core component is contained in a (k-1)-core component:
g = [image];KCoreComponents[g, 2]KCoreComponents[g, 1]The adjacency matrix of a k-core component has at least k nonzero entries in each row:
g = [image];c = KCoreComponents[g, 3]MatrixForm[AdjacencyMatrix[Subgraph[g, c]]]Total /@ %The adjacency matrix of a k-core in-degree component has at least k nonzero entries in each column:
g = [image];c = KCoreComponents[g, 2, "In"]MatrixForm[AdjacencyMatrix[Subgraph[g, c]]]Total[%]The adjacency matrix of a k-core out-degree component has at least k nonzero entries in each row:
c = KCoreComponents[g, 2, "Out"]MatrixForm[AdjacencyMatrix[Subgraph[g, c]]]Total[Transpose[%]]Related Guides
Text
Wolfram Research (2010), KCoreComponents, Wolfram Language function, https://reference.wolfram.com/language/ref/KCoreComponents.html (updated 2015).
CMS
Wolfram Language. 2010. "KCoreComponents." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2015. https://reference.wolfram.com/language/ref/KCoreComponents.html.
APA
Wolfram Language. (2010). KCoreComponents. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/KCoreComponents.html
BibTeX
@misc{reference.wolfram_2026_kcorecomponents, author="Wolfram Research", title="{KCoreComponents}", year="2015", howpublished="\url{https://reference.wolfram.com/language/ref/KCoreComponents.html}", note=[Accessed: 13-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_kcorecomponents, organization={Wolfram Research}, title={KCoreComponents}, year={2015}, url={https://reference.wolfram.com/language/ref/KCoreComponents.html}, note=[Accessed: 13-June-2026]}