learngraphtheory.org

Guest

Sign in to keep your graphs and progress.

Cover of the book Graph Theory Through Problems

Practice book

Graph Theory Through Problems

300 Exercises with Hints, Worked Algorithms and Complete Solutions

By Mohammed Islam Hadjoudj

Learn graph theory by solving problems: 300 exercises, from routine checks to challenging proofs, each with a complete solution.

Available inKindlePaperback

13 chapters

Also by the authorGraph Algorithms for Coding Interviews100 solved interview problems with visual explanations and Python solutions.View on Amazon
Algorithm Selection

Select an algorithm and generate steps to begin visualization

Spectral Partitioning

Let an eigenvector find the weakest seam

Splits a graph in two by the signs of the Fiedler vector, the Laplacian eigenvector of the second smallest eigenvalue, found here by power iteration

Time: O(m) per iteration
Space: O(n + m)
Use Case: Graph partitioning, spectral clustering, image segmentation, community detection
Showing the example graph for this algorithm.
Algorithm Execution

Select an algorithm and generate steps to begin visualization

About Spectral Partitioning (Fiedler Vector)

Spectral partitioning splits a graph in two using linear algebra. The graph Laplacian L = D − A has the eigenvalue 0 with the constant vector (1, …, 1). Its next eigenvector, for the second smallest eigenvalue λ₂, is the Fiedler vector: the smoothest way to give vertices numbers that are not all equal. Vertices in the same tightly knit group get similar numbers, so cutting at 0 separates two loosely joined parts. λ₂ itself, the algebraic connectivity, is above 0 exactly when the graph is connected.

How it works

The visualizer builds the Laplacian (degrees on the diagonal, −1 for each edge), then finds the Fiedler vector by power iteration. Multiplying by c·I − L, with c at least the largest eigenvalue, reverses the order of the eigenvalues, and removing the (1, …, 1) part every round keeps the iteration away from the trivial eigenvector. Each round costs O(m), and the vector settles at a speed set by the gap between λ₂ and λ₃. Then λ₂ = xᵀLx, and the vertices are split by the sign of their entry. Splitting at 0 approximately minimises the ratio cut, which prefers few cut edges and two parts of similar size.

Applications

Spectral bisection was used to partition meshes for parallel computing (Pothen, Simon and Liou), and the same idea, with several eigenvectors and k-means, is spectral clustering, a standard machine-learning method for data that is not separated by straight lines. It segments images (normalized cuts), finds communities in networks and orders vertices to reduce the bandwidth of sparse matrices. The algebraic connectivity also measures how robust a network is.

Pseudocode

Build the Laplacian, find its Fiedler vector by power iteration, split by sign.

SpectralSplit(G):
    L = D - A                          // degrees minus adjacency
    c = 2 * maximum degree             // at least the largest eigenvalue of L
    x = any vector with sum 0, length 1
    repeat:
        x = c * x - L * x              // power iteration on cI - L
        x = x - mean(x)                // remove the (1, ..., 1) part
        x = x / |x|
    until x stops changing             // x is the Fiedler vector
    lambda2 = x^T L x                  // the algebraic connectivity
    return A = {v : x[v] < 0}, B = {v : x[v] >= 0}

Multiplying by c·I − L turns the smallest eigenvalues of L into the largest ones. The constant vector would win, so it is removed every round, and the iteration settles on the next one, the Fiedler vector.

Worked example, step by step

The split of the ten-vertex example loaded on this page.

Example graph: Two groups of five, A to E and F to J, each with seven edges inside, joined by only two edges: B–F and C–J.

  1. The Laplacian. Degrees on the diagonal, −1 for each of the 16 edges. Each row adds up to 0, which is why (1, …, 1) is an eigenvector with eigenvalue 0.
  2. Start. An irregular starting vector adding up to 0. Its signs are mixed across both groups.
  3. Iterations. Each round multiplies by c·I − L, removes the constant part and rescales. By round 4 the signs already follow the two groups, while the values keep settling.
  4. Settled. After 81 rounds the vector moves by less than 10⁻⁹. λ₂ = 0.500: small, because two edges are enough to cut the graph.
  5. Split. A to E get negative entries (E lowest at −0.45), F to J positive ones. Cutting at 0 removes exactly the two joining edges.

Two parts of 5 vertices with 2 edges cut, ratio cut 2/5 + 2/5 = 0.80: the obvious split, found without looking at the drawing.

Complexity, and where it comes from

Time: O(m) per iteration · Space: O(n + m)

One round multiplies the sparse Laplacian by a vector, O(n + m). The error shrinks each round by the factor (c − λ₃)/(c − λ₂), so the number of rounds depends on the gap between λ₂ and λ₃: a clear two-part structure converges fast. Exact eigen-decomposition with dense methods costs O(n³), and Lanczos methods are the standard choice for large sparse graphs.

When to use Spectral Partitioning (Fiedler Vector), and when not to

Splitting a graph in two can be done exactly for some objectives and only approximately for others.

AlternativePrefer it whenCost
Minimum cut (Stoer-Wagner)The fewest edges cut, with no balance requirement. Often cuts off a single vertex.O(nm + n² log n)
Kernighan-LinBalanced bisection improved by swapping vertex pairs. Often run after a spectral split.O(n² log n) per pass
Spectral clustering (k vectors)More than two groups: k eigenvectors, then k-means on their rows.k eigenvectors plus k-means

Common pitfalls

  • Forgetting to remove the constant vector. Without the deflation, power iteration converges to (1, …, 1), which gives every vertex the same sign and no split.
  • Splitting at 0 when balance matters. The sign split can give parts of very different sizes. Splitting at the median gives two equal halves instead.
  • A disconnected graph. Then λ₂ = 0 and the vector is constant on each piece. The split simply separates the pieces, so check connectivity first.

Frequently asked questions

What is the Fiedler vector?
The eigenvector of the graph Laplacian for its second smallest eigenvalue. It is named after Miroslav Fiedler, who showed in 1973 that λ₂ measures how well connected a graph is.
What is algebraic connectivity?
λ₂, the second smallest Laplacian eigenvalue. It is positive exactly when the graph is connected, and small values mean the graph has a bottleneck.
How is this related to spectral clustering?
Spectral clustering uses the first k eigenvectors instead of one, maps each vertex to a point in k dimensions, and groups the points with k-means.
Why does splitting by sign work?
Among vectors of length 1 with sum 0, the Fiedler vector minimises the sum of squared differences across edges. Vertices joined by many edges therefore get similar values, and the sign change falls where few edges cross.

Related algorithms: Louvain Community Detection, Girvan-Newman Communities, Kirchhoff's Matrix-Tree Theorem, Stoer-Wagner Min Cut, Label Propagation

An example graph: you can change it, or start blank.

Zoom Controls

30%
Nodes: 10
Edges: 16