Model answer
A matrix uses Θ(V²) space, tests an edge in O(1), and scans all neighbours in O(V). A list uses Θ(V+E) space, tests an edge in O(deg(u)) normally, and enumerates neighbours in O(deg(u)).
Use the key terms, then explain the reasoning.
Adjacency lists use O(V+E) space and suit sparse graphs; matrices use O(V²) space and give O(1) edge tests.
Open this in the visual labAn adjacency matrix stores every possible vertex pair and answers edge existence in constant time, but consumes Θ(V²) space. An adjacency list stores only actual neighbours and is usually preferred for sparse graphs.
An edge list is minimal and ideal when algorithms process globally sorted edges, as Kruskal does. Weighted lists store destination-cost pairs; undirected edges normally appear twice.
| Operation | Best | Average | Worst | Extra space |
|---|---|---|---|---|
| List storage | O(V+E) | O(V+E) | O(V+E) | O(V+E) |
| Matrix storage | O(V²) | O(V²) | O(V²) | O(V²) |
For an undirected graph, store each edge in both endpoint lists.
Open a prompt when you are ready to check your answer.