Adjacency Matrix Calculator
Edge list → adjacency matrix · degree sequence · density · connected components · matrix powers A² A³
Separators: A-B A B A,B A->B. Arrow (->) forces directed edge.
Enter 0 (no edge) or 1 (edge). Edit vertex labels in the blue cells.
Format: vertex: neighbour1, neighbour2, ...
Enter your graph in Basic tab first, then switch here. Advanced analysis updates automatically after you calculate.
Quick Examples
What Is an Adjacency Matrix?
An adjacency matrix is a square n×n matrix A used to represent a graph G = (V, E) with n vertices. Entry A[i][j] = 1 if there is an edge from vertex i to vertex j, and 0 otherwise. For weighted graphs the entry stores the edge weight instead of 1. The matrix is one of the two canonical graph representations in computer science — the other being the adjacency list.
Adjacency matrices are fundamental to graph theory, network analysis, social network modelling, routing algorithms, and linear algebra applications in computer science. They allow O(1) edge existence queries and enable powerful matrix-algebraic techniques such as computing walk counts, detecting triangles, and finding connected components.
How to Use This Calculator
Three input modes are available:
- Edge List (default) — type vertex pairs, one per line. Flexible separators:
A-B,A B,A,B,A->B. Use->to force a directed edge. - Matrix Grid — fill a 0/1 grid directly. Choose size 2–8 and customise vertex labels in the blue header cells.
- Adj. List — enter in
vertex: n1, n2, ...format, one vertex per line.
Select Undirected or Directed, then click Calculate. The tool outputs the adjacency matrix, adjacency list, edge list, degree table, graph density, connectivity, matrix powers A² and A³, and an interactive graph visualisation. The Advanced tab adds a point-to-point path checker.
Key Formulas
Vertex Degree
Graph Density
Matrix Powers and Walk Counts
Symmetry Property
Worked Examples
Example 1 — Triangle Graph K₃ (Undirected)
Vertices: A, B, C. Edges: A–B, B–C, A–C.
- Index vertices: A=0, B=1, C=2. Initialise 3×3 zero matrix.
- Edge A–B: A[0][1] = A[1][0] = 1
- Edge B–C: A[1][2] = A[2][1] = 1
- Edge A–C: A[0][2] = A[2][0] = 1
- All degrees = 2. Density = 2×3 / (3×2) = 1.0 → this is the complete graph K₃.
| A | B | C | |
|---|---|---|---|
| A | 0 | 1 | 1 |
| B | 1 | 0 | 1 |
| C | 1 | 1 | 0 |
Example 2 — Directed Cycle (3 vertices)
Vertices: 1, 2, 3. Edges: 1→2, 2→3, 3→1.
- A[0][1] = 1, A[1][2] = 1, A[2][0] = 1. All other entries = 0.
- Matrix is NOT symmetric. Each vertex: out-degree = 1, in-degree = 1.
- Density = 3 / (3×2) = 0.50 (half of all directed pairs are connected).
| 1 | 2 | 3 | |
|---|---|---|---|
| 1 | 0 | 1 | 0 |
| 2 | 0 | 0 | 1 |
| 3 | 1 | 0 | 0 |
Example 3 — Reading A² Walk Counts
For the triangle K₃ above, A²[A][A] = A[A][B]×A[B][A] + A[A][C]×A[C][A] = 1+1 = 2. This means there are 2 walks of length 2 from A back to A (A→B→A and A→C→A). The diagonal of A² always equals the degree sequence for undirected graphs.
Frequently Asked Questions
What is an adjacency matrix?
How do you build an adjacency matrix from an edge list?
What is the difference between a directed and undirected adjacency matrix?
What does the squared adjacency matrix A² represent?
How do you find vertex degrees from an adjacency matrix?
What is graph density and how is it calculated?
How do you check graph connectivity using an adjacency matrix?
When should I use an adjacency list instead of a matrix?
Related Calculators
Matrix Calculator
Add, multiply, inverse & determinant
Probability Calculator
Binomial, normal distribution & combinations
Fraction Calculator
Add, subtract, multiply & simplify fractions
Trigonometry Calculator
Sin, cos, tan & right triangle solver
Binary / Decimal / Hex Converter
Convert between number bases with step-by-step working