GraphTheory
Diameter
find the diameter of a graph
Calling Sequence
Parameters
Description
Examples
Diameter(G)
G
-
graph
Diameter returns the maximum distance among all pairs of vertices in the graph G. If G is disconnected then the output is infinity.
For weighted graphs the edge weights are used to denote the distance accrued while traveling along each edge. For unweighted graphs the length of each edge is assumed to be 1.
The strategy is to use the Floyd-Warshall all-pairs shortest path algorithm. See AllPairsDistance.
with⁡GraphTheory:
with⁡SpecialGraphs:
P≔PetersenGraph⁡
P≔Graph 1: an undirected graph with 10 vertices and 15 edge(s)
Diameter⁡P
2
C≔CycleGraph⁡19
C≔Graph 2: an undirected graph with 19 vertices and 19 edge(s)
Diameter⁡C
9
G≔Graph⁡1,2,0.2,1,4,1.1,2,3,0.3,3,4,0.4
G≔Graph 3: an undirected weighted graph with 4 vertices and 4 edge(s)
DrawGraph⁡G
Diameter⁡G
0.9
The distance between vertices 1 and 4 is maximal
DijkstrasAlgorithm⁡G,1,4
1,2,3,4,0.9
See Also
AllPairsDistance
DijkstrasAlgorithm
Distance
Radius
ShortestPath
Download Help Document