spectral graphs are fun :D

spectral graphs are fun :D

August 31, 2026 · 27 min read

Two common problems in graph theory look purely combinatorial on the surface:

  1. Graph Layout: Given a set of vertices and edges, compute coordinates (xu,yu)(x_u, y_u) for each vertex in 2D space such that connected vertices are positioned near each other while avoiding unnecessary edge crossings.
  2. Graph Partitioning: Partition the vertices into two subsets of roughly equal size such that the number of cut edges across the partition is minimized.

Finding the optimal balanced partition (minimizing conductance) is NP hard. Yet both problems can be approximated directly using linear algebra by computing the eigenvectors of a single symmetric matrix called the Graph Laplacian.


1. The Graph Laplacian and Quadratic Forms

Let G=(V,E)G = (V, E) be an undirected, unweighted graph with nn vertices.

We define two matrices associated with GG:

  • The Degree Matrix (DD): an n×nn \times n diagonal matrix where Duu=deg(u)D_{uu} = \text{deg}(u) is the degree of vertex uu.
  • The Adjacency Matrix (AA): an n×nn \times n symmetric matrix where Auv=1A_{uv} = 1 if (u,v)E(u, v) \in E, and Auv=0A_{uv} = 0 otherwise.

The Graph Laplacian LL is defined as:

L=DAL = D - A

Suppose we assign a real value xuRx_u \in \mathbb{R} to each vertex uu, forming a vector x=(x1,,xn)TRnx = (x_1, \dots, x_n)^T \in \mathbb{R}^n. Evaluating the quadratic form xTLxx^T L x gives:

xTLx=xTDxxTAx=uVdeg(u)xu22(u,v)Exuxvx^T L x = x^T D x - x^T A x = \sum_{u \in V} \text{deg}(u) x_u^2 - 2 \sum_{(u, v) \in E} x_u x_v

Since deg(u)=v:(u,v)E1\text{deg}(u) = \sum_{v : (u, v) \in E} 1, we can rewrite the first sum over edges:

xTLx=(u,v)E(xuxv)2x^T L x = \sum_{(u, v) \in E} (x_u - x_v)^2

This formulation reveals the physical intuition behind LL. If we view each edge as a unit spring connecting vertices along a 1D coordinate axis, xTLxx^T L x represents the total potential energy of the system. Minimizing xTLxx^T L x corresponds to finding vertex positions that minimize the total squared distance between connected pairs.

Because (xuxv)20(x_u - x_v)^2 \ge 0 for every edge, xTLx0x^T L x \ge 0 for all xRnx \in \mathbb{R}^n. Thus, LL is positive semidefinite (L0L \succeq 0), and all its eigenvalues are real and nonnegative:

0=λ1λ2λ3λn0 = \lambda_1 \le \lambda_2 \le \lambda_3 \le \dots \le \lambda_n


2. The Trivial Solution and the Fiedler Vector

If we simply minimize xTLxx^T L x without constraints, the minimum is 0, achieved by setting all xux_u equal to a constant cc.

This corresponds to the all ones vector 1=(1,1,,1)T\mathbf{1} = (1, 1, \dots, 1)^T:

L1=(DA)1=0L \mathbf{1} = (D - A)\mathbf{1} = \mathbf{0}

Thus, λ1=0\lambda_1 = 0 is always an eigenvalue of LL with eigenvector v1=1v_1 = \mathbf{1}. In general, the multiplicity of the 0 eigenvalue equals the number of connected components in GG.

To obtain a nontrivial coordinate assignment, we enforce two normalization conditions:

  1. Centering at the origin: uVxu=0\sum_{u \in V} x_u = 0, which is equivalent to x1x \perp \mathbf{1}.
  2. Fixed variance: uVxu2=1\sum_{u \in V} x_u^2 = 1, which is equivalent to x2=1\|x\|_2 = 1.

We then consider the constrained optimization problem:

minx2=1x1xTLx\min_{\substack{\|x\|_2 = 1 \\ x \perp \mathbf{1}}} x^T L x

By the Rayleigh Ritz theorem, the solution to this problem is given by the eigenvector corresponding to the second smallest eigenvalue λ2\lambda_2 of LL.

This eigenvector v2v_2 is known as the Fiedler vector, and λ2\lambda_2 is called the algebraic connectivity of the graph.


3. A Worked Example: The Four Node Path Graph

Consider a four node path graph:

(1) === (2) === (3) === (4)

The degree matrix DD and adjacency matrix AA are:

D=(1000020000200001),A=(0100101001010010)D = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 2 & 0 & 0 \\ 0 & 0 & 2 & 0 \\ 0 & 0 & 0 & 1 \end{pmatrix}, \quad A = \begin{pmatrix} 0 & 1 & 0 & 0 \\ 1 & 0 & 1 & 0 \\ 0 & 1 & 0 & 1 \\ 0 & 0 & 1 & 0 \end{pmatrix}

The Laplacian L=DAL = D - A is:

L=(1100121001210011)L = \begin{pmatrix} 1 & -1 & 0 & 0 \\ -1 & 2 & -1 & 0 \\ 0 & -1 & 2 & -1 \\ 0 & 0 & -1 & 1 \end{pmatrix}

The characteristic polynomial of LL factors as:

det(LλI)=λ(λ2)(λ24λ+2)=0\det(L - \lambda I) = \lambda (\lambda - 2) (\lambda^2 - 4\lambda + 2) = 0

The eigenvalues are:

λ1=0,λ2=220.586,λ3=2.0,λ4=2+23.414\lambda_1 = 0, \quad \lambda_2 = 2 - \sqrt{2} \approx 0.586, \quad \lambda_3 = 2.0, \quad \lambda_4 = 2 + \sqrt{2} \approx 3.414

The normalized Fiedler eigenvector v2v_2 for λ2=22\lambda_2 = 2 - \sqrt{2} is:

v2=12(1+1/211/2+11/2+1+1/2)(0.6530.271+0.271+0.653)v_2 = \frac{1}{2} \begin{pmatrix} -\sqrt{1 + 1/\sqrt{2}} \\ -\sqrt{1 - 1/\sqrt{2}} \\ +\sqrt{1 - 1/\sqrt{2}} \\ +\sqrt{1 + 1/\sqrt{2}} \end{pmatrix} \approx \begin{pmatrix} -0.653 \\ -0.271 \\ +0.271 \\ +0.653 \end{pmatrix}

The entries of v2v_2 assign coordinates to the vertices in order along a 1D line:

  • v2(1)0.653v_2(1) \approx -0.653
  • v2(2)0.271v_2(2) \approx -0.271
  • v2(3)+0.271v_2(3) \approx +0.271
  • v2(4)+0.653v_2(4) \approx +0.653

The eigenvector recovers the linear ordering and symmetric spacing of the path graph purely from the entries of LL.


4. 2D Spectral Graph Drawing

To embed a graph in R2\mathbb{R}^2, we compute two orthogonal 1D coordinate assignments.

We choose:

  • x coordinates from the second eigenvector: x=v2x = v_2
  • y coordinates from the third eigenvector: y=v3y = v_3 (which satisfies v31v_3 \perp \mathbf{1} and v3v2v_3 \perp v_2)

Each vertex uu is plotted at the point (v2(u),v3(u))(v_2(u), v_3(u)).

The figure below compares embeddings generated by the smallest nontrivial eigenvectors (v2,v3)(v_2, v_3) against embeddings generated by the largest eigenvectors (vn,vn1)(v_n, v_{n-1}):

Spectral Graph Embeddings: Cycle and Grid Graphs

Mathematical Basis for the Layouts:

  • Top Left (20 node cycle with v2,v3v_2, v_3): The Laplacian of a cycle graph is a circulant matrix. Its eigenvectors are discrete Fourier modes of the form v(k)=(cos(2πjk/n))j=1nv(k) = (\cos(2\pi j k / n))_{j=1}^n and (sin(2πjk/n))j=1n(\sin(2\pi j k / n))_{j=1}^n. Plotting (v2,v3)(v_2, v_3) evaluates the fundamental frequency (k=1k=1), reconstructing a regular polygon in the plane.
  • Top Right (20 node cycle with vn,vn1v_n, v_{n-1}): The largest eigenvectors maximize the quadratic form (xuxv)2\sum (x_u - x_v)^2, forcing adjacent vertices to opposite sides of the origin.
  • Bottom Left (20×2020 \times 20 grid with v2,v3v_2, v_3): The Cartesian product structure of the grid yields tensor product eigenvectors that untangle the vertices into a planar grid.
  • Bottom Right (20×2020 \times 20 grid with vn,vn1v_n, v_{n-1}): High frequency eigenmodes create a heavily self intersecting configuration.

5. Spectral Graph Partitioning

The Fiedler vector also provides an approximation for the graph cut problem.

For a subset of vertices SVS \subset V, let Sˉ=VS\bar{S} = V \setminus S. The conductance ϕ(S)\phi(S) is defined as:

ϕ(S)=E(S,Sˉ)min(S,Sˉ)\phi(S) = \frac{|E(S, \bar{S})|}{\min(|S|, |\bar{S}|)}

Where E(S,Sˉ)|E(S, \bar{S})| is the number of edges with one endpoint in SS and one in Sˉ\bar{S}. The conductance of the graph is:

ϕ(G)=minSV0<SV/2ϕ(S)\phi(G) = \min_{\substack{S \subset V \\ 0 < |S| \le |V|/2}} \phi(S)

Finding the subset SS that minimizes conductance is NP hard. The Sweep Cut algorithm uses v2v_2 to find an approximate solution:

  1. Compute the Fiedler vector v2v_2 of LL.
  2. Sort the vertices such that v2(u1)v2(u2)v2(un)v_2(u_1) \le v_2(u_2) \le \dots \le v_2(u_n).
  3. Evaluate the conductance of each prefix set Sk={u1,,uk}S_k = \{u_1, \dots, u_k\} for k=1,,n1k = 1, \dots, n-1.
  4. Select the prefix cut that achieves the minimum conductance.

In our four node path example, v2=(0.653,0.271,+0.271,+0.653)v_2 = (-0.653, -0.271, +0.271, +0.653). The sign changes between vertices 2 and 3. The partition S={1,2}S = \{1, 2\} and Sˉ={3,4}\bar{S} = \{3, 4\} cuts exactly 1 edge with S=2|S| = 2, yielding conductance ϕ(S)=1/2\phi(S) = 1/2, which is optimal.

Cheeger’s Inequality

The theoretical guarantee for spectral partitioning is provided by Cheeger’s Inequality (adapted to graphs by Alon and Milman):

λ22ϕ(G)2dmaxλ2\frac{\lambda_2}{2} \le \phi(G) \le \sqrt{2 d_{\max} \lambda_2}

Where dmaxd_{\max} is the maximum degree in GG.

This inequality establishes that:

  • If λ2\lambda_2 is close to 0, there exists a cut with small conductance (a sparse bottleneck).
  • If λ2\lambda_2 is bounded away from 0, the graph is an expander graph, and no sparse cut exists.

6. Implementation

The following Python function computes the 2D spectral coordinates and performs the sweep cut on a sparse adjacency matrix:

import numpy as np
import scipy.sparse as sp
import scipy.sparse.linalg as sla
def spectral_embedding(adj_matrix):
"""Computes 2D coordinates (v2, v3) from the Graph Laplacian."""
degrees = np.array(adj_matrix.sum(axis=1)).flatten()
n = len(degrees)
# Construct Laplacian L = D - A
L = sp.diags(degrees) - adj_matrix
# Compute the 3 smallest eigenvalues and eigenvectors
vals, vecs = sla.eigsh(L.astype(float), k=3, which='SM')
order = np.argsort(vals)
v2 = vecs[:, order[1]]
v3 = vecs[:, order[2]]
return v2, v3
def sweep_cut(adj_matrix):
"""Finds the minimal conductance cut along the Fiedler vector."""
v2, _ = spectral_embedding(adj_matrix)
order = np.argsort(v2)
n = len(order)
best_cond = float('inf')
best_split = None
for k in range(1, n):
S = set(order[:k])
cut_edges = sum(
1 for u in S
for v in adj_matrix[u].indices
if v not in S
)
cond = cut_edges / min(len(S), n - len(S))
if cond < best_cond:
best_cond = cond
best_split = S
return best_split, best_cond

7. Summary

ObjectLinear Algebra DefinitionGraph Theoretic Meaning
L=DAL = D - ALaplacian matrixQuadratic energy operator on vertex coordinates
λ1=0,v1=1\lambda_1 = 0, v_1 = \mathbf{1}Smallest eigenvalue and eigenvectorConstant coordinate state; multiplicity gives connected components
λ2,v2\lambda_2, v_2Second eigenvalue (algebraic connectivity) and Fiedler vectorLowest nontrivial energy mode; orders vertices along bottlenecks
v2,v3v_2, v_3Second and third eigenvectorsFirst two orthogonal harmonic coordinates for 2D layout
Cheeger’s Boundλ2/2ϕ(G)2dmaxλ2\lambda_2 / 2 \le \phi(G) \le \sqrt{2 d_{\max} \lambda_2}Two sided bound relating continuous eigenvalue to discrete conductance

subscribe to be updated when i post ^-^

you'll get an email whenever i post either a thought, or a math writeup