Guest
Sign in to keep your graphs and progress.

Practice book
Graph Theory Through Problems300 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.
Also by the authorGraph Algorithms for Coding Interviews100 solved interview problems with visual explanations and Python solutions.View on AmazonSelect an algorithm and generate steps to begin visualization
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
Select an algorithm and generate steps to begin visualization
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.
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.
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.
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.
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.
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.
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.
Splitting a graph in two can be done exactly for some objectives and only approximately for others.
| Alternative | Prefer it when | Cost |
|---|---|---|
| Minimum cut (Stoer-Wagner) | The fewest edges cut, with no balance requirement. Often cuts off a single vertex. | O(nm + n² log n) |
| Kernighan-Lin | Balanced 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 |
Read the full article: Spectral Graph Theory in ML
Read the full article: Community Detection: Modularity, Louvain, Girvan-Newman
Related algorithms: Louvain Community Detection, Girvan-Newman Communities, Kirchhoff's Matrix-Tree Theorem, Stoer-Wagner Min Cut, Label Propagation