Adjacency Matrix
An adjacency matrix represents a graph using a V by V matrix. For an unweighted graph, matrix[i][j] indicates whether an edge exists from vertex i to vertex j. For a weighted graph, the cell can store the edge weight. It provides O(1) edge-existence lookup but requires O(V²) space.
Space: O(V²).
Check whether an edge exists: O(1).
Iterating all neighbors: O(V).
Excellent for dense graphs.
Can waste substantial memory for sparse graphs.