Adjacency List
Learn how to represent a graph using the adjacency lists representation.
We'll cover the following
What a waste!
An matrix requires memory. Imagine a graph on a thousand vertices, with a handful of edges incident on each vertex. In the adjacency matrix, the row for each vertex would contain mostly zeroes except for a smattering of ones.
That’s wasteful as far as memory is concerned because if we know the neighbors of a vertex, it is easy to infer which of the vertices are not its neighbors. We don’t really need to store a zero against each nonneighbor.
For instance, the adjacency matrix for the shown graph has entries in all, but only are non-zero.
Get hands-on with 1400+ tech skills courses.