arXiv:2609.17364cs.DSSep 2026

Manuscript Offprint

arXiv:2609.17364

The Classical Weisfeiler-Leman Algorithm Stabilizes in O(n)O(n) Rounds

Simon Döring, Daniel Neuen

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Abstract

The classical Weisfeiler-Leman algorithm (also known as the 2-dimensional Weisfeiler-Leman algorithm) is a simple combinatorial algorithm that was originally designed as a heuristic for the graph isomorphism problem. However, it has also numerous connections to other areas such as algebraic graph theory, logics, proof complexity, combinatorial optimization and machine learning.

We prove that the classical Weisfeiler-Leman algorithm terminates after 5(n−1)5(n-1) iterations. This improves over the previous best upper bound of O(nlog⁡n)O(n \log n) by Lichter, Ponomarenko and Schweitzer [LICS 2019], and asymptotically matches the known lower bound of Ω(n)\Omega(n) by Fürer [ICALP 2001].

Additionally, building on our results for the 2-dimensional case, we obtain an improved upper bound of O(nk−1/(k−2)!+nk−2)O(n^{k-1}/(k-2)! + n^{k-2}) on the number of iterations performed by the k-dimensional Weisfeiler-Leman algorithm, for every k≥3k \geq 3. Our arguments actually hold for a larger class of sequences of colorings of k-tuples; in this larger class our upper bounds are essentially tight for all k≥3k \geq 3.

1 Introduction

The Weisfeiler-Leman (WL) algorithm is a simple combinatorial procedure that iteratively computes a coloring of tuples of vertices in a graph, attempting to assign different colors to tuples that are structurally different. The WL algorithm was originally introduced in its 2-dimensional version (also known as the classical Weisfeiler-Leman algorithm) by Weisfeiler and Leman [61]. For each k≥1k \geq 1, the k-dimensional WL (k-WL) algorithm, independently introduced by Immerman and Lander [34] and Babai and Mathon (see [7] for a historical note), colors k-tuples of vertices of an input graph G. More precisely, initially the k-WL algorithm colors each k-tuple (v1,…,vk)(v_1, \ldots, v_k) of vertices with the isomorphism type of the underlying (ordered) induced subgraph. Afterwards, the coloring is iteratively refined by taking colors of k-tuples into account that differ in only one coordinate.

The most common application of the WL algorithm is in the context of the graph isomorphism problem. Indeed, despite the WL algorithm not being a complete isomorphism test for n-vertex graphs for dimension k=o(n)k = o(n) [13], it is widely used both in practice [1, 35, 36, 47, 48] and theory [26, 29, 38, 54]. The most important versions of the WL algorithm are dimensions 1 and 2. The 1-WL algorithm (also known as Color Refinement or Naive Vertex Refinement) can be implemented in near-linear time (see, e.g., [9]) and is already powerful enough to serve as a complete isomorphism test for almost all graphs [8].

Whereas the 1-dimensional algorithm fails to distinguish between d-regular graphs of equal size, the 2-WL version serves as a complete isomorphism test for almost all regular graphs [12]. Also, the 2-WL algorithm is closely tied to algebraic graph theory via so-called coherent configurations [6, 32], and is expressive enough to capture, e.g., many spectral invariants [19, 56] as well as other graph properties (see, e.g., [2, 41, 42]). For these reasons, the 2-WL algorithm is frequently used as a subroutine for isomorphism testing (see, e.g., [3, 27, 53, 52]) and also forms the basis for extensions such as Deep WL [30].

Higher dimensions of the WL algorithm are often sufficient for a complete isomorphism test on restricted classes of graphs. For example, it is known that 3-WL identifies all planar graphs [43], and more generally, for every class excluding some fixed minor, the k-WL algorithm is a complete isomorphism test for some fixed k [21]. Also, Babai's quasipolynomial-time isomorphism test [7] prominently relies on the k-WL algorithm for dimension k=O(log⁡n)k = O(\log n).

Beyond that, the WL algorithm has surprising connections to several other areas of (theoretical) computer science. For example, the expressive power of k-WL can be characterized via the (k+1)(k+1)-variable fragment Ck+1C^{k+1} of first-order logic with counting quantifiers [34, 13], homomorphism counts from graphs of treewidth at most k [17, 16], and suitable linear programming relaxations [5, 28]. Moreover, the WL algorithm has connections to combinatorial optimization [5, 22, 46], proof complexity [4, 10, 15, 58] and machine learning [50, 51, 57, 62].

Besides the dimension of the WL algorithm, the key parameter is the number of iterations it takes until stabilization (see, e.g., [38, 37]). The k-WL algorithm trivially terminates after nk−1n^k - 1 refinement steps, since the number of different colors of k-tuples increases in each iteration. For the 1-WL algorithm, this trivial upper bound is in fact tight [40], and there are even partial characterizations of those graphs that achieve n−1n - 1 refinement rounds [39]. In contrast, for k=2k = 2, the first non-trivial upper bound of O(n2/log⁡n)O(n^2 / \log n) was given by Kiefer and Schweitzer [44]. This bound was improved by Lichter, Ponomarenko and Schweitzer to O(nlog⁡n)O(n \log n) [45]. On the other hand, the best known lower bound due to Fürer [18] is Ω(n)\Omega(n). As the first main result of this work, we close the gap between upper and lower bound for the iteration number of the classical Weisfeiler-Leman algorithm (up to a constant factor).

Main Theorem 1. The 2-WL algorithm stabilizes after at most 5(n−1)5(n-1) iterations, where n denotes the number of vertices.

We note that our arguments are not limited to the 2-WL algorithm. Indeed, as a conceptual contribution, we introduce the notion of a multiplicative 2-refinement sequence χ=(χ0,…,χr)\boldsymbol{\chi} = (\chi_0, \ldots, \chi_r), where χi:V2→C\chi_i: V^2 \to C is a coloring of pairs (over some universe VV of size nn) for all i∈{0,…,r}i \in \{0, \ldots, r\}. As our main technical result, we show that every multiplicative 2-refinement sequence χ=(χ0,…,χr)\boldsymbol{\chi} = (\chi_0, \ldots, \chi_r) has length r≤5(n−1)r \leq 5(n-1). Since the sequence of colorings produced by the iterative refinement process of 2-WL is a multiplicative 2-refinement sequence, the above theorem follows.

We stress that Main Theorem 1 is not only relevant to the Weisfeiler-Leman algorithm itself, but has several corollaries via the characterizations mentioned above. To give just one example, the iteration number of k-WL precisely corresponds to the quantifier depth in the corresponding logic Ck+1\mathsf{C}^{k+1} (see, e.g., [37]). Exploiting this connection, Main Theorem 1 implies that every property expressible in C3\mathsf{C}^3 on graphs with nn vertices can also be expressed using only quantifier depth 5(n−1)5(n-1).

Building on our results for k=2k = 2, we also obtain improved bounds for all k≥3k \geq 3. For k≥3k \geq 3, the best known upper bound on the iteration number of kk-WL has been O(knk−1log⁡n)O(kn^{k-1} \log n) [24]. On the other hand, the currently best known lower bound is Ωk(nk/2)\Omega_k(n^{k/2}) [25] (which improves over previous lower bounds from [11, 24]). As our second main result, we improve the upper bound for all k≥3k \geq 3.

Main Theorem 2. For every k≥3k \geq 3, the k-WL algorithm stabilizes after O(nk−1(k−2)!+nk−2)O\left(\frac{n^{k-1}}{(k-2)!} + n^{k-2}\right) iterations, where n denotes the number of vertices.

Note that our upper bounds also significantly improve on the dependence on k. This is particularly relevant when k depends on n (e.g., this is the case in Babai's quasipolynomial-time isomorphism test which uses k=O(log⁡n)k = O(\log n)). While the improvement on the dependence on n is minor, let us stress that we view our main contribution to be on the technical side. Indeed, to obtain the upper bound of O(knk−1log⁡n)O(kn^{k-1} \log n), [24] relies on an involved argument via certain matrix tensors obtained from colorings produced by k-WL. In contrast, our upper bound follows from a rather straight-forward application of our results for the case k=2k = 2. Indeed, generalizing the case k=2k = 2, we introduce the notion of an extendable multiplicative kk-refinement sequence χ=(χ0,…,χr)\boldsymbol{\chi} = (\chi_0, \ldots, \chi_r), where χi:Vk→C\chi_i: V^k \to C is a coloring of kk-tuples (over some universe VV of size nn) for all i∈{0,…,r}i \in \{0, \ldots, r\}. For such sequences, we can derive an upper bound on rr from the corresponding result for k=2k = 2 essentially by considering suitable projections of the colorings χi\chi_i. This argument is significantly simpler and more direct than the arguments used in [24]. Also, it implies that any further improvement for the case k=2k = 2 (e.g., on the constant factor) directly translates to an improvement for higher dimensions.

On top of that, for the notion of extendable multiplicative k-refinement sequences, it turns out that our upper bounds are essentially optimal. Indeed, a construction from [24] gives extendable multiplicative k-refinement sequences 1^{1} of length nk−1/kΩ(k)n^{k-1}/k^{\Omega(k)}. Hence, our upper bounds are not only optimal in terms of n, but even essentially optimal in terms of k.

Related Work. There is a significant body of work on the relation between dimension and iteration number of the WL algorithm. For example, Grohe and Verbitsky [31] proved that O(log⁡n)O(\log n) rounds of k-WL can be implemented in TC1TC^{1}. For many classes of graphs, such as planar graphs [60, 23] or graphs of bounded treewidth [31], it turns out that O(log⁡n)O(\log n) rounds of k-WL, for some constant k, are sufficient to obtain a complete isomorphism test. In particular, this implies that isomorphism testing for the corresponding classes of graphs is in TC1TC^{1}. Additionally, there are connections to descriptive complexity theory [59]. Moreover, there has also been a series of results of this flavor in the context of the group isomorphism problem; see, e.g., [20].

References (56)