Graph Density — Definition, Formula & Examples
Graph density is a ratio that measures how many edges a graph has compared to the maximum number of edges it could have. A density of 0 means no edges, and a density of 1 means every possible edge is present (a complete graph).
For a simple undirected graph with vertices and edges, the density is defined as , where is the number of edges in the complete graph . For a simple directed graph, the density is , since each pair of vertices can have two directed edges.
Key Formula
Where:
- = Density of the undirected simple graph G
- = Number of edges in the graph
- = Number of vertices in the graph
How It Works
To compute graph density, count the number of edges and the number of vertices in your graph. Plug these into the formula. The result is always between 0 and 1 inclusive. Graphs with density close to 1 are called dense graphs, while those with density close to 0 (or where grows much slower than ) are called sparse graphs. This distinction matters because many graph algorithms have different performance characteristics on dense versus sparse graphs.
Worked Example
Problem: Find the density of an undirected simple graph with 5 vertices and 7 edges.
Maximum edges: A complete graph on 5 vertices has:
Apply the formula: Substitute and into the density formula:
Answer: The graph density is , meaning 70% of all possible edges are present. This graph is relatively dense.
Why It Matters
Choosing between an adjacency matrix and an adjacency list often depends on graph density — matrices suit dense graphs, while lists are more memory-efficient for sparse ones. Network scientists use density to characterize real-world networks; for instance, social networks tend to be sparse despite having millions of nodes.
Common Mistakes
Mistake: Forgetting the factor of 2 in the numerator (or equivalently, not dividing the denominator by 2).
Correction: The formula accounts for the fact that counts ordered pairs, while each undirected edge corresponds to one unordered pair. Make sure numerator and denominator are consistent.
