---
title: Classical Color Refinement Algorithm
url: https://www.emergentmind.com/topics/classical-color-refinement-algorithm
type: topic
---

# Classical Color Refinement Algorithm

The classical Color Refinement algorithm, also known as the 1-dimensional Weisfeiler–Leman (1-WL) procedure or naïve vertex classification, is a combinatorial partition-refinement method designed to distinguish non-isomorphic graphs efficiently, although it does not always uniquely identify isomorphism classes. Given input graphs—often two vertex-colored graphs $G$ and $H$—the algorithm produces successive colorings of their vertices by iteratively refining partitions according to the multisets of neighbor colors. The process continues until the coloring stabilizes, at which point distinct color-histograms of $G$ and $H$ certify that they are non-isomorphic. This algorithm is foundational in both practical graph isomorphism testers and theoretical work linking combinatorial invariants, partition-refinement strategies, and algebraic graph symmetries [1502.01255].

## 1. Formal Algorithmic Framework

The algorithm operates on a simple graph $G=(V,E)$, where $n=|V|$ and $m=|E|$. Initialization typically colors each vertex by its degree, $c^{(0)}(v)=\deg(v)$, or alternatively assigns a uniform color, $c^{(0)}(v)=1$ for all $v$. The iterative refinement step updates the coloring as follows:
$$
c^{(t+1)}(v) = \mathrm{Hash}\big(c^{(t)}(v),\,\{\!\{\,c^{(t)}(u) : u \in N(v)\}\!\}\big),
$$
where $\{\!\{\,\cdot\,\}\!\}$ denotes a multiset and $\mathrm{Hash}$ is a canonical injective mapping. Two vertices share a color at step $t+1$ if and only if their current color and the multiset of neighbor colors coincide.

Refinement proceeds until $c^{(t+1)} = c^{(t)}$, yielding the stable partition $\mathcal{P}_G$ (also called the equitable partition). For color comparison between graphs, the algorithm colors $G+H$ (disjoint union), and outputs “non-iso” if stable color-histograms differ [1502.01255].

## 2. Mathematical Properties and Invariants

Every step in color refinement produces a strictly finer partition unless it already stabilized. The sequence of partitions $\mathcal{P}^{(0)} \succeq \mathcal{P}^{(1)} \succeq \ldots$ converges after at most $n$ iterations, since the number of blocks cannot exceed $n$. For isomorphic graphs, any isomorphism $\varphi:V(G)\to V(H)$ preserves the color at every step: $c^{(t)}(v) = c^{(t)}(\varphi(v))$, ensuring color histograms remain identical during refinement. If stabilization yields different histograms, no isomorphism exists.

The stable partition is equitable: for all color classes $X,Y$, and any $u,v\in X$, $|N(u)\cap Y| = |N(v)\cap Y|$. This invariant is preserved by each refinement, guaranteeing that the final partition is the coarsest stable refinement with respect to neighborhood multiset signatures [1502.01255, 1307.5697].

## 3. Quasilinear-Time Implementation

Naïve implementations may require $\Omega(n^2)$ time per iteration. However, techniques originating with Cardon–Crochemore and Paige–Tarjan leverage partition-refinement data structures and a “smaller half” strategy to ensure optimal performance. Each color class is maintained as a list, and neighbor color counts are tracked for efficient splitting.

Refinement is driven by a work queue containing active color classes. When a class splits, only the smaller half is re-enqueued for further processing. Each vertex and edge participate in splits at most $O(\log n)$ times. Aggregating costs over all iterations yields an overall run time of $O((n+m)\log n)$ [1502.01255, 1509.08251, 1806.05654].

| Implementation Feature           | Key Property                  | Source        |
|----------------------------------|-------------------------------|--------------|
| Partition-refinement structure   | Smaller-half update           | 1509.08251   |
| Neighbor-color counting          | $O(\log n)$ per edge/vertex   | 1806.05654   |
| Canonical output                 | Isomorphic graphs get same coloring | 1509.08251   |

## 4. Amenable and Compact Graph Classes

A graph $G$ is called amenable if color refinement always distinguishes $G$ from any non-isomorphic $H$. The paper [1502.01255] provides a structural characterization: for each cell $X$ of the stable partition, $G[X]$ must be either empty, complete, a matching $mK_2$, the complement of a matching, or the 5-cycle $C_5$. For any two distinct cells $X \neq Y$, $G[X,Y]$ (the bipartite subgraph) must be empty, complete bipartite, a union of stars, or a bipartite complement of these.

Global constraints further restrict the cell graph structure: each anisotropic connected component of the cell graph is a tree with size-monotone cells and at most one heterogeneous cell per component. Examples of amenable graphs include discrete (independently colored) graphs, forests, and unigraphs [1502.01255].

A graph is compact if its fractional automorphism polytope consists only of permutation matrices—that is, all fractional automorphisms are convex combinations of genuine automorphisms. Color refinement’s stable partition induces a block-diagonalization of the automorphism polytope. Every amenable graph is compact, a result proved by structural induction on the cell graph; compactness allows efficient isomorphism testing via linear programming [1502.01255, 1307.5697].

## 5. Connections to Fractional Automorphisms and Linear Programming

Fractional automorphisms of a graph $G$ are doubly stochastic matrices $X$ satisfying $AX=XA$, where $A$ is $G$’s adjacency matrix. The set of such $X$ forms a polytope $S(G)$; permutation matrices correspond to actual graph automorphisms. For stable partitions, the corresponding fractional automorphism is block-diagonal, matching the coarsest equitable partition.

Color refinement computes this partition, which canonically corresponds to an extreme point of $S(G)$ with entries $0$ or $1/|C_i|$, where $C_i$ is a color class. Thus, color refinement is equivalent to identifying minimal fractional automorphisms, with applications in dimension reduction of linear programs and structural analysis of symmetry [1307.5697]. Compact graphs can be isomorphism-tested via a linear program:
$$
\begin{cases}
A_G X = X A_H \\
X \mathbf{1} = \mathbf{1}, \\
X^T \mathbf{1} = \mathbf{1}, \\
X \ge 0
\end{cases}
$$
where integrality of the optimal $X$ certifies isomorphism.

## 6. Limitations, Lower Bounds, and Graph-Theoretic Implications

Color refinement distinguishes many, but not all, non-isomorphic graphs. Regular graphs of the same degree and size, or certain strongly regular graphs, remain indistinguishable. The Tree Theorem asserts that color refinement distinguishes graphs exactly when tree homomorphism counts differ for every tree $T$—if counts coincide for all trees, color refinement cannot separate the graphs [1903.12432].

Worst-case lower bounds for iteration depth are sharp: the stabilization process may require up to $n-1$ rounds for $n$-vertex graphs, a bound that is tight for explicit graph families constructed in [2005.10182, 1407.3175]. The partition-refinement model admits no asymptotically faster color refinement algorithm; every refinement step must process all relevant edges between refining and splitting color classes, incurring a total cost of $\Omega((n+m)\log n)$ [1509.08251].

In machine learning, the number of color refinement rounds bounds the depth required in graph neural network architectures to replicate isomorphism invariants. In finite model theory, the stabilization depth aligns with quantifier depth in two-variable counting logic necessary to distinguish graphs [2005.10182].

## 7. Illustrative Example and Practical Role

For $G$ the path $v_1$-$v_2$-$v_3$-$v_4$, initial coloring by degree gives two classes: endpoints $\{v_1,v_4\}$ and middles $\{v_2,v_3\}$. Subsequent refinement steps update colors by neighborhood multisets; in this case, stabilization results in two color classes, distinguishing the path from structurally different graphs like $C_4$, a four-cycle, where all degrees are equal and refinement does not split the vertices [1502.01255].

Color refinement remains a central routine in graph isomorphism solvers, functioning as a symmetry-breaking preprocessor and yielding invariants suited for both combinatorial and algebraic analysis [1307.5697, 1502.01255]. For amenable graphs and their subclasses, it is a complete invariant. For compactness, its range meets that of linear programming relaxations, linking combinatorics and convex algebraic polytopes. Recognition of amenable (and thus compact) graphs is algorithmically efficient—$O((n+m)\log n)$—although characterizing larger classes remains a P-hard problem [1502.01255].

Source: https://www.emergentmind.com/topics/classical-color-refinement-algorithm