# When are adjacency lists better than sparse matrices?

I saw several questions discussion the benefits of adjacency lists over matrices to represent a sparse undirected graph. On the other hand, none of them discuss sparse matrix representations such as scipy's coo or csr formats.

Do adjacency lists still provide benefits in this case?

Definitions of the above:

• Adjacency list: a graph is represented as a dictionary, where each vertex is associated to the list of its neighbors (and the value of the edge): {i: [(neigh_1, val1), (neigh2, val_2)]}. Suppose these lists are linked lists ;
• coo format: the graph is represented as a dictionary of edges: (i,j) -> value.
• csr format: the matrix is stored row-wise. For each non-zero row, we have 2 arrays: indices[i] and values[i]. Example: indices[i] = [neigh_1, neigh_2], values[i] = [neigh1, neigh2].
• Not everybody is an expert on scipy. Perhaps you could explain what coo and csr are, as well as what you mean by adjacency lists? Apr 21 '20 at 12:59
• Right, thanks for the feedback. I added details on the data structures. Apr 21 '20 at 13:07
• The csr format seems equivalent to the adjacency list format. Apr 21 '20 at 13:24
• Different usages of course! Non of them is better than the other one. Each is used in some situations. Apr 21 '20 at 13:24