\HeaderA{diameter}{Diameter of a graph}{diameter}
\aliasA{farthest.nodes}{diameter}{farthest.nodes}
\aliasA{get.diameter}{diameter}{get.diameter}
\keyword{graphs}{diameter}
\begin{Description}\relax
The diameter of a graph is the length of the longest
geodesic.
\end{Description}
\begin{Usage}
\begin{verbatim}
diameter(graph, directed = TRUE, unconnected = TRUE)
get.diameter (graph, directed = TRUE, unconnected = TRUE) 
farthest.nodes (graph, directed = TRUE, unconnected = TRUE) 
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{graph}] The graph to analyize.
\item[\code{directed}] Logical, whether directed or undirected paths are to
be considered. This is ignored for undirected graphs.
\item[\code{unconnected}] Logical, what to do if the graph is unconnected. If
FALSE, the function will return the largest possible diameter which
is the number of vertices. If TRUE, the diameters of the connected
components will be calculated and the largest one will be returned.
\end{ldescription}
\end{Arguments}
\begin{Details}\relax
The diameter is calculated by using a breadth-first search like
method.

\code{get.diameter} returns a path with the actual diameter. If there
are many shortest paths of the length of the diameter, then it returns
the first one found.

\code{farthest.points} returns two vertex ids, the vertices which are
connected by the diameter path.
\end{Details}
\begin{Value}
A numeric constant for \code{diameter}, a numeric vector for
\code{get.diameter} and a numeric vector of length two for
\code{farthest.nodes}.
\end{Value}
\begin{Author}\relax
Gabor Csardi \email{csardi@rmki.kfki.hu}
\end{Author}
\begin{SeeAlso}\relax
\code{\LinkA{shortest.paths}{shortest.paths}}
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
g <- graph.ring(10)
g2 <- delete.edges(g, c(0,1,0,9))
diameter(g2, unconnected=TRUE)
diameter(g2, unconnected=FALSE)
\end{ExampleCode}
\end{Examples}

