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 be a weighted undirected graph with and weights on its edges.
- The adjacency matrix has if and otherwise. It is symmetric.
- The degree matrix is diagonal with , the (weighted) degree.
- The Laplacian is .
Every row of sums to zero, so . For a graph on four vertices with edges :
The quadratic form
The single most useful identity in the course is the formula for , for any vector viewed as a function on the vertices:
Proof. For an edge let (the orientation does not matter) and define the edge Laplacian . It has at positions and , at and , and zeros elsewhere. Summing over the edges puts on each diagonal entry and off the diagonal, so . Then , and summing gives the claim.
Three consequences follow at once.
- is positive semidefinite: for every , so all its eigenvalues are nonnegative.
- Cuts are quadratic forms. For and its indicator vector , the term is 1 exactly when the edge crosses between and , so , the weight of the cut.
- Smoothness. is small when 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 be the signed incidence matrix whose row for edge is , and the diagonal matrix of edge weights. Then . The program checks all of this on the four-vertex example.
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 count walks: is the number of walks of length from to in an unweighted graph, by induction on (a walk of length is a walk of length followed by one edge). Taking traces,
because a closed walk of length 3 is a triangle traversed from one of its 3 corners in one of 2 directions. Since for the eigenvalues of , 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 and the disjoint union of a 4-cycle and an isolated vertex, both with adjacency spectrum .
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 . 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 -regular graph, , so the Laplacian eigenvalues are 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:
- . Using in the quadratic form, . Equality needs a regular bipartite component.
- and . The upper bound: take an eigenvector for and the vertex maximizing ; then . The lower bound: the Rayleigh quotient of is .
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 for the Laplacian of a weighted graph?
For , what is ?
- The number of edges inside
- The total weight of edges with exactly one end in
- The volume of
How many triangles does a graph have if ?
- 24
- 8
- 4
- 3
Which statement about the star and plus an isolated vertex is true?
- They are isomorphic
- They have the same adjacency spectrum but different Laplacian spectra
- They have the same Laplacian spectrum
- Their adjacency spectra differ in the largest eigenvalue