I read it is ideal to represent sparse graphs by adjacency lists and dense graphs by an adjacency matrix. But I would like to understand the main difference between sparse and dense graphs.
Informally, a graph with relatively few edges is sparse, and a graph with many edges is dense. Definition (Sparse Graph): A sparse graph is a graph G = (V, E) in which |E| = O (|V|).
This definition is from Diestel's Graph Theory. In mathematics, a dense graph is a graph in which the number of edges is close to the maximal number of edges. The opposite, a graph with only a few edges, is a sparse graph. A sparse graph is a graph G = ( V, E) in which | E | = O ( | V |).
From Data Structures and Algorithms with Object-Oriented Design Patterns in C++ , p. 534, by Bruno P. Reiss: Informally, a graph with relatively few edges is sparse, and a graph with many edges is dense. Definition (Sparse Graph): A sparse graph is a graph G = (V, E) in which |E| = O (|V|).
Sparse graph is a graph in which the number of edges is close to the minimal number of edges. Sparse graph can be a disconnected graph. I think a graph with n vertices is considered to be sparse if it has O (n) or less edges.
Dense graph is a graph in which the number of edges is close to the maximal number of edges. Sparse graph is a graph in which the number of edges is close to the minimal number of edges. Sparse graph can be a disconnected graph.
As the names indicate sparse graphs are sparsely connected (eg: Trees). Usually the number of edges is in O(n) where n is the number of vertices. Therefore adjacency lists are preferred since they require constant space for every edge.
Dense graphs are densely connected. Here number of edges is usually O(n^2). Therefore adjacency matrix is preferred.
To give a comparison, let us assume graph has 1000 vertices.
Irrespective of whether the graph is dense or sparse, adjacency matrix requires 1000^2 = 1,000,000 values to be stored.
If the graph is minimally connected (i.e. it is a tree), the adjacency list requires storing 2,997 values. If the graph is fully connected it requires storing 3,000,000 values.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With