2.6. igraph_diameter — Calculates the diameter of a graph (longest geodesic).

int igraph_diameter(const igraph_t *graph, igraph_integer_t *pres, 
		    igraph_integer_t *pfrom, igraph_integer_t *pto, 
		    igraph_vector_t *path,
		    igraph_bool_t directed, igraph_bool_t unconn);

Arguments: 

graph:

The graph object.

pres:

Pointer to an integer, if not NULL then it will contain the diameter (the actual distance).

pfrom:

Pointer to an integer, if not NULL it will be set to the source vertex of the diameter path.

pto:

Pointer to an integer, if not NULL it will be set to the target vertex of the diameter path.

path:

Pointer to an initialized vector. If not NULL the actual longest geodesic path will be stored here. The vector will be resized as needed.

directed:

Boolean, whether to consider directed paths. Ignored for undirected graphs.

unconn:

What to do if the graph is not connected. If TRUE the longest geodesic within a component will be returned, otherwise the number of vertices is returned. (The rationale behind the latter is that this is always longer than the longest possible diameter in a graph.)

Returns: 

Error code: IGRAPH_ENOMEM, not enough memory for temporary data.

Time complexity: O(|V||E|), the number of vertices times the number of edges.