gives the mean distance between all pairs of vertices in the graph g.
MeanGraphDistance[{vw,…}]
uses rules vw to specify the graph g.
MeanGraphDistance
gives the mean distance between all pairs of vertices in the graph g.
MeanGraphDistance[{vw,…}]
uses rules vw to specify the graph g.
Details and Options
- MeanGraphDistance is also known as the average path length.
- MeanGraphDistance[g] is the average length of all shortest paths between vertices of g.
- MeanGraphDistance takes the following options:
-
Method Automatic method to use WorkingPrecision Automatic the precision used in internal computations
Examples
open all close allBasic Examples (2)
Find the mean distance between vertices in a graph:
MeanGraphDistance[[image]]Mean graph distance of the Watts–Strogatz model as a function of rewiring probability:
Plot[MeanGraphDistance[RandomGraph[WattsStrogatzGraphDistribution[1000, p, 5]]], {p, 0, 1}, MaxRecursion -> 0]Scope (7)
MeanGraphDistance works with undirected graphs:
MeanGraphDistance[[image]]MeanGraphDistance[[image]]MeanGraphDistance[[image]]MeanGraphDistance[[image]]MeanGraphDistance[[image]]Use rules to specify the graph:
MeanGraphDistance[{1 -> 2, 2 -> 3, 3 -> 1, 3 -> 4, 4 -> 5, 3 -> 5, 5 -> 2}]MeanGraphDistance works with large graphs:
g = GridGraph[{10, 10, 10, 10}];MeanGraphDistance[g]//TimingOptions (2)
Method (2)
By default, edge weights are used to determine graph distance:
MeanGraphDistance[[image]]Use Method->"UnitWeight" to ignore edge weights:
MeanGraphDistance[[image], Method -> "UnitWeight"]Applications (4)
A network of American football games between Division IA colleges during regular season fall 2000. The average number of games linking one team to another is about 2.5:
ExampleData[{"NetworkGraph", "AmericanCollegeFootball"}]N[MeanGraphDistance[%]]It takes a few more than five clicks on average to navigate from one symbol to another using the See Also links in the Wolfram Language documentation:
N[MeanGraphDistance[[image]]]Distribution of the number of co-appearances linking two randomly selected actors in a small-size Kevin Bacon game:
g = \!\(\*GraphicsBox[«5»]\);data = Table[GraphDistance[g, RandomChoice[VertexList[g]], RandomChoice[VertexList[g]]], {10000}];Histogram[data]Average number of co-appearances linking two actors:
N[MeanGraphDistance[g]]Distribution of the average number of relations connecting two people in a WattsStrogatzGraphDistribution social network model:
f[g_] := MeanGraphDistance[g] /. {∞ -> VertexCount[g] + 1}𝒟 = GraphPropertyDistribution[f[g], gWattsStrogatzGraphDistribution[50, 0.1, 3]];Histogram[RandomVariate[𝒟, 1000]]Compute the probability that the average exceeds 3:
NProbability[x > 3, x𝒟, PrecisionGoal -> 1]Properties & Relations (5)
MeanGraphDistance gives the off-diagonal mean of GraphDistanceMatrix:
g = KnightTourGraph[4, 3]MeanGraphDistance[g]Compute the off-diagonal mean when the diagonal of GraphDistanceMatrix is 0:
a = GraphDistanceMatrix[g];Diagonal[a]Total[Flatten[a]] / (Length[Flatten[a]] - Length[Diagonal[a]])The mean graph distance is greater than or equal to 1:
CirculantGraph[8, {1, 2, 3}]N[MeanGraphDistance[%]]It can be less than 1 for weighted graphs:
WeightedAdjacencyGraph[(| | | | |
| --- | --- | --- | --- |
| ∞ | 0.1 | 0.2 | 0.1 |
| 0.1 | ∞ | 0.2 | ∞ |
| 0.2 | 0.2 | ∞ | 0.1 |
| 0.1 | ∞ | 0.1 | ∞ |), EdgeLabels -> "EdgeWeight"]MeanGraphDistance[%]The mean graph distance of g is 1 iff g is a complete graph:
{g = Graph[{12, 23, 31}], h = Graph[{12, 13, 21, 31, 32}]}{MeanGraphDistance[g], MeanGraphDistance[h]}Use CompleteGraphQ to test for complete graphs:
{CompleteGraphQ[g], CompleteGraphQ[h]}The mean graph distance of a disconnected graph is Infinity:
g = Graph[{12, 34}]MeanGraphDistance[g]Use ConnectedGraphQ to test for connected graphs:
ConnectedGraphQ[g]MeanGraphDistance can be used to find the GraphLinkEfficiency:
g = CompleteKaryTree[3, 3]1 - MeanGraphDistance[g] / EdgeCount[g]% == GraphLinkEfficiency[g]Related Guides
Text
Wolfram Research (2012), MeanGraphDistance, Wolfram Language function, https://reference.wolfram.com/language/ref/MeanGraphDistance.html (updated 2015).
CMS
Wolfram Language. 2012. "MeanGraphDistance." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2015. https://reference.wolfram.com/language/ref/MeanGraphDistance.html.
APA
Wolfram Language. (2012). MeanGraphDistance. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/MeanGraphDistance.html
BibTeX
@misc{reference.wolfram_2026_meangraphdistance, author="Wolfram Research", title="{MeanGraphDistance}", year="2015", howpublished="\url{https://reference.wolfram.com/language/ref/MeanGraphDistance.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_meangraphdistance, organization={Wolfram Research}, title={MeanGraphDistance}, year={2015}, url={https://reference.wolfram.com/language/ref/MeanGraphDistance.html}, note=[Accessed: 12-June-2026]}