diameter#

diameter(G, e=None, usebounds=False)[source]#

Returns the diameter of the graph G.

The diameter is the maximum eccentricity.

Parameters:
GNetworkX graph

A graph

eeccentricity dictionary, optional

A precomputed dictionary of eccentricities.

Returns:
dinteger

Diameter of graph

See also

eccentricity

Examples

>>> G = nx.Graph([(1, 2), (1, 3), (1, 4), (3, 4), (3, 5), (4, 5)])
>>> nx.diameter(G)
3