TExcelTAD
Home › Spectral Graph Theory & Modern Graph Algorithms › Eigenvalue Zero and Connected Components

Eigenvalue Zero and Connected Components

The first theorem of spectral graph theory connects the bottom of the Laplacian spectrum to the most basic graph property, connectivity: the number of zero eigenvalues equals the number of connected components. In particular λ2>0\lambda_2 > 0 exactly when the graph is connected. This lesson proves it, turns "how far from zero" into a quantitative bound involving the diameter, and looks at what goes wrong when eigenvalues are computed in floating point.

The theorem

Theorem. Let GG be a graph with positive edge weights and Laplacian LL. The multiplicity of the eigenvalue 0 of LL equals the number cc of connected components of GG. The same holds for the normalized Laplacian NN (when there are no isolated vertices).

Proof. Because LL is symmetric, the multiplicity of 0 is dim⁡ker⁡L\dim \ker L. Since LL is positive semidefinite, Lx=0Lx = 0 if and only if xTLx=0x^{\mathsf{T}} L x = 0 (one direction is trivial; for the other, write L=BTWBL = B^{\mathsf{T}} W B, then xTLx=∥W1/2Bx∥2=0x^{\mathsf{T}} L x = \lVert W^{1/2} B x \rVert^2 = 0 forces Bx=0Bx = 0 and so Lx=0Lx = 0). Now

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

holds if and only if xu=xvx_u = x_v along every edge, that is, xx is constant on each connected component. If the components are C1,…,CcC_1, \ldots, C_c, the kernel is therefore spanned by the indicator vectors 1C1,…,1Cc\mathbf{1}_{C_1}, \ldots, \mathbf{1}_{C_c}, which are nonzero and have disjoint supports, hence linearly independent. So dim⁡ker⁡L=c\dim \ker L = c. For N=D−1/2LD−1/2N = D^{-1/2} L D^{-1/2} the kernel is D1/2ker⁡LD^{1/2} \ker L, of the same dimension. □\square

Corollary. GG is connected if and only if λ2(L)>0\lambda_2(L) > 0. The quantity λ2(L)\lambda_2(L) is called the algebraic connectivity (Fiedler, 1973).

The proof also says what the eigenvectors of 0 look like: any orthonormal basis of the kernel is a rotation of the normalized indicator vectors. A numerical solver may return any such rotation, so the kernel vectors themselves are not unique, but the rows of the n×cn \times c matrix of kernel vectors are equal for vertices in the same component and orthogonal across components. That observation is the seed of spectral clustering: with kk well-separated clusters, the bottom kk eigenvectors are close to a rotation of the cluster indicators.

python · try it yourself
from collections import deque
import numpy as np

def laplacian(n, edges):
    L = np.zeros((n, n))
    for u, v in edges:
        L[u, u] += 1; L[v, v] += 1; L[u, v] -= 1; L[v, u] -= 1
    return L

def bfs_components(n, edges):
    adj = [[] for _ in range(n)]
    for u, v in edges:
        adj[u].append(v); adj[v].append(u)
    comp, c = [-1] * n, 0
    for s in range(n):
        if comp[s] < 0:
            comp[s], queue = c, deque([s])
            while queue:
                u = queue.popleft()
                for v in adj[u]:
                    if comp[v] < 0:
                        comp[v] = c; queue.append(v)
            c += 1
    return comp

# three pieces: a triangle {0, 3, 6}, a path 1-4-7, and the pair {2, 5}; vertex 8 is isolated
n = 9
edges = [(0, 3), (3, 6), (6, 0), (1, 4), (4, 7), (2, 5)]
vals, vecs = np.linalg.eigh(laplacian(n, edges))
zero = vals < 1e-9
print("eigenvalues:", np.round(vals, 4) + 0.0)
print("zero eigenvalues:", int(zero.sum()), "  BFS components:", max(bfs_components(n, edges)) + 1)
K = vecs[:, zero]                                   # an orthonormal basis of the kernel
rows = np.round(K @ K.T, 4) + 0.0                   # equal rows <=> same component
labels, seen = [], {}
for v in range(n):
    key = tuple(rows[v])
    labels.append(seen.setdefault(key, len(seen)))
print("components read from the kernel:", labels)
print("components from BFS:            ", bfs_components(n, edges))
eigenvalues: [0. 0. 0. 0. 1. 2. 3. 3. 3.]
zero eigenvalues: 4   BFS components: 4
components read from the kernel: [0, 1, 2, 0, 1, 2, 0, 1, 3]
components from BFS:             [0, 1, 2, 0, 1, 2, 0, 1, 3]

The kernel has dimension 4 (three pieces plus the isolated vertex), and grouping vertices by their rows in the kernel basis recovers the same partition as BFS. The product KKTKK^{\mathsf{T}} is used because it does not depend on which orthonormal basis the solver returned: it is the projection onto the kernel.

How large is λ2\lambda_2 for a connected graph?

Connectivity says λ2>0\lambda_2 > 0; a bound in terms of the graph's shape says how far from 0.

Claim. If GG is connected, unweighted, with diameter δ\delta, then λ2≥1nδ\lambda_2 \ge \frac{1}{n\delta}.

Proof. Let xx be a unit eigenvector for λ2\lambda_2, so x⊥1x \perp \mathbf{1} and ∑vxv2=1\sum_v x_v^2 = 1. Some entry has ∣xv∣≥1/n\lvert x_v \rvert \ge 1/\sqrt n, and since the entries sum to zero there are entries of both signs, so xmax⁡−xmin⁡≥1/nx_{\max} - x_{\min} \ge 1/\sqrt n. Take a shortest path a=p0,p1,…,pℓ=ba = p_0, p_1, \ldots, p_\ell = b from a vertex aa with xa=xmax⁡x_a = x_{\max} to a vertex bb with xb=xmin⁡x_b = x_{\min}; ℓ≤δ\ell \le \delta. By Cauchy-Schwarz,

λ2=∑{u,v}∈E(xu−xv)2≥∑i=1ℓ(xpi−1−xpi)2≥1ℓ(∑i=1ℓ(xpi−1−xpi))2=(xmax⁡−xmin⁡)2ℓ≥1nδ.□\lambda_2 = \sum_{\{u,v\} \in E} (x_u - x_v)^2 \ge \sum_{i=1}^{\ell} (x_{p_{i-1}} - x_{p_i})^2 \ge \frac{1}{\ell}\Big(\sum_{i=1}^{\ell} (x_{p_{i-1}} - x_{p_i})\Big)^2 = \frac{(x_{\max} - x_{\min})^2}{\ell} \ge \frac{1}{n\delta}. \qquad \square

Mohar (1991) sharpened the constant to λ2≥4nδ\lambda_2 \ge \frac{4}{n\delta} (stated here without proof). The path shows the order of magnitude is right: there δ=n−1\delta = n - 1 and λ2≈π2/n2\lambda_2 \approx \pi^2/n^2, between 4n(n−1)\frac{4}{n(n-1)} and 12n(n+1)\frac{12}{n(n+1)}.

python · try it yourself
import numpy as np
from collections import deque

def laplacian(n, edges):
    L = np.zeros((n, n))
    for u, v in edges:
        L[u, u] += 1; L[v, v] += 1; L[u, v] -= 1; L[v, u] -= 1
    return L

def diameter(n, edges):
    adj = [[] for _ in range(n)]
    for u, v in edges:
        adj[u].append(v); adj[v].append(u)
    best = 0
    for s in range(n):
        dist, queue = {s: 0}, deque([s])
        while queue:
            u = queue.popleft()
            for v in adj[u]:
                if v not in dist:
                    dist[v] = dist[u] + 1; queue.append(v)
        best = max(best, max(dist.values()))
    return best

graphs = {
    "path P_20": (20, [(i, i + 1) for i in range(19)]),
    "cycle C_20": (20, [(i, (i + 1) % 20) for i in range(20)]),
    "star K_{1,19}": (20, [(0, i) for i in range(1, 20)]),
    "two K_10 + bridge": (20, [(a + s, b + s) for s in (0, 10) for a in range(10) for b in range(a + 1, 10)] + [(9, 10)]),
}
print("graph               diam   lambda_2   1/(n diam)   4/(n diam)")
for name, (n, edges) in graphs.items():
    d = diameter(n, edges)
    lam2 = float(np.linalg.eigvalsh(laplacian(n, edges))[1])
    print(f"{name:18} {d:5}   {lam2:8.4f}   {1 / (n * d):10.4f}   {4 / (n * d):10.4f}")
graph               diam   lambda_2   1/(n diam)   4/(n diam)
path P_20             19     0.0246       0.0026       0.0105
cycle C_20            10     0.0979       0.0050       0.0200
star K_{1,19}          2     1.0000       0.0250       0.1000
two K_10 + bridge      3     0.1690       0.0167       0.0667

The bound is within a factor of 10 for the path and the cycle. The graph "two K10K_{10} joined by a bridge" has diameter only 3, as small as a dense graph's, yet its λ2\lambda_2 is more than a hundred times smaller than that of K20K_{20} (which is 20). Diameter alone cannot see a bottleneck; that is the job of conductance and Cheeger's inequality in the next section.

Zero in floating point

Numerically, "is λ2=0\lambda_2 = 0?" is a question about a tolerance. A connected graph with a very weak link has a tiny but positive λ2\lambda_2, and rounding errors of size about 10−16λn10^{-16} \lambda_n can make an exact zero look like ±10−15\pm 10^{-15}. Counting components with eigenvalues is therefore a teaching device, not an algorithm: BFS answers the question exactly in O(n+m)O(n + m) time. Spectral information becomes valuable for questions BFS cannot answer, such as how well a connected graph is connected.

python · try it yourself
import numpy as np

def weighted_laplacian(n, wedges):
    L = np.zeros((n, n))
    for u, v, w in wedges:
        L[u, u] += w; L[v, v] += w; L[u, v] -= w; L[v, u] -= w
    return L

# two triangles joined by one edge of weight eps
for eps in [1e-2, 1e-6, 1e-10, 1e-14, 0.0]:
    wedges = [(0, 1, 1), (1, 2, 1), (2, 0, 1), (3, 4, 1), (4, 5, 1), (5, 3, 1), (2, 3, eps)]
    lam = np.linalg.eigvalsh(weighted_laplacian(6, wedges))
    lam2 = float(lam[1])
    if abs(lam2) < 1e-13:
        print(f"eps = {eps:7.0e}: |lambda_2| < 1e-13, at the level of rounding error")
    else:
        print(f"eps = {eps:7.0e}: lambda_2 = {lam2:.2e}   lambda_2 / eps = {lam2 / eps:.4f}")
eps =   1e-02: lambda_2 = 6.64e-03   lambda_2 / eps = 0.6637
eps =   1e-06: lambda_2 = 6.67e-07   lambda_2 / eps = 0.6667
eps =   1e-10: lambda_2 = 6.67e-11   lambda_2 / eps = 0.6667
eps =   1e-14: |lambda_2| < 1e-13, at the level of rounding error
eps =   0e+00: |lambda_2| < 1e-13, at the level of rounding error

For moderate ε\varepsilon, λ2≈23ε\lambda_2 \approx \frac{2}{3}\varepsilon exactly as perturbation theory predicts (the test vector ±1\pm 1 on the two triangles has Rayleigh quotient 4ε6\frac{4\varepsilon}{6}). At ε=10−14\varepsilon = 10^{-14} the connected graph and the disconnected one (ε=0\varepsilon = 0) both report a value at the level of rounding error (its exact digits depend on the machine and the library), and a threshold-based component count can no longer tell them apart.

Test yourself

A graph's Laplacian has eigenvalues 0,0,0,1.5,2,40, 0, 0, 1.5, 2, 4. How many connected components does it have?

  1. 1
  2. 2
  3. 3
  4. 6

In the proof, why does xTLx=0x^{\mathsf{T}} L x = 0 force xx to be constant on each component?

  1. Because LL is invertible
  2. Because it is a sum of nonnegative terms wuv(xu−xv)2w_{uv}(x_u - x_v)^2, each of which must vanish
  3. Because x⊥1x \perp \mathbf{1}
  4. Because LL has zero trace

Which lower bound on λ2\lambda_2 was proved for a connected unweighted graph with diameter δ\delta?

  1. λ2≥1/δ\lambda_2 \ge 1/\delta
  2. λ2≥1/(nδ)\lambda_2 \ge 1/(n\delta)
  3. λ2≥δ/n\lambda_2 \ge \delta/n
  4. λ2≥1/n2\lambda_2 \ge 1/n^2 always

Why is BFS, not eigenvalue counting, the right algorithm for counting components?

  1. Eigenvalues can be negative
  2. BFS is exact and takes O(n+m)O(n + m) time; numerically, a weakly connected graph's λ2\lambda_2 can be indistinguishable from 0
  3. Eigenvalues do not determine components
  4. BFS also computes λ2\lambda_2