VertexCount[g]
gives a count of the number of vertices in the graph g.
VertexCount[g,patt]
gives a count of the number of vertices that match the pattern patt.
VertexCount[{vw,…},…]
uses rules vw to specify the graph g.
VertexCount
VertexCount[g]
gives a count of the number of vertices in the graph g.
VertexCount[g,patt]
gives a count of the number of vertices that match the pattern patt.
VertexCount[{vw,…},…]
uses rules vw to specify the graph g.
Details
- VertexCount is also known as the order of the graph.
- VertexCount[g] returns the number of vertices in the graph g.
- VertexCount works with undirected graphs, directed graphs, multigraphs, and mixed graphs.
Examples
open all close allBasic Examples (2)
Scope (7)
VertexCount works with undirected graphs:
VertexCount[[image]]VertexCount[[image]]VertexCount[[image]]VertexCount[[image]]Use rules to specify the graph:
VertexCount[{1 -> 2, 2 -> 3, 3 -> 1}]Use patterns to count a subset of vertices:
g = Graph[{12, 21, a1, a2, b1, b2, bb}]VertexCount[g, _Integer]VertexCount[g, Except[_Integer]]VertexCount works with large graphs:
g = GridGraph[{10, 10, 10, 10}];Timing[VertexCount[g]]Generalizations & Extensions (1)
Count the number of vertices on symbolic graph constructors:
VertexCount[ButterflyGraph[n, b]]VertexCount[CirculantGraph[n, j]]VertexCount[CirculantGraph[n, j]]VertexCount[CompleteGraph[n]]VertexCount[CompleteKaryTree[level, k]]VertexCount[CycleGraph[n]]VertexCount[DeBruijnGraph[m, n]]VertexCount[GridGraph[{n, m, l}]]VertexCount[HararyGraph[k, n]]VertexCount[HypercubeGraph[n]]VertexCount[KaryTree[n]]VertexCount[KnightTourGraph[m, n]]VertexCount[PetersenGraph[n, k]]VertexCount[StarGraph[n]]VertexCount[TuranGraph[n, r]]VertexCount[WheelGraph[n]]Applications (3)
The minimum number of edges in a connected graph with
vertices is
:
g = PetersenGraph[5, 2]{ConnectedGraphQ[g], EdgeCount[g] ≥ VertexCount[g] - 1}A path graph with
vertices has exactly
edges:
g = PathGraph[Range[20]]{ConnectedGraphQ[g], EdgeCount[g] ≥ VertexCount[g] - 1}Construct a graph with a random vertex coloring:
g = GridGraph[{10, 10}, VertexStyle -> ((# -> RandomChoice[{Red, Green, Blue, Yellow}])& /@ VertexList[GridGraph[{10, 10}]]), VertexSize -> Large]Count the vertices with the color blue:
VertexCount[g, _ ? (AnnotationValue[{g, #}, VertexStyle] == Blue&)]Highlight the vertex by the vertex degree:
g = HararyGraph[3, 5, VertexSize -> Large, ImagePadding -> 10];vd = VertexDegree[g];HighlightGraph[g, Table[Style[Labeled[VertexList[g][[i]], vd[[i]]], ColorData["TemperatureMap"][vd[[i]] / Max[vd]]], {i, VertexCount[g]}]]Count the vertex with degree 3:
VertexCount[g, _ ? (VertexDegree[g, #] == 3&)]Properties & Relations (5)
Number of vertices of CompleteGraph[n]:
VertexCount[CompleteGraph[n]]VertexCount can be found using VertexList:
g = CompleteGraph[5]VertexCount[g]Length[VertexList[g]]The number of vertices can be found from matrix representations:
g = CompleteGraph[5]VertexCount[g]The number of rows and columns of an adjacency matrix:
Dimensions[AdjacencyMatrix[g]]The number of rows of an incidence matrix:
Dimensions[IncidenceMatrix[g]]The number of rows or columns of a Kirchhoff matrix:
Dimensions[KirchhoffMatrix[g]]The number of vertices of the line graph of graph g is equal to the number of edges of g:
g = CompleteGraph[5]EdgeCount[g]LineGraph[g]VertexCount[%]Isomorphic graphs have the same number of vertices:
{g, h} = {PetersenGraph[4, 1], HypercubeGraph[3]}IsomorphicGraphQ[g, h]VertexCount[g] == VertexCount[h]Related Guides
Text
Wolfram Research (2010), VertexCount, Wolfram Language function, https://reference.wolfram.com/language/ref/VertexCount.html (updated 2015).
CMS
Wolfram Language. 2010. "VertexCount." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2015. https://reference.wolfram.com/language/ref/VertexCount.html.
APA
Wolfram Language. (2010). VertexCount. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/VertexCount.html
BibTeX
@misc{reference.wolfram_2026_vertexcount, author="Wolfram Research", title="{VertexCount}", year="2015", howpublished="\url{https://reference.wolfram.com/language/ref/VertexCount.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_vertexcount, organization={Wolfram Research}, title={VertexCount}, year={2015}, url={https://reference.wolfram.com/language/ref/VertexCount.html}, note=[Accessed: 12-June-2026]}