Adjacency Matrix Calculator
Convert between adjacency matrix, edge list, and adjacency list. Auto-detects directed/undirected graphs, computes degree sequence, density, connected components, and matrix powers — with an interactive SVG graph visualization.
Your ad blocker is preventing us from showing ads
MiniWebtool is free because of ads. If this tool helped you, please support us by going Premium (ad‑free + faster tools), or allowlist MiniWebtool.com and reload.
- Allow ads for MiniWebtool.com, then reload
- Or upgrade to Premium (ad‑free)
About Adjacency Matrix Calculator
The Adjacency Matrix Calculator is a graph-theory utility that converts between the three canonical graph representations — adjacency matrix, edge list, and adjacency list — and enriches the result with structural analysis: degree sequence, graph density, connected components, and matrix powers. It auto-detects whether your input describes a directed or undirected graph and renders a live SVG visualization alongside every result.
What Is an Adjacency Matrix?
Given a graph G = (V, E) with n vertices, its adjacency matrix is the n × n square matrix A whose entry A[i][j] is 1 if there is an edge from vertex i to vertex j, and 0 otherwise.
For an undirected graph, the adjacency matrix is always symmetric: every edge {u, v} contributes both A[u][v] = 1 and A[v][u] = 1. For a directed graph (digraph), the matrix may be asymmetric, reflecting the direction of each arc.
Three Representations — Pick What Fits Your Problem
| Representation | Space | Edge lookup | List neighbors | Best for |
|---|---|---|---|---|
| Adjacency matrix | Θ(n²) | O(1) | Θ(n) | Dense graphs; matrix algebra (powers, eigenvalues) |
| Adjacency list | Θ(n + m) | O(deg v) | Θ(deg v) | Sparse graphs; BFS/DFS and shortest-path algorithms |
| Edge list | Θ(m) | Θ(m) | Θ(m) | Input/output, Kruskal's MST, edge-centric algorithms |
Key Metrics Computed
Degree Sequence
For undirected graphs, the degree of a vertex is the number of edges incident to it (with self-loops counting twice). For directed graphs, each vertex has an in-degree (incoming arcs) and out-degree (outgoing arcs). The sorted list of degrees is a classical graph invariant used in isomorphism testing and the Erdős–Gallai realisability theorem.
Graph Density
Density measures how "full" a graph is relative to the maximum number of edges possible on n vertices.
A density of 0 means no edges, 1 means the graph is complete, and values below 0.1 typically indicate a sparse graph where an adjacency list is more space-efficient than a matrix.
Connected Components
A connected component is a maximal subset of vertices such that every pair is joined by a path. For directed graphs, this calculator reports weakly connected components (ignoring arrow directions) — the same subsets you'd get by treating each arc as an undirected edge.
Matrix Powers (A², A³ ... )
A fundamental theorem of algebraic graph theory states that the (i, j) entry of Ak equals the number of walks of exactly length k from vertex i to vertex j. Consequently:
- A²[i][i] equals the degree of vertex i (undirected), since a 2-walk from i to itself is "go to a neighbor and back".
- The trace of A³ divided by 6 counts the triangles in an undirected graph.
- Whether An−1 has any zero entry tells you whether the graph is connected.
Input Formats Accepted
1. Edge list
One edge per line or comma-separated. Any of these separators work: A-B, A B, A,B, A->B, A--B. Use -> if you want to force a directed interpretation.
2. Adjacency list
One line per vertex, in the form vertex: neighbor1, neighbor2, .... Order doesn't matter; missing vertices are added automatically from the neighbor lists.
3. Adjacency matrix
One row per line with space- or comma-separated 0/1 values. The matrix must be square. Optionally provide custom labels in the Matrix labels field (otherwise A, B, C… are used).
How to Use This Calculator
- Pick an input format using the tabbed selector: edge list, adjacency list, or adjacency matrix.
- Paste or type your graph in the text area. For matrix input, add optional labels in the Matrix labels field.
- Select graph type — leave on Auto-detect and the calculator will infer directedness from arrows (
->) or matrix symmetry. Force it to Directed or Undirected if you want to override. - Click Convert & Analyze Graph. The result page shows the adjacency matrix, an interactive SVG rendering, the other two text representations, degree statistics, connected components, and walk-count matrices A² and A³ when the graph is small enough.
- Hover a matrix row or a graph node to light up the matching row/column and incident edges — an instant visual proof that each format encodes the same information.
Worked Example
Consider an undirected graph on vertices {A, B, C, D} with edges AB, BC, CA, CD. The adjacency matrix is:
Key facts the calculator derives:
- Symmetric? Yes — confirms undirected.
- Degree sequence: (3, 2, 2, 1) — vertex C is the hub.
- Density: 2·4 / (4·3) = 0.667 — a moderately dense graph.
- Connected? Yes, single component.
- Triangles: exactly one (A–B–C), as confirmed by tr(A³) = 6.
Common Applications
- Social network analysis — friendship / follower graphs, centrality.
- Web & citation graphs — PageRank and HITS work directly on A and AT.
- Routing & networks — shortest-path, min-cut, max-flow.
- Chemistry — molecular graphs with atoms as vertices, bonds as edges.
- Scheduling & dependency resolution — directed acyclic graphs (DAGs) in build systems.
- Markov chains — row-stochastic matrices derived from graphs encode transition probabilities.
Frequently Asked Questions
What is an adjacency matrix?
An adjacency matrix is an n × n square matrix used to represent a finite graph. Each cell A[i][j] is 1 if there is an edge from vertex i to vertex j, and 0 otherwise. For undirected graphs the matrix is symmetric, so A[i][j] = A[j][i]. The matrix makes it easy to check whether two vertices are connected in constant time, and matrix powers encode the number of walks between vertices.
How do I tell if a graph is directed from its adjacency matrix?
If the adjacency matrix is symmetric, meaning A[i][j] equals A[j][i] for every pair of indices, the graph is undirected. If there is at least one pair where A[i][j] differs from A[j][i], the graph is directed. This calculator performs that symmetry check automatically when you pick the Auto-detect option.
What does the k-th power of an adjacency matrix represent?
The entry (i, j) of A^k counts the number of walks of exactly length k from vertex i to vertex j. For example, A²[i][j] is the number of 2-step paths, which equals the number of common neighbors between i and j in undirected graphs. This property is used in algorithms for triangle counting, reachability, and PageRank-style computations.
What is graph density?
Graph density is the ratio of the number of edges present to the maximum possible number of edges. For an undirected simple graph with n vertices, density = 2m / (n(n-1)). For a directed graph, density = m / (n(n-1)). A density near 0 means a sparse graph; a density of 1 means a complete graph.
How is an adjacency matrix different from an adjacency list?
An adjacency matrix stores connectivity for every pair of vertices using n² bits, making neighbor lookup O(1) but memory usage O(n²). An adjacency list stores only the actual neighbors of each vertex, giving O(n + m) memory, which is far smaller for sparse graphs, but neighbor lookup requires a linear scan. Matrices are better for dense graphs and matrix-algebra operations; lists are better for sparse graphs and traversal algorithms like BFS/DFS.
Can this tool handle weighted graphs?
The current calculator focuses on unweighted adjacency matrices with 0/1 entries. If you paste a matrix with non-zero numeric weights, every non-zero cell is treated as a 1 for structural analysis. For weighted graph computations such as shortest-path, consider a dedicated weighted-graph tool.
Further Reading
- Adjacency matrix — Wikipedia
- Degree sequence — Wikipedia
- Graph density — Wikipedia
- Connected components — Wikipedia
Reference this content, page, or tool as:
"Adjacency Matrix Calculator" at https://MiniWebtool.com// from MiniWebtool, https://MiniWebtool.com/
by miniwebtool team. Updated: Apr 20, 2026
You can also try our AI Math Solver GPT to solve your math problems through natural language question and answer.