Illustrated · 1 min

Graphs can be represented in various data structures, most commonly by either a list of lists or by an adjacency matrix.

List of Lists

In this representation of a graph, we have a list of vertices. In each vertex, we keep a list of the neighbors of each vertex.

Adjacency Matrix

In this representation of a graph, we keep a matrix MM whose ijijth entry is 11 if there is an edge from ViV_i to VjV_j and 00 otherwise. There are two general observations we can make about all adjacency matrices: (1) they are symmetric, which means Mij=MjiM_{ij}=M_{ji} or M=MTM=M^T in matrix terms (2) they have 00s along the main diagonal, i.e., Mii=0M_{ii}=0. Note that symmetry is broken if MM becomes directed, but that is a whole different story.

Type a concept, like “slope” or “photosynthesis”.

↑ ↓ to choose · Enter to openSearch explanations and problems