In mathematics, a dense graph is a graph in which the number of edges is close to the maximal number of edges (where every pair of vertices is connected by one edge). The opposite, a graph with only a few edges, is a sparse graph. The distinction of what constitutes a dense or sparse graph is ill-defined, and is often represented by 'roughly equal to' statements. Due to this, the way that density is defined often depends on the context of the problem.
The graph density of simple graphs is defined to be the ratio of the number of edges with respect to the maximum possible edges.
For undirected simple graphs, the graph density is:
For directed, simple graphs, the maximum possible edges is twice that of undirected graphs (as there are two directions to an edge) so the density is:
where E is the number of edges and V is the number of vertices in the graph. The maximum number of edges for an undirected graph is , so the maximal density is 1 (for complete graphs) and the minimal density is 0 .
For families of graphs of increasing size, one often calls them sparse if as . Sometimes, in computer science, a more restrictive definition of sparse is used like or even .
Upper density is an extension of the concept of graph density defined above from finite graphs to infinite graphs. Intuitively, an infinite graph has arbitrarily large finite subgraphs with any density less than its upper density, and does not have arbitrarily large finite subgraphs with density greater than its upper density. Formally, the upper density of a graph G is the infimum of the values α such that the finite subgraphs of G with density α have a bounded number of vertices. It can be shown using the Erdős–Stone theorem that the upper density can only be 1 or one of the superparticular ratios 0, 1/2, 2/3, 3/4, 4/5, ... n/n + 1 (see, e.g., Diestel, edition 5, p. 189).
and define a graph as being (k, l)-sparse if every nonempty subgraph with n vertices has at most kn − l edges, and (k, l)-tight if it is (k, l)-sparse and has exactly kn − l edges.