Matrix or list?
Choose a matrix when
The graph is dense, constant-time edge checks matter, or a compact 2D representation makes an algorithm easier to reason about. Its cost is always V² cells, even when most contain zero.
Choose a list when
The graph is sparse or algorithms frequently iterate through neighbors. Storage grows with V + E, while checking one specific edge may require scanning a vertex’s neighbors.