WOLFRAM

gives a count of the number of edges in the graph g.

EdgeCount[g,patt]

gives a count of the number of edges that match the pattern patt.

EdgeCount[{vw,},]

uses rules vw to specify the graph g.

Details

  • EdgeCount is also known as the size of the graph.
  • Multiple edges between nodes are counted as separate.
  • EdgeCount works with undirected graphs, directed graphs, multigraphs and mixed graphs.

Examples

open allclose all

Basic Examples  (2)Summary of the most common use cases

Count the number of edges:

Out[1]=1
Out[2]=2

Count the number of edges that match a pattern:

Out[1]=1

The number of edges incident to 1:

Out[2]=2

Scope  (7)Survey of the scope of standard use cases

EdgeCount works with undirected graphs:

Out[3]=3

Directed graphs:

Out[1]=1

Multigraphs:

Out[1]=1

Mixed graphs:

Out[1]=1

Use rules to specify the graph:

Out[1]=1

Use a pattern to count a subset of edges:

Out[1]=1
Out[2]=2
Out[3]=3

Works with large graphs:

Out[2]=2

Generalizations & Extensions  (1)Generalized and extended use cases

Count the number of edges on symbolic graph constructors:

Out[1]=1
Out[2]=2
Out[3]=3
Out[4]=4
Out[5]=5
Out[6]=6
Out[1]=1
Out[8]=8
Out[9]=9
Out[10]=10
Out[11]=11
Out[12]=12

Applications  (2)Sample problems that can be solved with this function

The minimum number of edges in a connected graph with vertices is :

Out[1]=1
Out[2]=2

A path graph with vertices has exactly edges:

Out[3]=3
Out[4]=4

The number of edges for Bernoulli graphs with probability on vertices has mean pTemplateBox[{n, 2}, Binomial]:

Out[2]=2

The standard deviation is sqrt(p (1-p) TemplateBox[{n, 2}, Binomial]):

Out[3]=3

The full distribution:

Out[4]=4

Properties & Relations  (7)Properties of the function, and connections to other functions

The number of edges of CompleteGraph[n]:

Out[1]=1

EdgeCount can be found using EdgeList:

Out[1]=1
Out[2]=2
Out[3]=3

The number of edges for a directed graph can be found from matrix representations:

Out[1]=1
Out[2]=2

Totaling the adjacency matrix:

Out[3]=3

The number of columns of the incidence matrix:

Out[4]=4

The number of edges for an undirected graph can be found from matrix representations:

Out[1]=1
Out[2]=2

The total of the upper (or lower) triangular part of the adjacency matrix:

Out[3]=3

The number of columns of the incidence matrix:

Out[4]=4

Totaling the diagonal elements of the Kirchhoff matrix, divided by 2:

Out[5]=5

The number of edges of the graph is equal to the number of vertices of its line graph:

Out[1]=1
Out[2]=2

The sum of the degrees of all vertices of a graph is twice the number of edges:

Out[1]=1
Out[2]=2

The underlying undirected graph of a graph g has the same number of edges as g:

Out[1]=1
Out[2]=2
Wolfram Research (2010), EdgeCount, Wolfram Language function, https://reference.wolfram.com/language/ref/EdgeCount.html (updated 2015).
Wolfram Research (2010), EdgeCount, Wolfram Language function, https://reference.wolfram.com/language/ref/EdgeCount.html (updated 2015).

Text

Wolfram Research (2010), EdgeCount, Wolfram Language function, https://reference.wolfram.com/language/ref/EdgeCount.html (updated 2015).

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.

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

Wolfram Language. (2010). EdgeCount. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/EdgeCount.html

BibTeX

@misc{reference.wolfram_2025_edgecount, author="Wolfram Research", title="{EdgeCount}", year="2015", howpublished="\url{https://reference.wolfram.com/language/ref/EdgeCount.html}", note=[Accessed: 08-July-2025 ]}

@misc{reference.wolfram_2025_edgecount, author="Wolfram Research", title="{EdgeCount}", year="2015", howpublished="\url{https://reference.wolfram.com/language/ref/EdgeCount.html}", note=[Accessed: 08-July-2025 ]}

BibLaTeX

@online{reference.wolfram_2025_edgecount, organization={Wolfram Research}, title={EdgeCount}, year={2015}, url={https://reference.wolfram.com/language/ref/EdgeCount.html}, note=[Accessed: 08-July-2025 ]}

@online{reference.wolfram_2025_edgecount, organization={Wolfram Research}, title={EdgeCount}, year={2015}, url={https://reference.wolfram.com/language/ref/EdgeCount.html}, note=[Accessed: 08-July-2025 ]}