Adjacency Matrix

The adjacency matrix is a fundamental way to represent a graph as a square matrix. Each entry indicates whether a pair of vertices is connected by an edge. This representation enables the application of linear algebra to graph problems, revealing deep connections between graph structure and matrix properties. This page covers the definition, properties, and applications of adjacency matrices for both simple and weighted graphs.

Definition

Simple Graphs

For a simple graph G=(V,E) G equals open paren V comma E close paren with n n vertices labeled 1,2,…,n 1 comma 2 comma dot dot dot comma n, the adjacency matrix A A is an n×n n times n matrix where:

Ai⁢j={1if (i,j)∈E0otherwise A sub i j equals 2 cases Case 1: 1 if open paren i comma j close paren is a member of E Case 2: 0 otherwise

In other words, the entry in row i i and column j j is 1 1 if there is an edge from vertex i i to vertex j j, and 0 0 otherwise.

Directed Graphs

For a directed graph (digraph), the adjacency matrix is defined similarly, but it is generally not symmetric:

Ai⁢j={1if there is an edge from i to j0otherwise A sub i j equals 2 cases Case 1: 1 if there is an edge from i to j Case 2: 0 otherwise

Here Ai⁢j=1 A sub i j equals 1 means there is a directed edge from vertex i i to vertex j j.

Weighted Graphs

For a weighted graph with edge weights w⁡(i,j) w of open paren i comma j close paren, the adjacency matrix becomes:

Ai⁢j={w⁡(i,j)if (i,j)∈E0 or ∞otherwise A sub i j equals 2 cases Case 1: w of open paren i comma j close paren if open paren i comma j close paren is a member of E Case 2: 0 or infinity otherwise

The choice of 0 0 or ∞ infinity for non-edges depends on the application. For shortest path problems, ∞ infinity is often used; for other applications, 0 0 may be appropriate.

Basic Properties

Symmetry

For an undirected graph, the adjacency matrix is symmetric:

A=AT A equals A to the T power

This is because an undirected edge (i,j) open paren i comma j close paren implies both Ai⁢j=1 A sub i j equals 1 and Aj⁢i=1 A sub j i equals 1. For directed graphs, the matrix is generally not symmetric.

Degree and Row/Column Sums

For an undirected simple graph, the degree of vertex i i equals the sum of row i i (or column i) i close paren:

deg⁢(i)=∑j=1nAi⁢j=∑j=1nAj⁢i degree times i equals the sum from j equals 1 to n of A sub i j equals the sum from j equals 1 to n of A sub j i

For directed graphs, the row sum gives the out-degree and the column sum gives the in-degree:

deg+⁢(i)=∑j=1nAi⁢j,deg−⁢(i)=∑j=1nAj⁢i degree raised to the plus power times i equals the sum from j equals 1 to n of A sub i j comma degree raised to the minus power times i equals the sum from j equals 1 to n of A sub j i

Number of Edges

The total number of edges can be computed from the trace or the sum of entries:

|E|=12⁢∑i,jAi⁢j the absolute value of E equals one half the sum over i comma j of A sub i j (undirected), |E|=∑i,jAi⁢j the absolute value of E equals the sum over i comma j of A sub i j (directed)

Path Counting

One of the most powerful properties of the adjacency matrix is its connection to counting paths.

Theorem: Powers of the Adjacency Matrix

The (i,j) open paren i comma j close paren entry of Ak A to the k-th power gives the number of walks of length k k from vertex i i to vertex j j:

(Ak)i⁢j= open paren A to the k-th power close paren sub i j equals number of walks of length k kfrom i i to j j

Proof by Induction

Base case (k=1 k equals 1): A1=A A to the first power equals A, and Ai⁢j=1 A sub i j equals 1 if and only if there is an edge (a walk of length 1 1) from i i to j j.

Inductive step: Assume (Ak)i⁢j open paren A to the k-th power close paren sub i j counts walks of length k k. Then:

(Ak+1)i⁢j=∑m=1n(Ak)⁢Am⁢j open paren A raised to the k plus 1 power close paren sub i j equals the sum from m equals 1 to n of open paren A to the k-th power close paren A sub m j

A walk of length k+1 k plus 1 from i i to j j consists of a walk of length k k from i i to some vertex m m, followed by an edge from m m to j j. Summing over all possible intermediate vertices m m gives the total count.

Application: Triangles

The number of triangles in an undirected graph is:

triangles =16⁢tr⁡(A3)=16⁢∑i=1nA3 equals one sixth the trace of open paren A cubed close paren equals one sixth the sum from i equals 1 to n of A cubed

The diagonal entry (A3)i⁢i open paren A cubed close paren sub i i counts closed walks of length 3 3 starting and ending at vertex i i. Each triangle is counted 6 6 times (once for each starting vertex and direction), hence the factor of 16 one sixth.

Spectral Properties

The eigenvalues and eigenvectors of the adjacency matrix reveal important structural information about the graph.

Real Eigenvalues

For undirected graphs, the adjacency matrix is symmetric, so all eigenvalues are real. Let λ1≥λ2≥⋯≥λn lamda sub 1 is greater than or equal to lamda sub 2 is greater than or equal to dot dot dot is greater than or equal to lamda sub n be the eigenvalues.

Largest Eigenvalue

The largest eigenvalue λ1 lamda sub 1 (spectral radius) satisfies:

δ≤λ1≤ delta is less than or equal to lamda sub 1 is less than or equal toΔ

where δ delta is the minimum degree and Δ is the maximum degree. For regular graphs (all vertices have the same degree d d), λ1=d lamda sub 1 equals d.

Connectivity and Eigenvalues

The multiplicity of the eigenvalue λ1 lamda sub 1 equals the number of connected components of the graph. For a connected graph, λ1 lamda sub 1 has multiplicity 1 1.

Bipartiteness

A graph is bipartite if and only if its spectrum is symmetric about 0 0. That is, λ lamda is an eigenvalue if and only if −λ negative lamda is also an eigenvalue with the same multiplicity.

Related Matrix Representations

Degree Matrix

The degree matrix D D is a diagonal matrix where Di⁢i=deg⁡(i) D sub i i equals degree i:

D=diag⁡(deg⁢(1),deg⁢(2),…,deg⁢(n)) D equals diag of open paren degree times 1 comma degree times 2 comma dot dot dot comma degree times n close paren

Laplacian Matrix

The graph Laplacian is defined as L=D-A L equals D minus A:

Li⁢j={deg⁡(i)if i=j−1if i≠j and (i,j)∈E0otherwise L sub i j equals 3 cases Case 1: degree i if i equals j Case 2: negative 1 if i is not equal to j and open paren i comma j close paren is a member of E Case 3: 0 otherwise

The Laplacian is positive semidefinite with smallest eigenvalue 0 0. The multiplicity of the zero eigenvalue equals the number of connected components.

Normalized Adjacency Matrix

The normalized adjacency matrix is often used in spectral clustering and random walks:

A^=D−1/2⁢A⁢D−1/2 A hat equals D raised to the negative 1 divided by 2 power A D raised to the negative 1 divided by 2 power

The eigenvalues of lie in [-1,1] open bracket negative 1 comma 1 close bracket for connected graphs.

Computational Considerations

Space Complexity

The adjacency matrix requires O⁡(n2) O of open paren n squared close paren space regardless of the number of edges. For sparse graphs (|E|≪n2 the absolute value of E is much less than n squared), this is inefficient. Alternative representations like adjacency lists use O⁢(n+|E|) O times open paren n plus the absolute value of E close paren space.

Time Complexity of Operations

Checking if edge (i,j) open paren i comma j close paren exists: O⁡(1) O of 1 with adjacency matrix, O⁢(deg⁢(i)) O times open paren degree times i close paren with adjacency list.

Iterating over neighbors of vertex i i: O⁡(n) O of n with adjacency matrix, O⁢(deg⁢(i)) O times open paren degree times i close paren with adjacency list.

Matrix multiplication Ak A to the k-th power: O⁡(n3) O of open paren n cubed close paren using standard multiplication, or O⁡(n2.37) O of open paren n raised to the 2.37 power close paren using fast matrix multiplication.

Applications

PageRank

The PageRank algorithm uses a modified adjacency matrix to rank web pages. The transition matrix
P=D−1⁢A P equals D to the negative 1 power A represents random walk probabilities, and PageRank finds the dominant eigenvector of a damped version of P P.

Spectral Clustering

The eigenvectors of the adjacency matrix (or Laplacian) are used to embed graph vertices into a low-dimensional space where clustering can be performed using standard algorithms like k-means.

Graph Neural Networks

Many graph neural network architectures use the adjacency matrix to aggregate information from neighboring nodes. The message passing operation often takes the form:

H(l+1)=σ⁢(A^⁢H(l)⁢W(l)) the open paren l-th plus first close paren power of H equals sigma times open paren A hat the l-th power of H W raised to the l power close paren

where A~ A tilde is a normalized adjacency matrix, H(l) the l-th power of H is the feature matrix at layer l l, W(l) W raised to the l power is a learnable weight matrix, and σ sigma is an activation function.

Network Analysis

The adjacency matrix is fundamental in analyzing social networks, biological networks, and communication networks. Centrality measures, community detection, and influence propagation all use the adjacency matrix or its variants.

Special Cases

Complete Graph Kn K sub n: The adjacency matrix is J−I J minus I, where J J is the all-ones matrix. Eigenvalues: n−1 n minus 1 (with multiplicity 1 1) and −1 negative 1 (with multiplicity n−1 n minus 1).

Cycle Graph Cn C sub n: The adjacency matrix is a circulant matrix. Eigenvalues:
2⁢cos⁡2⁢π⁢kn 2 the cosine of 2 pi k over n for k=0,1,…,n−1 k equals 0 comma 1 comma dot dot dot comma n minus 1.

Path Graph Pn P sub n: The adjacency matrix is tridiagonal with 1 1s on the super- and sub-diagonals.

Summary

The adjacency matrix A A is an n×n n times n matrix representing a graph, where
Ai⁢j=1 A sub i j equals 1 if there is an edge from vertex i i to vertex j j, and 0 0 otherwise. For undirected graphs, A A is symmetric.

Key properties include: row/column sums give vertex degrees; (Ak)i⁢j open paren A to the k-th power close paren sub i j counts walks of length k k from i i to j j; the trace of A3 A cubed divided by 6 6 gives the triangle count.

The eigenvalues of A A reveal structural properties: the largest eigenvalue is bounded by minimum and maximum degree; its multiplicity equals the number of connected components; symmetric spectrum indicates bipartiteness.

Related matrices include the Laplacian L=D−A L equals D minus A. The adjacency matrix is widely used in network analysis, machine learning, and algorithm design.