Which representation uses O(V+E) space, and which uses O(V^2) space?

Prepare for the TJR Bootcamp Test with flashcards and detailed questions. Get hints and explanations for each query. Ace your exam!

Multiple Choice

Which representation uses O(V+E) space, and which uses O(V^2) space?

Explanation:
The question tests how graph representations use memory. An adjacency list stores, for each vertex, a list of its neighbors, so total storage grows with the number of vertices plus the number of edges. In big-O terms this is O(V + E). An adjacency matrix, on the other hand, allocates a full V by V grid to indicate whether each possible pair of vertices is connected, so the space is O(V^2) regardless of how many edges actually exist. Therefore, the adjacency list uses O(V + E) space, while the adjacency matrix uses O(V^2) space.

The question tests how graph representations use memory. An adjacency list stores, for each vertex, a list of its neighbors, so total storage grows with the number of vertices plus the number of edges. In big-O terms this is O(V + E). An adjacency matrix, on the other hand, allocates a full V by V grid to indicate whether each possible pair of vertices is connected, so the space is O(V^2) regardless of how many edges actually exist. Therefore, the adjacency list uses O(V + E) space, while the adjacency matrix uses O(V^2) space.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy