What is the space required to store a graph with V vertices and E edges as an adjacency matrix?
Correct answer D. O(V²)
Explanation
An adjacency matrix has one cell for every ordered pair of vertices, giving V × V entries regardless of how many edges exist. It answers 'is there an edge from u to v?' in O(1). An adjacency list stores only the edges that exist, needing O(V + E) space, which is far smaller for sparse graphs. That is why lists are preferred for most real-world graphs.
Answer checked How we write and check questions
Discussion