Skip to article content

Read an adjacency matrix as a graph

A table can describe the same connections as an edge list. Use the guide's three-vertex input to see how an adjacency matrix's rows and columns correspond to the diagram.

Check the editor stepsLoad data

The vertices behind rows and columns

This input has three rows and three columns, corresponding to vertices 1, 2, and 3. A 1 in row 1, column 2 means that vertices 1 and 2 are connected. A 0 means there is no edge for that pair.

The main diagonal pairs each vertex with itself. Its entries are all 0 in this example, so there are no self-loops.

Why six ones give three edges

For an undirected graph, row 1, column 2 and row 2, column 1 describe the same edge. This example has six ones outside the diagonal. Grouping them into symmetric pairs gives three edges.

Those edges are 1–2, 1–3, and 2–3, forming a triangle. In a directed graph, entries in opposite directions describe separate edges.

Compare the table with the diagram

Pasting this matrix produces a triangle with N=3 and M=3. Compare the preview with the entries in the matrix.
Pasting this matrix produces a triangle with N=3 and M=3. Compare the preview with the entries in the matrix. (Japanese interface.)

Choose adjacency matrix as the format and Undirected and 1-indexed in Settings. Check the three-vertex, three-edge preview, then match the two ones in each row to the two edges meeting that vertex.

Positions depend on the layout. Check the connected vertex pairs rather than the triangle's orientation or the order of vertices on the page.

Compare the input and diagram

Input to copy

0 1 1
1 0 1
1 1 0

Graph diagram

123
3 vertices and 3 edges form a triangle, with every pair connected.

Related articles

Back to all articles