EdgeCount
Examples
open all close allBasic Examples (2)
Scope (7)
EdgeCount works with undirected graphs:
EdgeCount[[image]]EdgeCount[[image]]EdgeCount[[image]]EdgeCount[[image]]Use rules to specify the graph:
EdgeCount[{1 -> 2, 2 -> 3, 3 -> 1}]Use a pattern to count a subset of edges:
g = Graph[{12, 21, a1, a2, b1, b2, bb}]EdgeCount[g, _Integer_]EdgeCount[g, a_ | b_]Count a subset of edges from a list of rules:
EdgeCount[{1 -> 2, 2 -> 1, a -> 1, a -> 2, b -> 1, b -> 2, b -> b}, _Integer_]g = GridGraph[{10, 10, 10, 10}];Timing[EdgeCount[g]]Generalizations & Extensions (1)
Count the number of edges on symbolic graph constructors:
EdgeCount[ButterflyGraph[n, b]]EdgeCount[CompleteGraph[n]]EdgeCount[CompleteKaryTree[level, k]]EdgeCount[CycleGraph[n]]EdgeCount[DeBruijnGraph[m, n]]EdgeCount[GridGraph[{n, m, l}]]EdgeCount[HararyGraph[k, n]]EdgeCount[HypercubeGraph[n]]EdgeCount[KaryTree[n]]EdgeCount[KnightTourGraph[m, n]]EdgeCount[StarGraph[n]]EdgeCount[WheelGraph[n]]Applications (2)
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}The number of edges for Bernoulli graphs with probability
on
vertices has mean
:
{n, p} = {9, 0.7};
data = EdgeCount /@ RandomGraph[BernoulliGraphDistribution[n, p], 2000];{Mean[data]//N, p Binomial[n, 2]}{StandardDeviation[data]//N, Sqrt[p(1 - p)Binomial[n, 2]]}Histogram[data, PlotLabel -> EdgeCount]Properties & Relations (7)
The number of edges of CompleteGraph[n]:
EdgeCount[CompleteGraph[n]]EdgeCount can be found using EdgeList:
g = CompleteGraph[5]EdgeCount[g]Length[EdgeList[g]]The number of edges for a directed graph can be found from matrix representations:
g = CompleteGraph[5, DirectedEdges -> True]EdgeCount[g]Totaling the adjacency matrix:
Total[AdjacencyMatrix[g], 2]The number of columns of the incidence matrix:
Dimensions[IncidenceMatrix[g]]The number of edges for an undirected graph can be found from matrix representations:
g = CompleteGraph[5]EdgeCount[g]The total of the upper (or lower) triangular part of the adjacency matrix:
Total[Table[Diagonal[AdjacencyMatrix[g], k], {k, 0, 5}], 2]The number of columns of the incidence matrix:
Dimensions[IncidenceMatrix[g]]Totaling the diagonal elements of the Kirchhoff matrix, divided by 2:
Total[Diagonal[KirchhoffMatrix[g]]] / 2The number of edges of the graph is equal to the number of vertices of its line graph:
g = CompleteGraph[5]EdgeCount[g] == VertexCount[LineGraph[g]]The sum of the degrees of all vertices of a graph is twice the number of edges:
g = PetersenGraph[5, 2]Total[VertexDegree[g]] == 2EdgeCount[g]The underlying undirected graph of a graph g has the same number of edges as g:
{g = Graph[{12, 23, 31}], UndirectedGraph[g]}EdgeCount /@ %See Also
EdgeList VertexCount AdjacencyMatrix IncidenceMatrix Graph
Function Repository: EdgeMultiplicity
Related Guides
Text
Wolfram Research (2010), EdgeCount, Wolfram Language function, https://reference.wolfram.com/language/ref/EdgeCount.html (updated 2015).
CMS
Wolfram Language. 2010. "EdgeCount." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2015. https://reference.wolfram.com/language/ref/EdgeCount.html.
APA
Wolfram Language. (2010). EdgeCount. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/EdgeCount.html
BibTeX
@misc{reference.wolfram_2026_edgecount, author="Wolfram Research", title="{EdgeCount}", year="2015", howpublished="\url{https://reference.wolfram.com/language/ref/EdgeCount.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_edgecount, organization={Wolfram Research}, title={EdgeCount}, year={2015}, url={https://reference.wolfram.com/language/ref/EdgeCount.html}, note=[Accessed: 12-June-2026]}