Starlight Tools

Adjacency Matrix Generator & Calculator

Convert an edge list, adjacency list, or adjacency matrix; edit the matrix directly; handle directed, undirected, binary, and weighted graphs; then visualize and analyze the result—all locally in your browser.

1. Enter or paste a graph

Auto-detect treats arrow syntax and asymmetric matrices as directed; other input is undirected.

Separate labels with commas, semicolons, or lines. List isolated vertices here.5 listed
Accepts A B, A-B, A--B, A,B, A -> B, or A → B.4 lines
Quick graph presets
Normalized previewA -- B B -- C A -- C C -- D

Private by design: vertex labels and edges are processed on this device. They are not uploaded, saved, or added to the page URL.

2. Matrix, graph & analysis

The sample graph is shown below.

What is an adjacency matrix?

For vertices v₁, v₂, …, vₙ, an adjacency matrix is an n × n matrix A. A binary entry is 1 when the row vertex is adjacent to the column vertex; a weighted entry stores the edge weight. In either mode, zero means no edge.

Directed graph

A[i,j] ≠ 0 if vᵢ → vⱼ

Rows are sources and columns are destinations. Count nonzero row entries for out-degree and nonzero column entries for in-degree.

Undirected graph

A[i,j] = A[j,i]

Every ordinary edge creates two mirrored entries, so the matrix is symmetric.

Self-loop

A[i,i] ≠ 0

A permitted loop appears on the main diagonal. For undirected graphs, a loop contributes two to degree even though it occupies one matrix cell.

How the calculator analyzes a matrix

Degree

deg(vᵢ) = Σⱼ 1[A[i,j] ≠ 0], with an undirected loop counted twice. Directed results report separate in- and out-degree sequences.

Edge count

For a loop-free undirected graph, |E| = ½Σᵢⱼ 1[A[i,j] ≠ 0]. Directed entries are counted once; diagonal loop entries are counted once.

Density and symmetry

Without loops, density is 2|E|/[n(n−1)] undirected or |E|/[n(n−1)] directed. An undirected matrix must equal its transpose.

Walk counts

For a binary adjacency matrix, (Aᵏ)[i,j] counts length-k walks from i to j. Enable A² and A³ in small results to inspect them.

Worked adjacency matrix examples

Each example keeps the diagram, vertex and edge sets, cell placement, and final matrix in the same order used by the calculator.

Undirected triangle

V={A,B,C}
E={{A,B},{B,C},{C,A}}

  1. A—B fills A,B and B,A.
  2. B—C and C—A fill their mirrored cells.
  3. Final matrix: [[0,1,1],[1,0,1],[1,1,0]].

Directed path

V={A,B,C}
E={(A,B),(B,C)}

  1. A→B fills row A, column B only.
  2. B→C fills row B, column C only.
  3. Final matrix: [[0,1,0],[0,0,1],[0,0,0]].

Weighted graph

V={A,B,C}
E={(A,B,2.5),(B,C,−1)}

  1. A→B places 2.5 at A,B.
  2. B→C places −1 at B,C.
  3. Zero remains the no-edge value.

Adjacency matrix vs. adjacency list vs. edge list

RepresentationStorageEdge lookupNeighbor iterationBest use
Adjacency matrixΘ(V²)Θ(1)Θ(V)Dense graphs, algebra, fastest repeated lookup
Adjacency listΘ(V+E)Typically Θ(deg(v))Θ(deg(v))Sparse graphs and graph traversal
Edge listΘ(E)Θ(E)Θ(E)Compact interchange, sorting, and edge-centric algorithms

Complexities assume ordinary unsorted lists; specialized sets or indexes can change lookup cost.

Method, conventions, and verification

  1. Choose an input tab and paste an edge list, adjacency list, or square matrix.
  2. Choose Auto-detect, Directed, or Undirected and switch between Binary and Weighted values as needed.
  3. Allow loops if diagonal entries are intended, choose repeated-edge handling, then select Convert & analyze.
  4. Edit cells or select graph vertices to verify the structure, then copy any of the three synchronized representations.

Edge-list syntax accepts spaces, hyphens, double hyphens, commas, ASCII arrows, and Unicode arrows. Weighted edges use a third number, such as A,B,2.5; negative and decimal weights are valid, while zero means no edge. Repeated weighted edges can be summed, maximized, or replaced by the last value. In undirected mode, reversed entries are the same edge.

Labels are case-sensitive and capped at 80 characters. The tool supports up to 150 vertices and 30,000 nonempty edge lines. Matrix size is limited to 22,500 visible cells. Auto-detect treats arrow syntax and asymmetric matrices as directed; adjacency lists without arrows default to undirected. The interactive calculator requires JavaScript and a modern web browser.

Reviewed by: Starlight Tools Mathematics Editorial Review role.
Method: parse labels, normalize edges, construct the matrix, derive representations from that matrix, and independently recount nonzero entries, degrees, loops, and symmetry.
Version: 2.0 · Last reviewed: .
Visible automated checks

The result panel verifies symmetry when required, agreement between matrix entries and edge count, and the applicable degree-sum or in/out-degree identity after every conversion or edit.

Terminology follows OpenStax, Contemporary Mathematics, Section 12.1. Weighted and multigraph conventions follow the NetworkX adjacency-matrix documentation: a nonedge is zero and multigraph weights are commonly summed, though this calculator also exposes maximum and last-value conventions.

Adjacency matrix generator FAQ

How can I tell whether an adjacency matrix is directed?

Use the result’s Symmetry check. A non-symmetric matrix must be directed; a symmetric matrix can be undirected or a directed graph with matching reverse arcs, so graph type still depends on the intended convention.

How do I count edges from a matrix?

For an undirected loop-free matrix, count nonzero entries and divide by two. For a directed matrix, count them once. Add diagonal loops once; the Analysis panel performs this check automatically.

Adjacency matrix or adjacency list?

Use a matrix for constant-time edge lookup, dense graphs, and matrix powers. Use an adjacency list for sparse graphs and fast neighbor iteration. The three representation boxes let you compare both for the same graph.

Adjacency matrix or incidence matrix?

An adjacency matrix is vertex × vertex and records which vertices connect. An incidence matrix is vertex × edge and records which vertices touch each edge; this tool produces adjacency representations.

What do powers of an adjacency matrix mean?

For a binary matrix, entry (Aᵏ)[i,j] counts length-k walks from i to j. Turn on A² and A³ below the Analysis panel for graphs with at most eight vertices.

When is a matrix preferable for a dense graph?

When many possible edges exist, Θ(V²) storage is less wasteful and direct edge lookup is useful. The comparison table shows the trade-off against lists.

How are weighted or parallel edges represented?

Choose Weighted and enter A,B,2.5. Matrix cells store weights and zero means no edge. For repeated or parallel edges choose Sum, Maximum, or Last value before conversion.

How do loops affect degree?

An undirected loop contributes two to degree but occupies one diagonal cell. A directed loop contributes one to both in-degree and out-degree. Enable Allow self-loops before adding or editing a diagonal cell.

Does the calculator store my graph?

No. Conversion, editing, visualization, analysis, copying, and downloads happen locally in your browser.

Explore more tools