TExcelTAD
Home › Spectral Graph Theory & Modern Graph Algorithms › Adjacency, Degree and Laplacian Matrices

Adjacency, Degree and Laplacian Matrices

Three matrices carry most of spectral graph theory. The adjacency matrix records which pairs are joined, the degree matrix records how many edges meet each vertex, and their difference, the Laplacian, turns out to be the one whose quadratic form measures how much a function on the vertices changes across edges. This lesson defines them, proves that the Laplacian is positive semidefinite, and shows how cut sizes and walk counts can be read off the matrices.

The three matrices

Let G=(V,E,w)G = (V, E, w) be a weighted undirected graph with V={1,…,n}V = \{1, \ldots, n\} and weights wuv>0w_{uv} > 0 on its edges.

  • The adjacency matrix AA has Auv=wuvA_{uv} = w_{uv} if {u,v}∈E\{u, v\} \in E and Auv=0A_{uv} = 0 otherwise. It is symmetric.
  • The degree matrix DD is diagonal with Dvv=dv=∑uAuvD_{vv} = d_v = \sum_u A_{uv}, the (weighted) degree.
  • The Laplacian is L=D−AL = D - A.

Every row of LL sums to zero, so L1=0L\mathbf{1} = 0. For a graph on four vertices with edges 12,13,23,3412, 13, 23, 34:

A=(0110101011010010),L=(2−1−10−12−10−1−13−100−11).A = \begin{pmatrix} 0 & 1 & 1 & 0 \\ 1 & 0 & 1 & 0 \\ 1 & 1 & 0 & 1 \\ 0 & 0 & 1 & 0 \end{pmatrix}, \qquad L = \begin{pmatrix} 2 & -1 & -1 & 0 \\ -1 & 2 & -1 & 0 \\ -1 & -1 & 3 & -1 \\ 0 & 0 & -1 & 1 \end{pmatrix}.

The quadratic form

The single most useful identity in the course is the formula for xTLxx^{\mathsf{T}} L x, for any vector x∈RVx \in \mathbb{R}^V viewed as a function on the vertices:

xTLx=∑{u,v}∈Ewuv(xu−xv)2.x^{\mathsf{T}} L x = \sum_{\{u, v\} \in E} w_{uv} (x_u - x_v)^2 .

Proof. For an edge e={u,v}e = \{u, v\} let be=eu−evb_e = \mathbf{e}_u - \mathbf{e}_v (the orientation does not matter) and define the edge Laplacian Le=webebeTL_e = w_e b_e b_e^{\mathsf{T}}. It has wew_e at positions (u,u)(u, u) and (v,v)(v, v), −we-w_e at (u,v)(u, v) and (v,u)(v, u), and zeros elsewhere. Summing over the edges puts dvd_v on each diagonal entry and −wuv-w_{uv} off the diagonal, so L=∑eLeL = \sum_e L_e. Then xTLex=we(beTx)2=we(xu−xv)2x^{\mathsf{T}} L_e x = w_e (b_e^{\mathsf{T}} x)^2 = w_e (x_u - x_v)^2, and summing gives the claim. □\square

Three consequences follow at once.

  1. LL is positive semidefinite: xTLx≥0x^{\mathsf{T}} L x \ge 0 for every xx, so all its eigenvalues are nonnegative.
  2. Cuts are quadratic forms. For S⊆VS \subseteq V and its indicator vector 1S\mathbf{1}_S, the term (xu−xv)2(x_u - x_v)^2 is 1 exactly when the edge crosses between SS and S‾\overline{S}, so 1STL 1S=w(∂S)\mathbf{1}_S^{\mathsf{T}} L\, \mathbf{1}_S = w(\partial S), the weight of the cut.
  3. Smoothness. xTLxx^{\mathsf{T}} L x is small when xx changes little along edges. An eigenvector with a small eigenvalue is a "smooth" function on the graph; this is why low eigenvectors reveal clusters.

In matrix form, let BB be the m×nm \times n signed incidence matrix whose row for edge ee is beTb_e^{\mathsf{T}}, and WW the diagonal matrix of edge weights. Then L=BTWBL = B^{\mathsf{T}} W B. The program checks all of this on the four-vertex example.

python · try it yourself
import numpy as np

n = 4
edges = [(0, 1), (0, 2), (1, 2), (2, 3)]
A = np.zeros((n, n))
for u, v in edges:
    A[u, v] = A[v, u] = 1
D = np.diag(A.sum(axis=1))
L = D - A
B = np.zeros((len(edges), n))                  # signed incidence matrix, one row per edge
for i, (u, v) in enumerate(edges):
    B[i, u], B[i, v] = 1, -1
print("L =\n", L.astype(int))
print("L == B^T B:", np.array_equal(L, B.T @ B))

rng = np.random.default_rng(1)
x = rng.integers(-3, 4, size=n).astype(float)
print("x =", x, " x^T L x =", float(x @ L @ x),
      " sum over edges =", sum((x[u] - x[v]) ** 2 for u, v in edges))
S = np.array([1.0, 1.0, 0.0, 0.0])             # S = {0, 1}
print("cut of S = {0, 1}:", float(S @ L @ S), " (edges 0-2 and 1-2 cross)")
print("eigenvalues of L:", np.round(np.linalg.eigvalsh(L), 4) + 0.0)
L =
 [[ 2 -1 -1  0]
 [-1  2 -1  0]
 [-1 -1  3 -1]
 [ 0  0 -1  1]]
L == B^T B: True
x = [0. 0. 2. 3.]  x^T L x = 9.0  sum over edges = 9.0
cut of S = {0, 1}: 2.0  (edges 0-2 and 1-2 cross)
eigenvalues of L: [0. 1. 3. 4.]

The eigenvalues are nonnegative, the smallest is 0, and the quadratic form agrees with the edge sum for an arbitrary integer vector.

What the adjacency matrix counts

Powers of AA count walks: (Ak)uv(A^k)_{uv} is the number of walks of length kk from uu to vv in an unweighted graph, by induction on kk (a walk of length kk is a walk of length k−1k - 1 followed by one edge). Taking traces,

tr⁡(A2)=∑vdv=2m,tr⁡(A3)=6⋅#triangles,\operatorname{tr}(A^2) = \sum_v d_v = 2m, \qquad \operatorname{tr}(A^3) = 6 \cdot \#\text{triangles},

because a closed walk of length 3 is a triangle traversed from one of its 3 corners in one of 2 directions. Since tr⁡(Ak)=∑iμik\operatorname{tr}(A^k) = \sum_i \mu_i^k for the eigenvalues μi\mu_i of AA, the spectrum alone determines the number of edges and triangles. It does not determine the graph: there are non-isomorphic cospectral graphs, the smallest pair being the star K1,4K_{1,4} and the disjoint union of a 4-cycle and an isolated vertex, both with adjacency spectrum {2,0,0,0,−2}\{2, 0, 0, 0, -2\}.

python · try it yourself
import numpy as np

def adjacency(n, edges):
    A = np.zeros((n, n))
    for u, v in edges:
        A[u, v] = A[v, u] = 1
    return A

# the Petersen graph: outer 5-cycle, inner pentagram, spokes
edges = [(i, (i + 1) % 5) for i in range(5)] + [(5 + i, 5 + (i + 2) % 5) for i in range(5)] + [(i, i + 5) for i in range(5)]
A = adjacency(10, edges)
mu = np.linalg.eigvalsh(A)
print("Petersen: m =", len(edges), " tr(A^2)/2 =", float(np.trace(A @ A)) / 2,
      " triangles = tr(A^3)/6 =", float(np.trace(A @ A @ A)) / 6)
print("adjacency spectrum:", np.round(mu[::-1], 4) + 0.0)
print("walks of length 4 from 0 to 1:", int(np.linalg.matrix_power(A, 4)[0, 1]))

star = adjacency(5, [(0, 1), (0, 2), (0, 3), (0, 4)])
c4_plus_point = adjacency(5, [(0, 1), (1, 2), (2, 3), (3, 0)])
for name, M in [("star K_{1,4}", star), ("C_4 + isolated vertex", c4_plus_point)]:
    print(f"{name:22} adjacency spectrum {np.round(np.linalg.eigvalsh(M)[::-1], 4) + 0.0}")
Petersen: m = 15  tr(A^2)/2 = 15.0  triangles = tr(A^3)/6 = 0.0
adjacency spectrum: [ 3.  1.  1.  1.  1.  1. -2. -2. -2. -2.]
walks of length 4 from 0 to 1: 4
star K_{1,4}           adjacency spectrum [ 2.  0.  0.  0. -2.]
C_4 + isolated vertex  adjacency spectrum [ 2.  0.  0.  0. -2.]

The Petersen graph is 3-regular, has no triangles and only three distinct eigenvalues, 3, 1 and −2-2. The last two lines show the cospectral pair: one graph is connected and the other is not, yet their adjacency spectra agree. (Their Laplacian spectra differ, since the Laplacian sees connectivity, as the lesson Eigenvalue Zero and Connected Components proves.)

Bounds on the spectrum

For a dd-regular graph, L=dI−AL = dI - A, so the Laplacian eigenvalues are λi=d−μi\lambda_i = d - \mu_i and the two matrices carry the same information. For general graphs they do not, and the Laplacian is the better-behaved one for cuts. Two quick bounds:

  • λn≤2dmax⁡\lambda_n \le 2 d_{\max}. Using (xu−xv)2≤2xu2+2xv2(x_u - x_v)^2 \le 2x_u^2 + 2x_v^2 in the quadratic form, xTLx≤2∑vdvxv2≤2dmax⁡∥x∥2x^{\mathsf{T}} L x \le 2\sum_v d_v x_v^2 \le 2d_{\max} \lVert x \rVert^2. Equality needs a regular bipartite component.
  • μ1≤dmax⁡\mu_1 \le d_{\max} and μ1≥dˉ=2m/n\mu_1 \ge \bar d = 2m/n. The upper bound: take an eigenvector xx for μ1\mu_1 and the vertex vv maximizing ∣xv∣\lvert x_v \rvert; then ∣μ1xv∣=∣∑u∼vxu∣≤dv∣xv∣\lvert \mu_1 x_v \rvert = \lvert \sum_{u \sim v} x_u \rvert \le d_v \lvert x_v \rvert. The lower bound: the Rayleigh quotient of 1\mathbf{1} is 1TA1/n=2m/n\mathbf{1}^{\mathsf{T}} A \mathbf{1}/n = 2m/n.
python · try it yourself
import random
import numpy as np

rng = random.Random(3)
n = 30
edges = [(u, v) for u in range(n) for v in range(u + 1, n) if rng.random() < 0.15]
A = np.zeros((n, n))
for u, v in edges:
    A[u, v] = A[v, u] = 1
d = A.sum(axis=1)
L = np.diag(d) - A
lam = np.linalg.eigvalsh(L)
mu = np.linalg.eigvalsh(A)
print(f"n = {n}, m = {len(edges)}, average degree {2 * len(edges) / n:.4f}, max degree {int(d.max())}")
print(f"largest adjacency eigenvalue {float(mu[-1]):.4f}  (between average and max degree)")
print(f"largest Laplacian eigenvalue {float(lam[-1]):.4f}  (at most 2 d_max = {int(2 * d.max())})")
print(f"smallest Laplacian eigenvalue {float(abs(lam[0])):.4f}")
n = 30, m = 59, average degree 3.9333, max degree 10
largest adjacency eigenvalue 4.8739  (between average and max degree)
largest Laplacian eigenvalue 11.4500  (at most 2 d_max = 20)
smallest Laplacian eigenvalue 0.0000

Test yourself

What is xTLxx^{\mathsf{T}} L x for the Laplacian of a weighted graph?

  1. ∑vdvxv2\sum_v d_v x_v^2
  2. ∑{u,v}∈Ewuv(xu−xv)2\sum_{\{u,v\} \in E} w_{uv}(x_u - x_v)^2
  3. ∑{u,v}∈Ewuvxuxv\sum_{\{u,v\} \in E} w_{uv} x_u x_v
  4. (∑vxv)2(\sum_v x_v)^2

For S⊆VS \subseteq V, what is 1STL 1S\mathbf{1}_S^{\mathsf{T}} L\, \mathbf{1}_S?

  1. ∣S∣\lvert S \rvert
  2. The number of edges inside SS
  3. The total weight of edges with exactly one end in SS
  4. The volume of SS

How many triangles does a graph have if tr⁡(A3)=24\operatorname{tr}(A^3) = 24?

  1. 24
  2. 8
  3. 4
  4. 3

Which statement about the star K1,4K_{1,4} and C4C_4 plus an isolated vertex is true?

  1. They are isomorphic
  2. They have the same adjacency spectrum but different Laplacian spectra
  3. They have the same Laplacian spectrum
  4. Their adjacency spectra differ in the largest eigenvalue