An adjacency matrix for a graph with n nodes is an n x n matrix. For 7 nodes, it has 7 rows and 7 columns, so 7 × 7 = 49 elements.
Adjacency lists store only the edges that exist, so for graphs with few edges, they use less memory than adjacency matrices, which store all possible connections.
An adjacency matrix stores edges in a 2D array, so checking if an edge exists between two nodes is a simple lookup, which takes constant time.
Adjacency matrices are efficient for dense graphs because they provide quick access and the memory cost is justified by many edges.
Adjacency lists allow easy addition and removal of edges by updating lists, while adjacency matrices require changing matrix entries, which can be less efficient for frequent updates.
