Adjacency Matrix Calculator for Graphs
This interactive tool helps you build and analyze the adjacency matrix of a graph. Choose the number of vertices, toggle directed vs undirected and weighted vs unweighted, edit the matrix or paste an edge list, and get degrees, edge counts, density and adjacency lists.
It is designed for students, data scientists and engineers who want a transparent, step-by-step companion to standard graph theory references.
Adjacency matrix builder
Between 2 and 12 vertices.
Undirected graphs have symmetric adjacency matrices when unweighted.
In weighted mode, entries represent edge weights; 0 means no edge.
If empty, vertices are labeled v1, v2, …, vn. Labels are used in adjacency lists and edge parsing.
Rows correspond to source vertices, columns to target vertices. For undirected graphs, entries above the diagonal are mirrored automatically.
Accepted formats: u v or u-v, separated by commas or new lines. Use your vertex labels or indices (1-based).
Adjacency matrix – definition
Let \( G = (V, E) \) be a graph with vertices \( V = \{v_1, \dots, v_n\} \). The adjacency matrix of \(G\) is the \(n \times n\) matrix \(A = (a_{ij})\) defined by
\( a_{ij} = \begin{cases} 1, & \text{if there is an edge from } v_i \text{ to } v_j, \\ 0, & \text{otherwise.} \end{cases} \)
For weighted graphs, \( a_{ij} \) is the weight of the edge from \( v_i \) to \( v_j \).
For an undirected simple graph (no loops, no multiple edges), the adjacency matrix is symmetric: \( a_{ij} = a_{ji} \) and \( a_{ii} = 0 \). For a directed graph (digraph), the matrix is not necessarily symmetric.
Degrees from the adjacency matrix
In the unweighted case, vertex degrees are simple row/column sums:
- For an undirected graph, the degree of vertex \(v_i\) is \( \deg(v_i) = \sum_j a_{ij} \).
- For a directed graph, the out-degree is \( \deg^+(v_i) = \sum_j a_{ij} \) and the in-degree is \( \deg^-(v_i) = \sum_j a_{ji} \).
The calculator shows degrees in both undirected and directed modes, and for weighted graphs it also reports weighted degree (sum of weights).
Example: adjacency matrix of a triangle
Consider the undirected triangle on vertices \(v_1, v_2, v_3\) with edges \(\{v_1, v_2\}, \{v_2, v_3\}, \{v_1, v_3\}\). The adjacency matrix is
\( A = \begin{pmatrix} 0 & 1 & 1 \\ 1 & 0 & 1 \\ 1 & 1 & 0 \end{pmatrix}. \)
Row sums give degrees: each vertex has degree 2. The matrix is symmetric, as expected for an undirected simple graph.
From matrix to adjacency list and back
In practice, graphs may be stored either as adjacency matrices or as adjacency lists. The two representations are equivalent:
- Adjacency matrix: constant-time access to edge \((i, j)\), uses \(O(n^2)\) storage.
- Adjacency list: storage proportional to \(n + m\) (vertices plus edges), faster to iterate over neighbors when the graph is sparse.
This calculator converts between them: edit the matrix or the edge list, and it will keep both views synchronized for analysis.