TExcelTAD
Home › Spectral Graph Theory & Modern Graph Algorithms › Gaussian Elimination and Schur Complements

Gaussian Elimination and Schur Complements

The most direct way to solve Lx=bLx = b is Gaussian elimination. For Laplacians it has a graph meaning that is both pretty and algorithmically important: eliminating a vertex replaces it by a weighted clique on its neighbours, and the new matrix is again a Laplacian. Eliminating everything except a set of terminals produces the Schur complement, a smaller network that is electrically indistinguishable from the original as seen from the terminals. This lesson develops both, measures fill-in (the reason elimination can be slow), and ends with the idea behind the fastest practical Laplacian solvers: eliminate approximately, keeping the cliques sparse by random sampling.

Eliminating one vertex

Order the vertices so that vv comes first and write

L=(dv−aT−aL−v),au=wuv.L = \begin{pmatrix} d_v & -a^{\mathsf{T}} \\ -a & L_{-v} \end{pmatrix}, \qquad a_u = w_{uv} .

One step of Gaussian elimination (or of Cholesky factorization) subtracts multiples of the first row to clear the first column, leaving the Schur complement

L/v=L−v−aaTdv.L / v = L_{-v} - \frac{a a^{\mathsf{T}}}{d_v} .

Claim. L/vL/v is the Laplacian of the graph obtained by deleting vv and adding, for every pair of neighbours u,u′u, u' of vv, an edge of weight wuvwu′vdv\frac{w_{uv} w_{u'v}}{d_v}.

Proof. L−vL_{-v} is the Laplacian of G−vG - v plus the diagonal matrix diag⁡(a)\operatorname{diag}(a) (each neighbour lost an edge to vv but keeps it in its degree). Then diag⁡(a)−aaTdv\operatorname{diag}(a) - \frac{aa^{\mathsf{T}}}{d_v} has off-diagonal entries −auau′dv-\frac{a_u a_{u'}}{d_v} and diagonal entries au−au2dv=au(dv−au)dv=∑u′≠uauau′dva_u - \frac{a_u^2}{d_v} = \frac{a_u(d_v - a_u)}{d_v} = \sum_{u' \ne u}\frac{a_u a_{u'}}{d_v}, which is exactly the Laplacian of the clique with those weights. □\square

This is the star-mesh transform of circuit theory. For degree 2 it is the series rule (two resistors r1,r2r_1, r_2 become one of r1+r2r_1 + r_2: conductance w1w2w1+w2\frac{w_1w_2}{w_1 + w_2}), and for degree 3 it is the Y-Δ\Delta transform.

python · try it yourself
import numpy as np

def 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

# vertex 0 is a star centre with neighbours 1, 2, 3 (weights 1, 2, 3); edge 1-2 also present
wedges = [(0, 1, 1.0), (0, 2, 2.0), (0, 3, 3.0), (1, 2, 1.0), (3, 4, 1.0)]
L = laplacian(5, wedges)
a = -L[1:, 0]
schur = L[1:, 1:] - np.outer(a, a) / L[0, 0]
d0 = 6.0
mesh = [(1, 2, 1.0 + 1 * 2 / d0), (1, 3, 1 * 3 / d0), (2, 3, 2 * 3 / d0), (3, 4, 1.0)]
expected = laplacian(5, mesh)[1:, 1:]
print("Schur complement after eliminating vertex 0:\n", np.round(schur, 4) + 0.0)
print("equals the Laplacian of the star-mesh graph:", bool(np.allclose(schur, expected)))
print("row sums:", np.round(schur.sum(axis=1), 12) + 0.0)
Schur complement after eliminating vertex 0:
 [[ 1.8333 -1.3333 -0.5     0.    ]
 [-1.3333  2.3333 -1.      0.    ]
 [-0.5    -1.      2.5    -1.    ]
 [ 0.      0.     -1.      1.    ]]
equals the Laplacian of the star-mesh graph: True
row sums: [0. 0. 0. 0.]

Schur complements onto terminals

Eliminating every vertex outside a terminal set FF (in any order; the result does not depend on it) gives

SC⁡(L,F)=LFF−LFC LCC−1 LCF,C=V∖F,\operatorname{SC}(L, F) = L_{FF} - L_{FC}\, L_{CC}^{-1}\, L_{CF}, \qquad C = V \setminus F ,

again a Laplacian, on the vertex set FF. It is the network "seen from FF":

  • Energy. For any potentials yy on FF, yTSC⁡(L,F) y=min⁡z(yz)TL(yz)y^{\mathsf{T}}\operatorname{SC}(L, F)\, y = \min_{z} \begin{pmatrix} y \\ z \end{pmatrix}^{\mathsf{T}} L \begin{pmatrix} y \\ z \end{pmatrix}, attained by the harmonic extension z=−LCC−1LCF yz = -L_{CC}^{-1}L_{CF}\, y.
  • Effective resistances between terminals are the same in SC⁡(L,F)\operatorname{SC}(L, F) as in GG.
  • For F={s,t}F = \{s, t\} the Schur complement is a single edge of conductance 1/Reff(s,t)1/R_{\text{eff}}(s, t).

Schur complements are the backbone of multilevel solvers and of recent dynamic graph algorithms (maintaining approximate Schur complements onto a small terminal set lets one answer resistance and flow queries quickly; Durfee, Gao, Goranci and Peng, 2019).

python · try it yourself
import random
import numpy as np

rng = random.Random(42)
n = 10
edges = [(u, v) for u in range(n) for v in range(u + 1, n) if rng.random() < 0.4]
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
P = np.linalg.pinv(L)
reff = lambda M, s, t: M[s, s] + M[t, t] - 2 * M[s, t]

def schur(L, F):
    C = [v for v in range(len(L)) if v not in F]
    return L[np.ix_(F, F)] - L[np.ix_(F, C)] @ np.linalg.solve(L[np.ix_(C, C)], L[np.ix_(C, F)])

S2 = schur(L, [0, 9])
print(f"{len(edges)} edges; Schur complement onto {{0, 9}}:\n", np.round(S2, 4) + 0.0)
print(f"1 / R_eff(0, 9) = {1 / reff(P, 0, 9):.4f}")

F = [0, 3, 6, 9]
S4 = schur(L, F)
Ps = np.linalg.pinv(S4)
for i, j in [(0, 1), (0, 3), (2, 3)]:
    print(f"R_eff({F[i]},{F[j]}): in G {reff(P, F[i], F[j]):.4f}, in the 4-vertex Schur complement {reff(Ps, i, j):.4f}")

y = np.array([1.0, -0.5, 0.25, 2.0])                   # potentials on the terminals
C = [v for v in range(n) if v not in F]
z = -np.linalg.solve(L[np.ix_(C, C)], L[np.ix_(C, F)] @ y)
full = np.zeros(n); full[F] = y; full[C] = z
print(f"y^T SC y = {float(y @ S4 @ y):.4f}, energy of the harmonic extension = {float(full @ L @ full):.4f}")
20 edges; Schur complement onto {0, 9}:
 [[ 2.1988 -2.1988]
 [-2.1988  2.1988]]
1 / R_eff(0, 9) = 2.1988
R_eff(0,3): in G 0.4607, in the 4-vertex Schur complement 0.4607
R_eff(0,9): in G 0.4548, in the 4-vertex Schur complement 0.4548
R_eff(6,9): in G 0.4659, in the 4-vertex Schur complement 0.4659
y^T SC y = 15.9957, energy of the harmonic extension = 15.9957

Fill-in and elimination orders

Eliminating a vertex of degree kk creates up to (k2)\binom{k}{2} new edges (fill), which later steps must process. The order matters enormously:

  • Trees can be eliminated leaf-first with no fill at all, so Laplacian systems on trees are solved in O(n)O(n) time. Degree-2 vertices also create no new edge beyond the one replacing the path; repeatedly removing degree-1 and degree-2 vertices is a standard preprocessing step in every fast solver.
  • Planar graphs: with nested dissection (George, 1973; Lipton, Rose and Tarjan, 1979), eliminating the two halves before a small separator, the fill is O(nlog⁡n)O(n\log n) and the time O(n1.5)O(n^{1.5}).
  • Expanders: any order produces Ω(n2)\Omega(n^2) fill, because every separator is large. Exact elimination is then cubic.

The program counts the fill on a 10×1010 \times 10 grid for three orders: row by row, the greedy minimum-degree heuristic (eliminate a vertex of currently smallest degree), and nested dissection by recursive middle cuts.

python · try it yourself
import random

def grid(r, c):
    adj = {(i, j): set() for i in range(r) for j in range(c)}
    for i in range(r):
        for j in range(c):
            for di, dj in ((0, 1), (1, 0)):
                if i + di < r and j + dj < c:
                    adj[(i, j)].add((i + di, j + dj)); adj[(i + di, j + dj)].add((i, j))
    return adj

def fill(adj, order):
    adj = {v: set(nb) for v, nb in adj.items()}
    added = 0
    for v in order:
        nbrs = list(adj.pop(v))
        for u in nbrs:
            adj[u].discard(v)
        for i in range(len(nbrs)):
            for j in range(i + 1, len(nbrs)):
                a, b = nbrs[i], nbrs[j]
                if b not in adj[a]:
                    adj[a].add(b); adj[b].add(a); added += 1
    return added

def min_degree_order(adj):
    adj = {v: set(nb) for v, nb in adj.items()}
    order = []
    while adj:
        v = min(adj, key=lambda x: (len(adj[x]), x))
        nbrs = adj.pop(v)
        for u in nbrs:
            adj[u].discard(v)
            adj[u] |= nbrs - {u}
        order.append(v)
    return order

def nested_dissection(cells):
    if len(cells) <= 2:
        return list(cells)
    rows = sorted({i for i, _ in cells}); cols = sorted({j for _, j in cells})
    if len(cols) >= len(rows):
        mid = cols[len(cols) // 2]
        sep = [x for x in cells if x[1] == mid]
        a = [x for x in cells if x[1] < mid]; b = [x for x in cells if x[1] > mid]
    else:
        mid = rows[len(rows) // 2]
        sep = [x for x in cells if x[0] == mid]
        a = [x for x in cells if x[0] < mid]; b = [x for x in cells if x[0] > mid]
    return nested_dissection(a) + nested_dissection(b) + sep    # separator last

k = 10
G = grid(k, k)
orders = {
    "row by row": sorted(G),
    "random": random.Random(3).sample(sorted(G), len(G)),
    "minimum degree": min_degree_order(G),
    "nested dissection": nested_dissection(sorted(G)),
}
print(f"{k} x {k} grid, {sum(len(v) for v in G.values()) // 2} edges")
for name, order in orders.items():
    print(f"  {name:18} fill = {fill(G, order)} new edges")
10 x 10 grid, 180 edges
  row by row         fill = 729 new edges
  random             fill = 952 new edges
  minimum degree     fill = 376 new edges
  nested dissection  fill = 498 new edges

Row-by-row elimination keeps a "front" of about kk vertices that become a clique, so its fill grows like k3=n1.5k^3 = n^{1.5}; a random order is worse still. On a grid this small, minimum degree beats the simple nested dissection; the advantage of nested dissection is asymptotic (O(nlog⁡n)O(n \log n) fill, with a guarantee), and production codes (METIS, the approximate minimum degree ordering AMD) combine both ideas.

In C++

Elimination is also a way to compute an effective resistance without any linear algebra library: eliminate every vertex except ss and tt (minimum degree first), and the single remaining edge has conductance 1/Reff(s,t)1/R_{\text{eff}}(s, t).

cpp · try it yourself
#include <cstdio>
#include <map>
#include <vector>

using Adj = std::vector<std::map<int, double>>;     // neighbour -> conductance

// Eliminate vertex v: connect each pair of its neighbours with weight w_a w_b / d_v (star-mesh).
void eliminate(Adj& g, int v, long& fill) {
    double d = 0;
    for (auto& [u, w] : g[v]) d += w;
    std::vector<std::pair<int, double>> nb(g[v].begin(), g[v].end());
    for (auto& [u, w] : nb) g[u].erase(v);
    for (std::size_t i = 0; i < nb.size(); ++i)
        for (std::size_t j = i + 1; j < nb.size(); ++j) {
            auto [a, wa] = nb[i];
            auto [b, wb] = nb[j];
            if (!g[a].count(b)) ++fill;
            g[a][b] += wa * wb / d;
            g[b][a] += wa * wb / d;
        }
    g[v].clear();
}

int main() {
    const int k = 12, n = k * k;
    Adj g(n);
    auto add = [&](int a, int b) { g[a][b] += 1.0; g[b][a] += 1.0; };
    for (int i = 0; i < k; ++i)
        for (int j = 0; j < k; ++j) {
            if (j + 1 < k) add(i * k + j, i * k + j + 1);
            if (i + 1 < k) add(i * k + j, (i + 1) * k + j);
        }
    const int s = 0, t = n - 1;                      // opposite corners
    std::vector<char> alive(n, 1);
    long fill = 0;
    for (int step = 0; step < n - 2; ++step) {
        int best = -1;
        for (int v = 0; v < n; ++v)
            if (alive[v] && v != s && v != t && (best < 0 || g[v].size() < g[best].size())) best = v;
        eliminate(g, best, fill);
        alive[best] = 0;
    }
    double w = g[s].count(t) ? g[s][t] : 0.0;
    std::printf("%d x %d grid: eliminated %d vertices, fill %ld edges\n", k, k, n - 2, fill);
    std::printf("remaining edge s-t has conductance %.6f, so R_eff(s, t) = %.6f\n", w, 1.0 / w);
}
12 x 12 grid: eliminated 142 vertices, fill 642 edges
remaining edge s-t has conductance 0.308354, so R_eff(s, t) = 3.243023

Approximate elimination

Fill is the enemy, and Kyng and Sachdeva (2016) defeated it with randomness: when a vertex is eliminated, do not add the whole clique on its neighbours; add a random sparse sample of it (about as many edges as the vertex had) whose expectation is the clique. Eliminating vertices in a random order and sampling each clique this way yields an approximate Cholesky factor with O(mlog⁡3n)O(m\log^3 n) nonzeros, which as a preconditioner gives a solver running in O(mlog⁡3nlog⁡(1/ε))O(m\log^3 n\log(1/\varepsilon)) time, simple enough to implement (the Laplacians.jl package does). The analysis uses matrix martingales, the same concentration tools as sparsification.

Test yourself

What does eliminating vertex vv from a Laplacian do to the graph?

  1. Deletes vv and its edges
  2. Deletes vv and joins each pair of its neighbours u,u′u, u' with weight wuvwu′v/dvw_{uv}w_{u'v}/d_v
  3. Contracts vv into its heaviest neighbour
  4. Doubles the weights at vv

What is the Schur complement of LL onto {s,t}\{s, t\}?

  1. The zero matrix
  2. A single edge of conductance 1/Reff(s,t)1/R_{\text{eff}}(s,t)
  3. The submatrix L{s,t}L_{\{s,t\}}
  4. The identity

Why can Laplacian systems on trees be solved in linear time by elimination?

  1. Trees have no edges
  2. Eliminating leaves first creates no fill
  3. Trees are bipartite
  4. Their Laplacian is diagonal

What is the key idea of approximate Gaussian elimination (Kyng and Sachdeva, 2016)?

  1. Skip half the vertices
  2. Replace the clique created by each elimination with a sparse random sample that equals it in expectation
  3. Use floating point with fewer bits
  4. Eliminate only degree-1 vertices