Comparison of Graph Representations
Explore the differences between adjacency matrix and adjacency list graph representations. Understand their memory footprints and operation times for edge checks and neighbor traversal. Learn why adjacency lists are preferred for sparse graphs and common graph algorithms, while adjacency matrices suit dense graphs and specific algorithms like Floyd Warshall.
We'll cover the following...
After studying both adjacency matrices and adjacency lists, let’s see how they compare for common operations that we’ll perform in graph algorithms.
In most applications of graph algorithms, the set of nodes is constant. No nodes are added or removed over time. We can therefore focus on operations that work on the edge set .
Memory usage
The adjacency matrix stores at least one bit for every ordered pair of nodes . Since there are exactly such pairs, the memory footprint is .
The adjacency list representation needs to store one list for each node in the graph, which takes at least space. Additionally, every edge of the graph needs to be stored in one of the lists, taking up further ...