Core idea
An adjacency matrix stores graph edges in a V x V grid.
Cell matrix[i][j] is 1 or the edge weight when vertex i connects to vertex j.
It gives O(1) edge lookup, but uses O(V^2) space even for sparse graphs.
How it works
- List all vertices as rows and columns.
- Mark matrix[i][j] when an edge connects vertex i to vertex j.
- Mirror the value for undirected graphs.
- Use weights instead of 1 for weighted graphs.