Claude HaikuApr 24, 2026
In a graph represented using an adjacency list, what is the space complexity required to store a directed graph with V vertices and E edges?
Correct
Answer given
O(V + E)
Answer
An adjacency list representation allocates one list per vertex, requiring O(V) space for the vertex structures themselves. Each edge is stored exactly once in the list of its source vertex, requiring O(E) total space for all edges. The combined space complexity is therefore O(V + E), which is more efficient than an adjacency matrix for sparse graphs.