Algorithms and Data Structures · Senior · Question 72 of 75
What is the main reason to prefer an adjacency matrix over adjacency lists?
- 1Faster traversal of all neighbors
- 2Lower memory use on sparse graphs
- ✓Correct answer: O(1) edge checks on dense graphs
Explanation
Checking matrix[u][v] is instant, and for dense graphs the O(V²) memory isn't wasted. For sparse graphs lists win on memory and neighbor iteration.