spectral graphs are fun :D
August 31, 2026 · 27 min read
Two common problems in graph theory look purely combinatorial on the surface:
- Graph Layout: Given a set of vertices and edges, compute coordinates for each vertex in 2D space such that connected vertices are positioned near each other while avoiding unnecessary edge crossings.
- 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 be an undirected, unweighted graph with vertices.
We define two matrices associated with :
- The Degree Matrix (): an diagonal matrix where is the degree of vertex .
- The Adjacency Matrix (): an symmetric matrix where if , and otherwise.
The Graph Laplacian is defined as:
Suppose we assign a real value to each vertex , forming a vector . Evaluating the quadratic form gives:
Since , we can rewrite the first sum over edges:
This formulation reveals the physical intuition behind . If we view each edge as a unit spring connecting vertices along a 1D coordinate axis, represents the total potential energy of the system. Minimizing corresponds to finding vertex positions that minimize the total squared distance between connected pairs.
Because for every edge, for all . Thus, is positive semidefinite (), and all its eigenvalues are real and nonnegative:
2. The Trivial Solution and the Fiedler Vector
If we simply minimize without constraints, the minimum is 0, achieved by setting all equal to a constant .
This corresponds to the all ones vector :
Thus, is always an eigenvalue of with eigenvector . In general, the multiplicity of the 0 eigenvalue equals the number of connected components in .
To obtain a nontrivial coordinate assignment, we enforce two normalization conditions:
- Centering at the origin: , which is equivalent to .
- Fixed variance: , which is equivalent to .
We then consider the constrained optimization problem:
By the Rayleigh Ritz theorem, the solution to this problem is given by the eigenvector corresponding to the second smallest eigenvalue of .
This eigenvector is known as the Fiedler vector, and 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 and adjacency matrix are:
The Laplacian is:
The characteristic polynomial of factors as:
The eigenvalues are:
The normalized Fiedler eigenvector for is:
The entries of assign coordinates to the vertices in order along a 1D line:
The eigenvector recovers the linear ordering and symmetric spacing of the path graph purely from the entries of .
4. 2D Spectral Graph Drawing
To embed a graph in , we compute two orthogonal 1D coordinate assignments.
We choose:
- x coordinates from the second eigenvector:
- y coordinates from the third eigenvector: (which satisfies and )
Each vertex is plotted at the point .
The figure below compares embeddings generated by the smallest nontrivial eigenvectors against embeddings generated by the largest eigenvectors :

Mathematical Basis for the Layouts:
- Top Left (20 node cycle with ): The Laplacian of a cycle graph is a circulant matrix. Its eigenvectors are discrete Fourier modes of the form and . Plotting evaluates the fundamental frequency (), reconstructing a regular polygon in the plane.
- Top Right (20 node cycle with ): The largest eigenvectors maximize the quadratic form , forcing adjacent vertices to opposite sides of the origin.
- Bottom Left ( grid with ): The Cartesian product structure of the grid yields tensor product eigenvectors that untangle the vertices into a planar grid.
- Bottom Right ( grid with ): 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 , let . The conductance is defined as:
Where is the number of edges with one endpoint in and one in . The conductance of the graph is:
Finding the subset that minimizes conductance is NP hard. The Sweep Cut algorithm uses to find an approximate solution:
- Compute the Fiedler vector of .
- Sort the vertices such that .
- Evaluate the conductance of each prefix set for .
- Select the prefix cut that achieves the minimum conductance.
In our four node path example, . The sign changes between vertices 2 and 3. The partition and cuts exactly 1 edge with , yielding conductance , 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):
Where is the maximum degree in .
This inequality establishes that:
- If is close to 0, there exists a cut with small conductance (a sparse bottleneck).
- If 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 npimport scipy.sparse as spimport 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_cond7. Summary
| Object | Linear Algebra Definition | Graph Theoretic Meaning |
|---|---|---|
| Laplacian matrix | Quadratic energy operator on vertex coordinates | |
| Smallest eigenvalue and eigenvector | Constant coordinate state; multiplicity gives connected components | |
| Second eigenvalue (algebraic connectivity) and Fiedler vector | Lowest nontrivial energy mode; orders vertices along bottlenecks | |
| Second and third eigenvectors | First two orthogonal harmonic coordinates for 2D layout | |
| Cheeger’s Bound | Two sided bound relating continuous eigenvalue to discrete conductance |