An adjacency matrix represents a graph with a two-dimensional array: rows and columns correspond to vertices, and each entry records whether a pair is connected. section 1.4.5
Read the entries this way:
- A 1 marks a connection between the row and column vertices; a 0 marks no connection. section 1.4.5
- Unlike an adjacency list, which stores only each vertex’s neighbors, the matrix lays out connections in a two-dimensional array. section 1.4.5
Figure 1.12 The two primary data structures for graph traversals. Left: Simple graph representation with four nodes connected to each other. Middle: An adjacency matrix maps connections from one node to another, denoting them by the value 1 in the matrix and otherwise 0. Right: An adjacency list showing a key-value dictionary connecting to neighboring nodes only.
Compare the graph, its matrix, and its adjacency list to see how each represents the same connections. section 1.4.5








