# diameter

From igraph v0.6.5-2
by Gabor Csardi

##### Diameter of a graph

The diameter of a graph is the length of the longest geodesic.

- Keywords
- graphs

##### Usage

```
diameter(graph, directed = TRUE, unconnected = TRUE, weights = NULL)
get.diameter (graph, directed = TRUE, unconnected = TRUE, weights = NULL)
farthest.nodes (graph, directed = TRUE, unconnected = TRUE, weights = NULL)
```

##### Arguments

- graph
- The graph to analyze.
- directed
- Logical, whether directed or undirected paths are to be considered. This is ignored for undirected graphs.
- unconnected
- Logical, what to do if the graph is unconnected. If FALSE, the function will return a number that is one larger the largest possible diameter, which is always the number of vertices. If TRUE, the diameters of the connected components will be
- weights
- Optional positive weight vector for calculating
weighted distances. If the graph has a
`weight`

edge attribute, then this is used by default.

##### Details

The diameter is calculated by using a breadth-first search like method.

`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.

`farthest.points`

returns two vertex ids, the vertices which are
connected by the diameter path.

##### Value

- A numeric constant for
`diameter`

, a numeric vector for`get.diameter`

and a numeric vector of length two for`farthest.nodes`

.

##### concept

Diameter

##### See Also

##### Examples

```
g <- graph.ring(10)
g2 <- delete.edges(g, c(1,2,1,10))
diameter(g2, unconnected=TRUE)
diameter(g2, unconnected=FALSE)
## Weighted diameter
set.seed(1)
g <- graph.ring(10)
E(g)$weight <- sample(seq_len(ecount(g)))
diameter(g)
get.diameter(g)
diameter(g, weights=NA)
get.diameter(g, weights=NA)
```

*Documentation reproduced from package igraph, version 0.6.5-2, License: GPL (>= 2)*

### Community examples

Looks like there are no examples yet.