16.1. igraph_density — Calculate the density of a graph.

int igraph_density(const igraph_t *graph, igraph_real_t *res, 
		   igraph_bool_t loops);

The density of a graph is simply the ratio number of edges and the number of possible edges. Note that density is ill-defined for graphs with multiple and/or loop edges, so consider calling igraph_simplify() on the graph if you know that it contains multiple or loop edges.

Arguments: 

graph:

The input graph object.

res:

Pointer to a real number, the result will be stored here.

loops:

Logical constant, whether to include loops in the calculation. If this constant is TRUE then loop edges are thought to be possible in the graph (this does not neccessary means that the graph really contains any loops). If this FALSE then the result is only correct if the graph does not contain loops.

Returns: 

Error code.

Time complexity: O(1).