GraphDensity[g]
gives the graph density of the graph g.
GraphDensity[{vw,…}]
uses rules vw to specify the graph g.
GraphDensity
GraphDensity[g]
gives the graph density of the graph g.
GraphDensity[{vw,…}]
uses rules vw to specify the graph g.
Details and Options
- GraphDensity is the ratio of the number of edges divided by the number of edges of a complete graph with the same number of vertices.
- A simple undirected graph with
vertices and
edges has graph density
. - A simple directed graph with
vertices and
edges has graph density
.
Examples
open all close allBasic Examples (2)
Compute the density of a graph:
GraphDensity[[image]]Graph density distribution of the Bernoulli graph model:
𝒟 = GraphPropertyDistribution[GraphDensity[g], gBernoulliGraphDistribution[100, 0.3]];Histogram[RandomVariate[𝒟, 10000], 20]Scope (6)
GraphDensity works with undirected graphs:
GraphDensity[[image]]GraphDensity[[image]]GraphDensity[[image]]GraphDensity[[image]]Use rules to specify the graph:
GraphDensity[{1 -> 2, 2 -> 3, 3 -> 1, 3 -> 4, 4 -> 5, 3 -> 5, 5 -> 2}]GraphDensity works with large graphs:
g = GridGraph[{10, 10, 10, 10}];GraphDensity[g]//TimingApplications (4)
Find the proportion of games between teams during an American college football season:
g = ExampleData[{"NetworkGraph", "AmericanCollegeFootball"}]N[GraphDensity[g]]Compute the probability that two randomly chosen friends in a network are connected:
g = ExampleData[{"NetworkGraph", "ZacharyKarateClub"}]GraphDensity[g]g = ExampleData[{"NetworkGraph", "ZacharyKarateClub"}];𝒢 = BernoulliGraphDistribution[VertexCount[g], GraphDensity[g]];RandomGraph[𝒢, 4]Mean[GraphPropertyDistribution[EdgeCount[h], h𝒢]]The expected number of edges matches the original graph:
EdgeCount[g]Distribution of density in BernoulliGraphDistribution[n,p]:
𝒟 = GraphPropertyDistribution[GraphDensity[g], gBernoulliGraphDistribution[30, 0.7]];Histogram[RandomVariate[𝒟, 1000]]NExpectation[x, x𝒟]Properties & Relations (6)
GraphDensity measures the density of the AdjacencyMatrix:
g = AdjacencyGraph[(| | | |
| - | - | - |
| 0 | 1 | 1 |
| 1 | 1 | 0 |
| 1 | 1 | 0 |), DirectedEdges -> True]GraphDensity[g, SelfLoops -> True]Get the density from AdjacencyMatrix:
Flatten[Normal[AdjacencyMatrix[g]]]Count[%, x_ /; x ≠ 0] / Length[%]The graph density is between 0 and 1:
Graph[{12, 13, 14, 23}]GraphDensity[%]The density of an empty graph is 0:
g = Graph[{1, 2, 3, 4}, {}]GraphDensity[g]Use EmptyGraphQ to test for emptiness:
EmptyGraphQ[g]The density of a complete graph is 1:
g = CompleteGraph[9]GraphDensity[g]Use CompleteGraphQ to test for complete graphs:
CompleteGraphQ[g]Converting an undirected graph to a directed graph does not change the density:
g = GridGraph[{2, 3}];
graphs = {g, DirectedGraph[g]}GraphDensity /@ graphsUnless self-loops are taken into consideration:
GraphDensity[#, SelfLoops -> True]& /@ graphsLocalClusteringCoefficient gives a local measure of density:
g = CirculantGraph[6, {1, 2}, VertexShapeFunction -> "Name"]h = VertexDelete[NeighborhoodGraph[g, 1], 1]{GraphDensity[h], LocalClusteringCoefficient[g, 1]}See Also
Related Guides
Text
Wolfram Research (2012), GraphDensity, Wolfram Language function, https://reference.wolfram.com/language/ref/GraphDensity.html (updated 2015).
CMS
Wolfram Language. 2012. "GraphDensity." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2015. https://reference.wolfram.com/language/ref/GraphDensity.html.
APA
Wolfram Language. (2012). GraphDensity. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/GraphDensity.html
BibTeX
@misc{reference.wolfram_2026_graphdensity, author="Wolfram Research", title="{GraphDensity}", year="2015", howpublished="\url{https://reference.wolfram.com/language/ref/GraphDensity.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_graphdensity, organization={Wolfram Research}, title={GraphDensity}, year={2015}, url={https://reference.wolfram.com/language/ref/GraphDensity.html}, note=[Accessed: 12-June-2026]}