Manuscript Offprint
arXiv:2608.25212Time-Optimal APSP and Matrix Multiplication in Classes of Linear Neighborhood Complexity
Abstract
The notion of linear neighborhood complexity is a very general structural assumption on a graph class, covering most classes of sparse graphs such as planar graphs, graphs excluding a fixed (topological) minor, or bounded expansion graphs, as well as many structured classes of dense graphs, such as graphs of bounded clique-width, twin-width, merge-width, or flip-width.
In this work, we present -time optimal algorithms for -vertex graphs coming from a class of linear neighborhood complexity for the following problems:
• ALL-PAIRS SHORTEST PATHS,
- the multiplication of the adjacency matrix M of the input graph with any matrix. More specifically, after a quadratic preprocessing, we can multiply M with any n-vector in time.
This solves several questions raised in [Bonnet, Kim, Geniet, Moon; ICALP '26], and improves and generalizes results in several other recent papers [Bonnet, Giocanti, Ossona de Mendez, Thomassé; STACS '23], [Bannach, Marwitz, Tantau; STACS '24], [Anand, van den Brand, McCarty; NeurIPS '26], [Kozma, Opler '26], and [Cardinal, McCarty, Yuditsky '26]. We also extend our results to classes of bounded VC density.
In classes of linear neighborhood complexity, we also give a triangle-detection algorithm in randomized linear time in -vertex -edge graphs, a -detection algorithm in randomized or deterministic time, and a -detection algorithm in randomized time.
*CNRS, ENS de Lyon, Université Claude Bernard Lyon 1, LIP UMR 5668, 69342 Lyon, France. Homepage: http://perso.ens-lyon.fr/edouard.bonnet. Email: edouard.bonnet@ens-lyon.fr.
Institute of Informatics, University of Warsaw, Poland. Email: j.duron@uw.edu.pl
Institute of Informatics, University of Warsaw, Poland. Homepage: https://www.mimuw.edu.pl/~malcin/. Email: m.pilipczuk@uw.edu.pl.
Max Planck Institute for Informatics, Saarland Informatics Campus, Saarbrücken, Germany. Homepage: https://mnbvmar.github.io. Supported by the Deutsche Forschungsgemeinschaft (DFG, German Research Foundation) grant number 559177164. Email: msokolow@mpi-inf.mpg.de.
Institute of Informatics, University of Warsaw, Poland. Homepage: https://www.mimuw.edu.pl/~szymtor/. Email:szymtor@uw.edu.pl.
Contents
1 Introduction 1
1.1 Our results 2
2 Preliminaries 5
2.1 Neighborhood complexity 5
2.2 Symmetric difference and sd-degeneracy 5
2.3 Signed tree models and interval biclique partitions 6
2.4 Matrix multiplication 7
3 Finding an sd-degeneracy sequence deterministically 7
4 SSSP in graphs given with an interval biclique partition 9
4.1 Interval intersections data structure 11
5 Wrap-up of the algorithmic corollaries 14
6 Finding an sd-degeneracy sequence in randomized linear time 15
7 Finding Small Patterns 19
A Neighborhood complexity and versatile symmetric difference 28
Classic studies of structured graph classes tackle topologically constrained graphs such as planar graphs, or, more generally, graph classes excluding a minor [40]. This is probably the limit of improved tractability for some algorithmic problems, e.g., network design problems, where topological restrictions on the input graph seem necessary. However, for problems that treat unweighted graphs and interactions between vertices only within a bounded distance, we expect to find efficient algorithms in more general graph classes. Problems of this type include NP-hard problems such as MINIMUM DOMINATING SET or MAXIMUM INDEPENDENT SET (where one can hope for approximation or parameterized algorithms that are believed to be impossible for general graphs) and polynomial-time solvable problems such as multiple shortest path computations (where one can hope to beat known lower bounds that hold in general graphs).
Two decades ago, Nešetril and Ossona de Mendez [43, 44, 45, 46] initiated the study of bounded expansion and nowhere dense graph classes. Subsequent research confirmed that the latter are the limit of tractability of first-order model checking (a meta-problem capturing most problems that concern bounded-distance interactions between vertices) among subgraph-closed graph classes [30]. However, the assumption of being subgraph-closed does not allow this theory to capture dense structured graph classes. In attempts to understand the limit of tractability of first-order model checking on graphs in full generality, width parameters twin-width [16], flip-width [48], and merge-width [24] were introduced. Boundedness of the last two is conjectured to be equivalent; furthermore, tractability of the first-order model checking problem in hereditary graph classes is conjectured to be delimited by the slightly more general notions of almost bounded flip-width or almost bounded merge-width [24]. Research on algorithms for classes of bounded twin-width/merge-width/flip-width includes not only parameterized algorithms for first-order model checking [16, 28, 24], but also parameterized algorithms for specific problems [13, 14, 29, 4], approximation algorithms [13, 7, 22], polynomial kernels [15], and polynomial-time algorithms [13, 37, 31, 12, 23].
However, most of the above-mentioned algorithms require a witness of low twin-width or merge-width to be given as part of the input. The existence of polynomial-time or parameterized algorithms providing appropriate witnesses remains a central open question in the area.
First-order formulas are able to speak about any fixed distance between vertices, but some problems are concerned only with direct adjacencies. This makes them potentially efficiently solvable on even larger classes of graphs. A promising concept in this direction is the notion of linear neighborhood complexity [27]. We say that a graph class has linear neighborhood complexity if there exists a constant such that for every and the number of neighborhood traces on , i.e., , is at most . We also say that has VC density if there exists a constant such that for every and , .
Linear neighborhood complexity not only covers all classes of bounded twin-width, flip-width, and merge-width but also, for example, classes with bounded weak 2-coloring number, such as the class of 2-subdivisions of all graphs. An even more general notion—extending graph degeneracy to the dense setting—is bounded symmetric-difference degeneracy (sd-degeneracy) [11]. For a graph G, it is the least number c such that G can be reduced into a single vertex by iteratively finding two distinct vertices u, v with and removing one of them from the graph. (This notion of a decomposition is called an sd-degeneracy sequence. See Section 2 for precise definitions.) We refer to Fig. 1 for an overview of the properties of graph classes mentioned here.
The first algorithmic applications of the linear neighborhood complexity assumption stem from

Figure 1: Properties of hereditary graph classes and implications among them.

Figure 2: Diagram of the algorithmic pipeline.
the seminal work of Welzl [49], which implies that for a given -vertex graph from such a class, one can order its vertices in polynomial time so that every neighborhood is a union of many intervals. The runtime was improved to in very recent work with intervals for each vertex [23] instead of . Prior works [19, 25] achieve intervals on average per vertex in the same running time. In turn, such a representation can be transformed into an sd-degeneracy sequence of width [12].
Furthermore, [11] introduced a representation of the edge set of the graph, called a signed tree model. A signed tree model of a graph G is a binary tree with leaves labeled with and additional transversal edges which can be positive or negative, and which fully determine the adjacency in G (see Section 2 for a precise definition). Subsequent work [12] transformed signed tree models into interval biclique partitions, first defined in [13]. An interval biclique partition into b bicliques of a graph G is a labeling of with together with a partition of into b bicliques whose sides are intervals of . By pipelining the results of [12, 11], we can first turn an sd-degeneracy sequence of width d into a signed tree model with transversal pairs in time, and then into an interval biclique partition with bicliques in time.
While sd-degeneracy sequences, sparse signed tree models, and interval biclique partitions are relatively simple and often efficiently computable, they bypass the need for involved decomposition notions in classes of bounded twin-width/merge-width/flip-width, when the problem at hand lends itself to their algorithmic uses.
1.1 Our results
Our first contributions are two time-optimal algorithms for computing sd-degeneracy sequences of bounded width in classes of linear neighborhood complexity.
Theorem 1. For every graph class C of linear neighborhood complexity, there is an -time algorithm that, given an n-vertex graph , outputs an sd-degeneracy sequence of G of width .
Note that the running time of Theorem 1 is optimal for graphs with edges. This resolves an open problem of [12]. For graphs with a subquadratic number of edges, we provide a linear-time randomized algorithm.
Theorem 2. For every graph class C of linear neighborhood complexity, there is a randomized algorithm that, given a graph , outputs an sd-degeneracy sequence of G of width in expected time .
Previously available algorithms would either proceed by naively constructing an sd-degeneracy sequence of width , which takes time using a direct implementation (or after realizing that has bounded versatile symmetric difference, see definition below), or by following Welzl's approach, which currently yields an sd-degeneracy sequence of width in time [23, 12], where and .
To prove Theorem 1, we introduce the notion of bounded versatile symmetric difference, where we require that every induced subgraph with vertices contains disjoint vertex pairs satisfying for some constant .
On one hand, a simple application of Haussler’s packing lemma (cf. Theorem 33) proves that linear neighborhood complexity implies bounded versatile symmetric difference. On the other hand, we show how to use the “versatility” strengthening, together with a known data structure for longest common extension of [39], to compute sd-degeneracy sequences in time.
We will actually prove generalizations of Theorems 1 and 2 to classes of VC density .
Theorem 3. For every real number and every graph class of VC density , there is an -time algorithm that, given an n-vertex graph , outputs an sd-degeneracy sequence of G of width .
Theorem 4. For every real number and every graph class of VC density , there is a randomized algorithm that, given a graph , outputs an sd-degeneracy sequence of G of width in expected time .
With the aforementioned results of [12, 11], Theorem 1 allows us to compute in time a signed tree model with transversal pairs and an interval biclique partition with bicliques. Our second contribution is an efficient algorithm using the latter for shortest-path computation.
Theorem 5. There is an -time algorithm that, given an interval biclique partition of an n-vertex graph G with b bicliques and , outputs a shortest-path tree from vertex s in G.
Note that the running time of Theorem 5 is independent of m, the number of edges of G, and in fact is usually sublinear in m. Theorem 5 bypasses the use of the DAG-compression technique [5], which is a way to solve shortest-path problems from interval biclique partitions that incurs, in the current state of knowledge, extra superconstant factors.
By applying Theorem 5 to every vertex of the graph and pipelining it with Theorem 1 and the aforementioned results of [12, 11], we obtain a time-optimal algorithm for ALL-PAIRS SHORTEST PATH (APSP for short) in classes of linear neighborhood complexity.
Theorem 6. For every graph class C of linear neighborhood complexity, ALL-PAIRS SHORTEST PATH can be solved in time on n-vertex graphs of C.
Previous work on APSP includes an -time algorithm in classes of bounded twin-width, and in time on graphs of bounded radius-1 merge-width given with a witness [12]. More recently, the -time APSP algorithm was extended to classes of linear neighborhood complexity [18]. In [13], an -time APSP algorithm was given on graphs of bounded twin-width given with their contraction sequence, which was then improved to -time in the paper introducing DAG-compressions [5].
Note that Theorems 2 and 5, together with [12, 11], also give a randomized -time algorithm for MULTI-SOURCE SHORTEST PATH from k sources on n-vertex m-edge graphs. Another consequence of Theorem 1 and results in [12] (see Lemma 14) is:
Theorem 7. For every graph class C of linear neighborhood complexity, there is an -time algorithm that, given any adjacency matrix M of an n-vertex graph of C, yields a data structure that computes the matrix-vector product MX in time for any n-vector X.
In particular, the product MN can be computed in time for any matrix N.
We refer to Fig. 2 for a diagram of the algorithmic pipeline discussed in the previous few paragraphs.
Theorem 6 answers [12, Question 2] positively, far beyond classes of bounded twin-width (for which the question was asked). Theorems 6 and 7 improve APSP and matrix-multiplication algorithms in [14, 2, 12, 35, 18], all of which have extra polylog factors, and extend results in [36, 5], which work on graphs of bounded clique-width and on graphs of bounded twin-width given with contraction sequences, respectively.
By using Theorem 3 rather than Theorem 1, one can solve ALL-PAIRS SHORTEST PATH in graphs of VC density (or multiply the adjacency matrix of graphs of VC density with any matrix) in time . However, we observe that fast matrix multiplication and Seidel's algorithm [47] have a better running time in general instances as soon as .
We also obtain a time-optimal triangle-detection algorithm in classes of linear neighborhood complexity, which leverages an sd-degeneracy sequence of constant width.
Theorem 8. For every graph class C of linear neighborhood complexity, TRIANGLE DETECTION can be solved in expected time on n-vertex m-edge graphs of C.
Let us recall that on general graphs, the fastest known TRIANGLE DETECTION algorithm runs in time [1] where is the exponent of square matrix multiplication, which currently implies time.
Utilizing both an sd-degeneracy sequence and a Welzl order of the input graph, we obtain randomized almost-linear algorithms for finding 4-vertex and 5-vertex cliques, and a deterministic -time algorithm for detection (time-optimal within dense graphs).
Theorem 9. For every graph class C of linear neighborhood complexity, a subgraph can be found in expected or in deterministic time on n-vertex m-edge graphs of C.
Theorem 10. For every graph class C of linear neighborhood complexity, a subgraph can be found in expected time on n-vertex m-edge graphs of C.
Prior to our work, no linear-time algorithm was known for TRIANGLE DETECTION in the much more restricted classes of bounded clique-width, nor was an almost-linear algorithm known in classes of bounded twin-width (where, for both, the input is a mere graph without a witness of low width).
2 Preliminaries
We index the word positions from 1. In particular, for every word of length . We let denote the base-2 logarithm of . For integers , let be the integer interval spanning all values from to , inclusively, and for integer , let . Graphs are simple (without loops or parallel edges), undirected, and finite. For a graph , we denote its vertex- and edge-set as and , respectively.
2.1 Neighborhood complexity
For a graph G, let be the maximum number of distinct neighborhoods of vertices in G restricted to a set of at most m vertices, i.e.,
We say that has -linear neighborhood complexity (or -LNC) if for all positive . Class has linear neighborhood complexity if there exists a constant such that all graphs have -LNC. We say that has density if there exists a constant such that for all , for all positive . Finally, we say that has -polynomial neighborhood complexity (or -PNC) if for all positive .
2.2 Symmetric difference and sd-degeneracy
In this paper, we define the symmetric difference of two vertices u, v in a graph G as
where denotes the symmetric difference of two sets: . There are slight variations in defining the symmetric difference of (depending on whether or not themselves count), but they only differ by a constant additive term. We say that two distinct vertices are -near-twins in if , and are twins if .
The symmetric difference of a graph G is the least nonnegative integer d such that for every induced subgraph H of G with at least two vertices, there are two d-near-twins in H.
An sd-degeneracy sequence of an n-vertex graph G is a list of pairs of vertices of G such that
• for every ,
• , and
• there is no such that .
Informally, it is an elimination sequence where only the first element of the pair is removed at each step. The width of the sd-degeneracy sequence is defined as
The sd-degeneracy of G (where 'sd' stands for symmetric difference) is the least integer d such that G admits an sd-degeneracy sequence of width d.
Equivalently, the class of graphs of sd-degeneracy at most can be defined by induction on the number of vertices: a graph has sd-degeneracy at most if either , or there is a pair of distinct vertices such that and the graph has sd-degeneracy at most .
We say that a hereditary graph class has bounded versatile symmetric difference if there is an integer such that for every -vertex graph , there are at least disjoint pairs of vertices satisfying . For , we say that has versatile symmetric difference of exponent if there is a constant such that for every -vertex graph , there are disjoint pairs of vertices in satisfying . Thus versatile symmetric difference of exponent coincides with bounded versatile symmetric difference.
2.3 Signed tree models and interval biclique partitions
We recall the definition of signed tree models for the sake of self-containedness. However, we will not use them in the rest of the paper. Thus, from this subsection, one can only read the definition of interval biclique partitions (given just after Lemma 11) and Lemma 13.
Signed tree models, originally defined in [11], generalize the tree models introduced in the context of twin-width [17, 13]. In a rooted tree and , by we denote that is an ancestor of . A pair of vertices of a rooted tree is a transversal pair of if it is not between an ancestor and descendant. We say that two transversal pairs and cross if one of is a strict ancestor of one of , and conversely, one of is a strict ancestor of one of .
A full binary tree is a rooted binary tree where every internal node has exactly two children. A signed tree model is a triple where is a full binary tree, and are two disjoint sets of transversal pairs of , and does not contain any crossing pair. The transversal pairs of and are called negative edges and positive edges, respectively.
We say that a transversal pair covers the pair if and and there is no transversal pair in with and . We denote by the set of leaves of . The graph represented by the signed tree model has vertex set , and are adjacent in if and only if the pair is covered by a positive transversal pair in .

Figure 3: A signed tree model of a 14-vertex graph, with A in amber and B in blue. The topmost amber edge and the dashed red edge cross (which is not in ). Vertex 8 is adjacent to 4 because 4,8 is covered by the positive edge , and to 2 because 2,8 is covered by the positive edge , but 8 is not adjacent to 7 because 7,8 is covered by the negative edge .
A graph class has sparse signed tree models if there is a constant such that every admits a signed tree model with . There is an efficient algorithm that turns sd-degeneracy sequences of bounded width into sparse signed tree models.
Lemma 11 (Lemma 18 of [12], Lemma 3.1 of [11]). There is an -time algorithm that, given an sd-degeneracy sequence of an n-vertex m-edge graph G of width d, outputs a signed tree model of G with transversal pairs.
Assume that the graph G comes with a total ordering of its vertices; for convenience, assume that the vertex set of G is [n], ordered naturally. We then define the interval biclique partition of G as the partitioning of the edge set of G into bicliques, where each side of each biclique is an integer subinterval of [n]. The following lemma implies that a small-size signed tree model can be efficiently turned into a small-size interval biclique partition.
Lemma 12 (Item 1 of Theorem 1 of [12]). There is an -time algorithm that, given a signed tree model of an n-vertex graph G with p transversal pairs, outputs an interval biclique partition of G with bicliques.
We will rely on the following consequence of Lemmas 11 and 12.
Lemma 13. There is an -time algorithm that, given an sd-degeneracy sequence of an n-vertex m-edge graph G of width d, outputs an interval biclique partition of G with bicliques.
2.4 Matrix multiplication
An interval biclique partition with bicliques of an n-vertex graph G allows one to multiply any adjacency matrix of G with any n-vector in time. More precisely:
Lemma 14 (Theorem 33 in [12]). For every abelian group A, there exists an algorithm that takes on input an interval biclique partition with b bicliques of an n-vertex graph G with adjacency matrix M and an n-vector and computes the product MX, in time and group operations.
Note that, as the adjacency matrix is a -matrix, the multiplication of with a vector of group elements is well-defined. This lemma has a short proof that encodes into an -matrix with nonzero entries. As a direct consequence of Lemma 14, one can multiply with any matrix in time (assuming the group operations take constant time).
3 Finding an sd-degeneracy sequence deterministically
In this section, we provide an algorithm that computes an sd-degeneracy sequence of constant width in graphs of bounded versatile symmetric difference. The algorithm is time-optimal for dense graphs (i.e., n-vertex graphs with edges). More generally, the algorithm computes an sd-degeneracy sequence of width in graphs of versatile symmetric difference of exponent .
It uses classic data structures for strings. Given a word of finite length , a longest common extension (LCE) query asks for the largest integer such that .
Theorem 15 (Section 4 of [39]). Fix a finite alphabet . There is an -time algorithm, that given a word of length over , builds a data structure that answers each LCE query on in constant time.
Theorem 15 is originally shown by reduction to least common ancestor (LCA) in the suffix tree. To avoid computing the suffix tree, one can alternatively go through suffix array, longest common prefix (LCP) array, and range minimum query (RMQ). See [6] for a simple proof of optimal LCA and RMQ data structures.
Theorem 15 yields a surprisingly fast check for d-near-twinness in graphs.
Theorem 16. There is an -time algorithm that, given an n-vertex graph , builds a data structure that given a query reports if in time.
Proof. We build a binary word of length by concatenating the adjacency vectors of all vertices. Formally, assuming , for every if and otherwise. The word can easily be built in time.
By Theorem 15, we build, in time, a data structure that answers each LCE query on in constant time. Given a query , we proceed as follows. We initialize and .
While and , we feed with the query , . (Note that, for , those are the positions where the adjacency vectors of and , respectively, start.) Let be the query answer, found in constant time. If , we decrement by 1 and set , else we exit the while loop.
When we exit the while loop, if , we report that , and otherwise that .
Time. We have already checked that is built in time. Note that each query makes at most LCE queries. Indeed, in the end of the while loop, we decrement (initially set to ) by 1 or we exit the loop, whereas continuing looping requires that is nonnegative. Hence a query is met in time .
Correctness. Let be the successive values is set to. In particular, . The following properties hold:
•
• for every , ;
- for every , if then there exists such that .
The main invariant is that there are exactly vertices with label smaller than adjacent to exactly one of . As we check both if more than such positions where found () and if the current position overflows to the next adjacency vectors (), we correctly decide whether or not holds when exiting the while loop.
In particular, we can list all pairs of d-near-twins in quadratic time, when d is constant.
Corollary 17. There is an -time algorithm that, given an n-vertex graph and a positive integer , lists all the pairs of vertices such that .
Proof. We compute in time the data structure of Theorem 16. For every with , we present with the query . If the answer is positive ( ), we add to the output pairs. Overall, this takes time.
We obtain the objective of this section by repeatedly applying Corollary 17.
Theorem 18. Let C be a (hereditary) class of versatile symmetric difference of exponent . There is an -time algorithm that, given an n-vertex graph of C, outputs an sd-degeneracy sequence of G of width .
Proof. Let be such that for every -vertex graph , there are disjoint pairs of vertices satisfying . We initialize an sd-degeneracy sequence of of width to the empty list. We also set and .
While the remaining graph has vertices, we do the following.
By Corollary 17, we list all the pairs of -near-twins of in time. We then greedily build a list of disjoint pairs of -near-twins of in time. (Indeed, if one fixes a set disjoint pairs, then the choice of any other pair consumes at most two pairs of .) We append this list to . We then set and . This finishes the body of the while loop.
When we exit the while loop, we finish the sd-degeneracy sequence arbitrarily.
Correctness. If the algorithm terminates, it does output an sd-degeneracy sequence of G of width since we only append to S pairs of -near-twins in the current graph, and remove their first elements in batches of disjoint pairs.
Time. At every loop iteration, we add at least one pair to the sequence and remove their first elements from the graph. Thus, the algorithm does terminate, and goes through the successive induced subgraphs of with . Let .
Claim 19. For every , .
Proof. Indeed, if , then since (we remove at least one vertex of to form ). If instead, , we conclude because .
By Claim 19, for every , . So the overall running time is
and we conclude.
Theorem 3 is then a consequence of Theorems 18 and 33. For classes of bounded versatile symmetric difference (exponent 0), we get the following corollary (which, by Theorem 33, implies Theorem 1).
Corollary 20. Let C be a (hereditary) class of bounded versatile symmetric difference. There is an -time algorithm that, given an n-vertex graph of C, outputs an sd-degeneracy sequence of G of width .
4 SSSP in graphs given with an interval biclique partition
In this section we prove Theorem 5, which for convenience we recall below.
Theorem 5. There is an -time algorithm that, given an interval biclique partition of an n-vertex graph with bicliques and , outputs a shortest-path tree from vertex in .
We begin by introducing a data structure problem for reporting interval intersections, called INTERVAL-INTERSECT, and we show how to solve this problem in total linear time. In INTERVAL-INTERSECT, we are given as input a unary-encoded integer (the universe size) and a finite set of labels, where every label is assigned an integer interval . Initially, all labels are active. The data structure is required to answer the following online queries: given an integer interval , report all active labels with the corresponding intervals intersecting , and deactivate all reported labels.
Subsequently, we will use the resulting data structure to show the linear-time algorithm for Theorem 5. In Section 4.1, we prove the following.
Lemma 21. There exists a data structure for INTERVAL-INTERSECT in the word RAM model of computation that processes an instance with universe size N, set of labels A, and q queries in time.
The purpose of encoding N in unary is to ensure that every element of the universe [N] fits within a single RAM word; hence we can assume where is the size of the machine word.
We show now to use Lemma 21 to solve SSSP in linear time in graphs with a given interval biclique partition, namely, we prove Theorem 5.
Proof of Theorem 5. Recall that is the vertex set of the graph, and let the ith biclique in the edge partition have sides and ; each and is a subinterval of .
In the beginning, we set up two instances of the linear-time data structure for INTERVAL-INTERSECT, both with universe :
• , with labels from , where the label is assigned the interval ;
- , with labels , with the interval assigned to and the interval assigned to .
The active items in are the vertices undiscovered by the run of the breadth-first search (BFS); hence, we initially query with , where is the source of the BFS, to deactivate the label . On the other hand, the active items in represent the sides of the bicliques that do not contain vertices visited by BFS.
We perform the usual BFS in , with the usual queue holding the vertices discovered by the search (initially only ) that are yet to be visited. When a vertex is visited by the search, we find the yet undiscovered neighbors of as follows. We first use to enumerate the not yet processed sides of the bicliques by querying for the interval . Suppose returns (resp., ) as one of the labels; then, we have that (resp., ). In this case, all vertices in (resp., ) should become discovered if not yet discovered. In order to ensure that, we query with the interval (resp., ), and enqueue all vertices returned as a result of the query, marking as the parent of each of them. We repeat this process for each label reported by .
The correctness of the algorithm is clear as it is simply a breadth-first search with a bespoke method for listing the yet undiscovered neighbors. To see the efficiency, observe that we issue at most n queries to , and it reports at most labels throughout the entire run of SSSP. Thus, at most queries to are issued. Hence both data structures for INTERVAL-INTERSECT process all respective queries in total time. Moreover, it is clear that outside of the queries, the SSSP implementation above takes time linear in the size of the input; the claim follows.
4.1 Interval intersections data structure
It remains to prove Lemma 21.
Our approach resembles the tabulation technique and the method of Four Russians, commonly used in algorithm design in the word RAM model of computation; see e.g. [3, 26, 8, 6]. Namely, we first show a data structure with a worse complexity guarantee (Lemma 22). Using Lemma 22, we then show how to bootstrap a linear-time data structure for universes of size , given access to a linear-time data structure for universes of size (Lemma 23). Next, in the word RAM model, we give a linear-time data structure for universes of size , assuming -time prior preprocessing (Lemma 24). Applying Lemma 23 twice to Lemma 24 implies Lemma 21. We implement this strategy below.
Lemma 22 (Quasi-linear interval intersections). There exists a data structure for INTERVAL-INTERSECT that processes an instance with universe size N, set of labels A, and q queries in time.
Proof. On initialization, we build an auxiliary directed graph with vertices and arcs, as follows. Let . For integer , let the th interval layer comprise all integer intervals . For every such and every interval , we introduce two vertices: an outvertex and an invertex . For every , we also introduce a vertex .
We construct arcs in as follows. Every with is a disjoint union of two integer intervals ; add arcs (so that arcs between outvertices are directed toward lower-indexed layers) and arcs (so arcs between invertices are oriented toward higher-indexed layers). Also, for every , add an arc . It is easy to verify that now, for every and , there is a path from to if and only if ; and by the same token, there is a path from to if and only if . It follows that for an outvertex and an invertex , a path from to exists if and only if the intervals and intersect. Finally, for every with the corresponding interval , write as a (not necessarily disjoint) union of two intervals for some (where possibly ). Then add arcs . This guarantees that for any outvertex , a path from to in exists if and only if and intersect. See Fig. 4.
Apart from the graph , we also initialize a visited bit for each , initially unset. Then consider a query . As above, write as a union of two intervals for some . Then perform two graph searches in from the outvertices , visiting only previously unvisited vertices of , and marking these vertices as visited. For each newly visited vertex , we report as the label corresponding to the interval intersecting .
The correctness of the data structure is clear. For the efficiency of the data structure, observe that has size and can be constructed in time proportional to its size. Then, each of the queries spawns at most two graph searches in that only visit previously unvisited vertices. Therefore, all queries are processed in total time , as required.
We then show how to use Lemma 22 to bootstrap a data structure for tiny universes to handle an exponentially larger universe. In the next lemma, b is the size of the machine word.
Lemma 23 (Bootstrapping for interval intersections). Let be an integer. Suppose there exists a data structure for INTERVAL-INTERSECT that processes instances with universe of size , set of labels A, and q queries in time. Then there exists a data structure for INTERVAL-INTERSECT that processes instances with universe of size , the set of labels A, and q queries in time.
outvertices

Figure 4: The graph with and a single interval . There is a directed path from to . Note that, on the contrary, one cannot reach from or from .
Proof. We construct the promised data structure as follows. Let and partition into blocks of length ; the last block is shorter if needed. For an interval , define:
• inter(I) ⊆ [m] to be the (nonempty) interval of indices of blocks that intersect I;
-
core(I) ⊆ [m] to be the (possibly empty) interval of indices of blocks that are fully contained within I;
-
fringe(I) to be the collection (of size at most 2) of nonempty intervals over all blocks .
See Fig. 5 for an illustration. All of the above can be computed from in constant time. Also, whenever is a subinterval of , let be the position of the interval relative to , i.e., the interval with both endpoints shifted by .

Figure 5: The objects inter(I), core(I), and fringe(I) for m = 8 and some interval I.
We instantiate three types of auxiliary data structures for INTERVAL-INTERSECT.
-
holds universe . For every with nonempty , it holds the interval with label . is implemented via Lemma 22.
-
holds universe . For every and every fringe interval within an ith block, it holds the interval with label is also implemented via Lemma 22.
-
For each block , the data structure carries universe . For every and every fringe interval within the ith block, it holds the interval labeled . Each is implemented via the assumed linear-time data structure for small universes.
Moreover, for each , we introduce a bit , initially set, representing whether the label is still active.
Given a query interval , we perform the following queries to auxiliary data structures and gather all the returned labels.
• Query with inter(J).
• Query with as long as is nonempty.
• For each , let be contained within the jth block. Then query with .
For each returned label a, if a is still active, we deactivate a (i.e., unset ) and add a to the result label set. This concludes the description of the data structure; we now argue its correctness and efficiency.
Correctness. Let be an input interval labeled and be a query interval. First, suppose is reported by the query. Then, was still active before the query. If reported , then , which easily implies . Next, if reported , then a fringe subinterval resides in a block belonging to ; hence and so . Finally, if is returned by , then there exist and , both within the ith block, so that ; hence trivially .
Conversely, suppose and is active. Let be any element of the intersection and suppose is within the th block. First, if , then definitely reports since intersects the th block. Otherwise, for some . If , then reports as the data structure carries the interval labeled . In the opposite case, for some and so . Therefore, returns . We conclude that an active label is output if and only if , which implies the correctness of our implementation.
Time. Suppose queries are processed by our data structure. Both and maintain a universe of size , hold at most labels, and accept at most queries. Thus both of these auxiliary data structures initialize and process the queries in total time . Then, the data structures have total universe size , carry at most labels in total, and accept queries in total. By our assumption, they all process all the queries in total time . Therefore, the time complexity of our constructed data structure is also linear.
Technically, this may cause two intervals to be assigned to the same label . Formally, in this case, we create two labels and assign them to the two intervals. Then, whenever is reported by , we translate the label to on the fly.
Note that in Lemma 23, the constant hidden in the notation of the resulting data structure is greater than the constant hidden in the prerequisite data structure.
It remains to give a linear-time data structure for sufficiently small universe sizes.
Lemma 24 (Efficient interval intersections for tiny universes). Let be the size of the machine word and . There exists a data structure for any instance of INTERVAL-INTERSECT with the universe size at most that takes a finite set of labels and processes queries in total time . The data structure requires a global table, which can be computed given only in time .
Proof. Fix as the universe size; if the universe size of an instance is smaller than , we can artificially increase it to . Define the state of an instance of INTERVAL-INTERSECT to be the set of active integer intervals of : the intervals assigned to the active labels of the instance. Note that there are exactly different states since there are integer subintervals of . We represent states in memory as bitmasks of length ; this is permitted in our computation model as .
In the preprocessing stage, we initialize a global two-dimensional table as follows. For a state and an interval , we define , where is the set of intervals of intersecting , and is the remaining intervals of . Observe that when an instance of INTERVAL-INTERSECT is in state , then performing a query on it transitions it to state and returns all labels with the corresponding intervals in . Let also, for a state and an interval , the value be an integer such that, for each , the mapping from intervals to the values is a bijection between and . We also explicitly compute an -sized array mapping integer subintervals of to their bit index within the state. The arrays can be constructed in time .
We now give an implementation of the data structure. On initialization, we compute the initial state from and using . Then create buckets of labels from , and for each label , insert —corresponding to an interval —into bucket . This can be done in total time. Let also track the current state of the data structure; initially . Then, for a given query , let . We update the state of the data structure to and return all labels of the intervals in (i.e., all labels in the buckets for ). This can clearly be done in time , where denotes the total number of returned labels. Therefore, all queries are processed in total time .
Given Lemmas 23 and 24, the proof of Lemma 21 is direct.
Proof of Lemma 21. Fix the universe size , and let . By Lemma 24, after preprocessing in time , we can construct a data structure for INTERVAL-INTERSECT processing instances with a universe of size at most , the set of labels , and queries in time . Applying Lemma 23 the first time with , we get a data structure for universes of size with total time . Applying Lemma 23 once again with , we end with the required data structure.
5 Wrap-up of the algorithmic corollaries
The proof of Theorem 6 now simply wraps the results of previous sections together.
Theorem 6. For every graph class C of linear neighborhood complexity, ALL-PAIRS SHORTEST PATH can be solved in time on n-vertex graphs of C.
Proof. By Theorem 33, has bounded versatile symmetric difference. Thus, by Corollary 20, we compute an sd-degeneracy sequence of of constant width in time . By Lemma 13, we get an interval biclique partition of with bicliques in further time. We finally invoke Theorem 5 from every vertex as source, and conclude.
Theorem 7. For every graph class C of linear neighborhood complexity, there is an -time algorithm that, given any adjacency matrix M of an n-vertex graph of C, yields a data structure that computes the matrix-vector product MX in time for any n-vector X.
In particular, the product MN can be computed in time for any matrix N.
Proof. As in the proof of Theorem 6, we obtain an interval biclique partition of with bicliques in time. We conclude with Lemma 14.
6 Finding an sd-degeneracy sequence in randomized linear time
In this section, we prove Theorem 4: we show how to compute an sd-degeneracy sequence of width in expected linear time in graphs of VC density . In particular, this yields an expected linear-time algorithm that outputs sd-degeneracy sequences of constant width in classes of linear neighborhood complexity (Theorem 2). The proof relies on a result in learning theory and VC-combinatorics related to Haussler's packing lemma (Theorem 32).
A set system on a domain is a set of subsets of . For , denote
The shatter function of a set system is the function defined by
The VC dimension of a set system is the largest integer such that there exists a subset of size with .
Given a finite domain , an -sample is a tuple of elements of . We will consider -samples of drawn uniformly at random, that is, each element of is drawn independently and uniformly at random from . (Note that an -sample can contain the same element multiple times.)
Given a set and an -sample , denote . For a set system on a domain and integer , denote
that is, the set of all restrictions of sets in to all possible samples of size s. The next lemma originates in [38, Lemma 9] as part of a proof of Haussler's packing lemma. It is in the spirit of the classical PAC learning model, and states that sets from a set system of bounded VC dimension can be learned from a small random sample.
Lemma 25 ([38]). Let be a set system on a finite domain of VC dimension at most . For any and integer , there exists a map such that for every ,
where denotes that S is an s-sample of X, drawn uniformly at random.
The next algorithm relies on the existence of the map f as above, but does not require to compute it explicitly.
Lemma 26. Fix real numbers and , and let . There is a Las Vegas randomized algorithm that, given an -vertex graph with -polynomial neighborhood complexity and a set with , outputs in expected time
a set of disjoint pairs of -near-twins contained in .
Proof. We may assume that . If , then . An arbitrary maximal pairing of has size at least , and every pair has symmetric difference at most , so we are done. Henceforth assume that .
We first consider the case when U contains no pair of vertices which are twins in G. Let
be the set system with domain of neighborhoods of vertices of . The members of are distinct, and, since has -polynomial neighborhood complexity,
for every positive integer . Let be the VC dimension of . Since , we have , and
Consequently, there is an integer , fixed independently of the input, such that .
Let
Our lower bound on ensures that
Moreover,
Fix a map as in Lemma 25, using the upper bound on the VC dimension. For an -sample , we call an element bad (with respect to ) if
By Lemma 25, for any fixed , the probability over the random choice of that is bad is at most . Thus, the expected number of bad elements of is at most . By Markov's inequality,
One attempt of the algorithm draws an s-sample of and lets be its underlying set. Consider the set system
We have
For each , let the bucket be the set of sets such that . Thus, the buckets partition .
Inside every bucket, we arbitrarily choose a maximum set of pairwise disjoint pairs, leaving at most one set unpaired. Let be the collection of pairs obtained from all the buckets, and let consist of those pairs such that . If , we output the corresponding pairs of vertices in ; otherwise, we discard the attempt and resample .
Claim 27. One attempt takes expected time .
Proof of claim. Sampling takes time. Computing and partitioning into buckets takes expected time by scanning the adjacency lists of the vertices in . Building the candidate pairs takes time.
Given a candidate pair , computing takes time. As the candidate pairs are disjoint, checking all of them takes time.
Claim 28. Every attempt succeeds with probability at least 1/2.
Proof of claim. Let lie in the same bucket. Then , and hence
Therefore, every pair in contains a bad element of . As the candidate pairs are disjoint, the number of such pairs is at most the number of bad elements.
If the buckets are , then and
With probability at least 1/2, at most elements of F are bad, and on that event
Thus, the attempt succeeds.
The expected number of attempts is at most two, so Claim 27 proves the claimed expected running time when U contains no pair of twins in G.
In the general case, construct a graph by adding, for every , a new private pendant vertex adjacent only to . Then the vertices of have pairwise distinct neighborhoods in . We claim that has -polynomial neighborhood complexity. Indeed, fix a nonempty set , and put and . The traces of the old vertices are determined by their traces on , except that at most of them can acquire a private pendant element. The new pendant vertices have traces among and the singletons for . Consequently, the total number of traces on is at most
Also, , , and for every . We can therefore apply the twin-free case to and with constants , , and . This application has the claimed expected running time. Finally, deleting the new pendant vertices cannot increase a symmetric difference, so the returned pairs satisfy the asserted bound in as well.
We now present the randomized linear-time algorithm computing an sd-degeneracy sequence.
Theorem 4. For every real number and every graph class of VC density , there is a randomized algorithm that, given a graph , outputs an sd-degeneracy sequence of of width in expected time .
Proof. Let be such that every graph in has -polynomial neighborhood complexity. Write , , and . We build a sequence of induced subgraphs of , with . Every still has -polynomial neighborhood complexity.
In every iteration with , let be the set of vertices of with smallest degrees, breaking ties arbitrarily. By Lemma 26, applied to , , and , in expected time
we find a set of disjoint pairs of -near-twins inside . We order every pair of arbitrarily, append the ordered pairs to the output sequence, and obtain by deleting the first vertex of every pair. When at most two vertices remain, we append their pair if there are two vertices, and terminate.
Claim 29. The output is an sd-degeneracy sequence of G of width .
Proof of claim. Consider a pair from a batch when it is reached in the output sequence. Earlier pairs of the same batch are vertex-disjoint from , and the graph then present is an induced subgraph of . Hence, its symmetric difference is no larger than it was in , where is a pair of -near-twins. Since , this is . If the algorithm terminates with two vertices, their symmetric difference is at most 2, and hence at most .
Claim 30. The expected running time is .
Proof of claim. We maintain for every current vertex , initialized in time. When vertices are deleted, we update the degrees of their surviving neighbors; all such updates cost in total. In iteration , a linear-time selection algorithm applied to these maintained degrees finds the vertices of smallest degree in time.
By conditional linearity of expectation, the remaining expected work is bounded by
Every iteration removes vertices. Thus, the sequence decreases geometrically, and
For the second term of (1), we have
For every with , let be the smallest index such that contains a vertex of degree at least . The geometric decrease and imply
For every , let
Because consists of the lower half of the degree order and contains a vertex of degree at least , every vertex of has degree at least in , and hence also in . Therefore,
Since for and , we obtain
Substituting both estimates into (1) proves the claim.
We conclude by Claims 29 and 30.
7 Finding Small Patterns
We next design a randomized linear-time algorithm that returns a triangle (if one exists) in graphs from a class of linear neighborhood complexity. The main idea is to use an sd-degeneracy sequence of the input graph to guide the search. In the next three (almost-)linear algorithms we assume that the edges of the input graph are preprocessed into a static dictionary in expected time and space, supporting adjacency queries in expected time.
Theorem 8. For every graph class C of linear neighborhood complexity, TRIANGLE DETECTION can be solved in expected time on n-vertex m-edge graphs of C.
Proof. Let be any input graph. By Theorem 2, we get an sd-degeneracy sequence of of width in randomized time .
For every , we define . Note that to find a triangle in (if any), it is enough to return a triangle of that contains or obtain the guarantee that not all the triangles of contain , and recursively apply this strategy to . Indeed, at each step we either find a triangle in or move to with the promise that contains a triangle if and only if contains one.
We set
for every .
For going from 1 to , the algorithm proceeds as follows. Compute in time by filtering out the vertices of that are adjacent to . By assumption, . For every and every check if . If so, return the triangle (break from the for loop, and terminate). Even if all the checks are unsuccessful, this takes time. If no triangle is found, remove from in time to obtain (and move to the next iteration of the for loop).
Correctness. If there is a triangle in that contains but the algorithm does not return one at the th iteration of the for loop, it is of the form with . Then still contains at least the triangle .
Running time. Computing the sd-degeneracy sequences takes randomized time . The rest of the algorithm takes time
☐
We now build on the scheme of the previous proof to detect a 4-vertex clique. The randomized almost linear algorithm relies on both an sd-degeneracy sequence and a Welzl order.
Theorem 9. For every graph class C of linear neighborhood complexity, a subgraph can be found in expected or in deterministic time on n-vertex m-edge graphs of C.
Proof. We obtain an sd-degeneracy sequence of the input graph of width in randomized time by Theorem 2, or deterministic time by Theorem 1. For every , we define as in the proof of Theorem 8.
Our general strategy remains the same. Now, for every , we do not merely need to know if but rather whether contains an edge, where
We start describing the deterministic -time algorithm, which naturally uses Theorem 1 as opening step.
Let be an arbitrary adjacency matrix of , on which we compute the data structure of Theorem 7 (associated sparse matrix) in time. For going from 1 to , the algorithm proceeds as follows. It computes in time . For every , it computes the indicator (column) vector of in time .
We observe that
and compute the matrix-vector product in time , by Theorem 7. We now check in time whether there is a such that both and are nonzero. If this happens, we know that there is at least one edge in incident to the th vertex, say , of . We can find the other endpoint of such an edge, say , in time. We return the 4-vertex clique (and terminate).
If no is found, we remove from in time to obtain (and move to the next iteration of the for loop). This concludes the algorithm.
Each iteration takes time because . The preprocessing of takes time. Therefore, the overall running time is . The correctness follows as in the proof of Theorem 8.
We now describe the randomized -time algorithm, which first calls Theorem 2. In addition to the sd-degeneracy sequence, we will rely on a Welzl order for ; more specifically, in time we compute a vertex ordering such that the neighborhood of every vertex of is the union of -intervals [23]. We further compute, for every , the -intervals with such that ; overall this takes time . We observe that the orderings and are a priori unrelated. For every , we denote by the integer such that .
We create the following planar point set , with . For every , we add points and to . In preprocessing time, a data structure can be computed that answers rectangle query (given an axis-parallel rectangle , yield a point in ) in time [20, Theorem 2].
Let
and note the subscripts (so in particular ). We proceed as the deterministic -time algorithm, except we decide if (not ) has an edge with the -intervals and . (We do not compute nor .) We compute as the intersection of
This intersection is itself the union of -intervals, say , computed in time. For every , we test if is nonempty with the query rectangle on . If so, we return the corresponding 4-vertex clique, and terminate. This test takes time in total, hence the claimed running time.
We can go one step further and find 5-vertex cliques in randomized almost linear time.
Theorem 10. For every graph class C of linear neighborhood complexity, a subgraph can be found in expected time on n-vertex m-edge graphs of C.
Proof. The proof exactly follows the second part of that of Theorem 9. We now need to detect a triangle of between a triple of -intervals of with . Instead of the planar point set , we build the following integral point set in . To simplify the presentation, we assume that and that is the Welzl order computed in time such that the neighborhood of every vertex of is the union of -intervals [23].
For every , let
where each is an -interval and , and add the point
to , for each . We build in time a 4-dimensional orthogonal range data structure that, given a query box, returns in time one point of contained in the box, if one exists [21, Theorem 5.11].
Now for every triple , , and , we query the box on . If the query returns a point , it holds that , , , , and . In particular, the interval of intersects . Let be any vertex in . It holds that is a triangle in , and we return the 5-vertex clique . If no is found, is removed and the algorithm continues with (next iteration).
Each iteration takes time , hence the overall running time .
One should, however, not expect an almost-linear dependence on uniformly over all clique sizes . The Exponential Time Hypothesis (ETH) asserts that there exists a constant such that 3-SAT on variables cannot be solved in time [33].
Theorem 31. There is a class C of linear neighborhood complexity such that k-CLIQUE cannot be solved in time for any function f, unless the ETH fails.
Proof. By [41, Theorem 1.3] specialized to bipartite 3-regular graphs, as stated in [34, Theorem 1.4], unless the ETH fails, 2-CSP with alphabet and constraints cannot be solved in time for any computable function .
Let be such an instance, and be its constraint graph. Thus . For every constraint , where and , let be the set of pairs allowed by . We construct the cell gadget from the proof of [10, Theorem 3] with and tile set : each of its five blocks contains a copy of for every . Denote the two border blocks at the ends of its horizontal (resp. vertical) path by and (resp. by and ), and the central block by . Each block is a clique, and every copy of in is adjacent to every vertex in except the four copies of .
For every , let be the edges of incident to . For every , we add edges between and , making two vertices adjacent precisely when their first coordinates differ. Similarly, for each variable , we arbitrarily list the edges of incident to as and, for every , add edges between and , making two vertices adjacent precisely when their second coordinates differ.
Denote the resulting graph by . By the correctness argument of [10], is satisfiable if and only if , and
Moreover, by the radius-2 merge sequence from [10], . Observe indeed that the upper bound on the width of the merge sequences does not depend on which pairs of border blocks from distinct cells are connected. Let consist of the complements of all graphs . By [9, Theorem 1.5], the graphs form a class of linear neighborhood complexity. This property is preserved under complementation.
Now an algorithm for k-CLIQUE on running in time , applied to with , would decide in time
The polynomial time needed to construct is absorbed in this bound. This contradicts the ETH lower bound of 2-CSP.
AI Disclosure. A number of proofs in this work have been developed with the assistance of ChatGPT 5.5 Pro.
-
The idea to use a longest-common-extension data structure, critical to Theorem 1, has been brought up by ChatGPT.
-
The details of the bootstrapping process presented in Lemma 23 and Lemma 24 were developed with ChatGPT’s assistance. (The data structure of Lemma 22 was developed by the authors.)
-
A number of technical details in the proof of Theorem 2 have been developed with ChatGPT’s assistance.
The suspected generalizations in Theorems 3 and 4 were confirmed by GPT-5.6 Sol Pro, which also found the extensions in Theorems 9 and 10 of the triangle-detection algorithm. In each case, while ChatGPT suggested pieces of the write-up, the final write-up is due to the authors and has been polished and verified by us.
References
[1] Noga Alon, Raphael Yuster, and Uri Zwick. Finding and counting given length cycles. Algorithmica, 17(3):209–223, 1997. doi:10.1007/BF02523189.
[2] Emile Anand, Jan van den Brand, and Rose McCarty. The structural complexity of matrix-vector multiplication. Advances in Neural Information Processing Systems, 38:37145–37183, 2026.
[3] V. L. Arlazarov, E. A. Dinic, M. A. Kronrod, and I. A. Faradžev. On economical construction of the transitive closure of a directed graph. Doklady Akademii Nauk SSSR, 194(3):487–488, 1970. In Russian.
[4] Jakub Balabán, Daniel Mock, and Peter Rossmanith. Solving partial dominating set and related problems using twin-width. In Paweł Gawrychowski, Filip Mazowiecki, and Michał Skrzypczak, editors, 50th International Symposium on Mathematical Foundations of Computer Science, MFCS 2025, Warsaw, Poland, August 25-29, 2025, volume 345 of LIPIcs, pages 13:1–13:19. Schloss Dagstuhl - Leibniz-Zentrum für Informatik, 2025. URL: https://doi.org/10.4230/LIPIcs.MFCS.2025.13, doi:10.4230/LIPICS.MFCS.2025.13.
[5] Max Bannach, Florian Andreas Marwitz, and Till Tantau. Faster Graph Algorithms Through DAG Compression. In Olaf Beyersdorff, Mamadou Moustapha Kanté, Orna Kupferman, and Daniel Lokshtanov, editors, 41st International Symposium on Theoretical Aspects of Computer Science (STACS 2024), volume 289 of Leibniz International Proceedings in Informatics (LIPIcs), pages 8:1–8:18, Dagstuhl, Germany, 2024. Schloss Dagstuhl – Leibniz-Zentrum für Informatik. URL: https://drops.dagstuhl.de/entities/document/10.4230/LIPIcs.STACS.2024.8, doi:10.4230/LIPIcs.STACS.2024.8.
[6] Michael A. Bender and Martin Farach-Colton. The LCA problem revisited. In Gaston H. Gonnet, Daniel Panario, and Alfredo Viola, editors, LATIN 2000: Theoretical Informatics, 4th Latin American Symposium, Punta del Este, Uruguay, April 10-14, 2000, Proceedings, Lecture Notes in Computer Science, pages 88–94. Springer, 2000. doi:10.1007/10719839_9.
[7] Pierre Bergé, Édouard Bonnet, Hugues Déprés, and Rémi Watrigant. Approximating highly inapproximable problems on graphs of bounded twin-width. In Petra Berenbrink, Patricia Bouyer, Anuj Dawar, and Mamadou Moustapha Kanté, editors, 40th International Symposium on Theoretical Aspects of Computer Science, STACS 2023, Hamburg, Germany, March
7-9, 2023, volume 254 of LIPIcs, pages 10:1–10:15. Schloss Dagstuhl - Leibniz-Zentrum für Informatik, 2023. URL: https://doi.org/10.4230/LIPIcs.STACS.2023.10, doi:10.4230/LIPICS.STACS.2023.10.
[8] Omer Berkman and Uzi Vishkin. Finding level-ancestors in trees. J. Comput. Syst. Sci., 48(2):214–230, 1994. doi:10.1016/S0022-0000(05)80002-9.
[9] Marthe Bonamy and Colin Geniet. -boundedness and neighbourhood complexity of bounded merge-width graphs. CoRR, abs/2504.08266, 2025. URL: https://doi.org/10.48550/arXiv.2504.08266, arXiv:2504.08266, doi:10.48550/ARXIV.2504.08266.
[10] Édouard Bonnet, Maël Dumas, and Julien Duron. Independent set hardness in graphs of bounded twin-width and low-radius merge-width, IPEC 2026. URL: https://arxiv.org/abs/2607.00244, arXiv:2607.00244.
[11] Édouard Bonnet, Julien Duron, John Sylvester, and Viktor Zamaraev. Symmetric-difference (degeneracy) and signed tree models. In Rastislav Královic and Antonín Kucera, editors, 49th International Symposium on Mathematical Foundations of Computer Science, MFCS 2024, August 26-30, 2024, Bratislava, Slovakia, volume 306 of LIPIcs, pages 32:1–32:16. Schloss Dagstuhl - Leibniz-Zentrum für Informatik, 2024. URL: https://doi.org/10.4230/LIPIcs.MFCS.2024.32, doi:10.4230/LIPICS.MFCS.2024.32.
[12] Édouard Bonnet, Colin Geniet, Eun Jung Kim, and Sungmin Moon. Fast shortest path in graphs with sparse signed tree models and applications. In Sayan Bhattacharya, Danupon Nanongkai, Michael Benedikt, and Gabriele Puppis, editors, 53rd International Colloquium on Automata, Languages, and Programming, ICALP 2026, Royal Holloway, University of London, Egham, United Kingdom, July 7-10, 2026, volume 374 of LIPIcs, pages 40:1–40:23. Schloss Dagstuhl - Leibniz-Zentrum für Informatik, 2026. URL: https://doi.org/10.4230/LIPIcs.ICALP.2026.40, doi:10.4230/LIPICS.ICALP.2026.40.
[13] Édouard Bonnet, Colin Geniet, Eun Jung Kim, Stéphan Thomassé, and Rémi Watrigant. Twin-width III: max independent set, min dominating set, and coloring. SIAM Journal on Computing, 53(5):1602–1640, 2024. doi:10.1137/21M142188X.
[14] Édouard Bonnet, Ugo Giocanti, Patrice Ossona de Mendez, and Stéphan Thomassé. Twin-width V: linear minors, modular counting, and matrix multiplication. In Petra Berenbrink, Patricia Bouyer, Anuj Dawar, and Mamadou Moustapha Kanté, editors, 40th International Symposium on Theoretical Aspects of Computer Science, STACS 2023, Hamburg, Germany, March 7-9, 2023, volume 254 of LIPIcs, pages 15:1–15:16. Schloss Dagstuhl - Leibniz-Zentrum für Informatik, 2023. URL: https://doi.org/10.4230/LIPIcs.STACS.2023.15, doi:10.4230/LIPICS.STACS.2023.15.
[15] Édouard Bonnet, Eun Jung Kim, Amadeus Reinald, Stéphan Thomassé, and Rémi Watrigant. Twin-width and polynomial kernels. Algorithmica, 84(11):3300–3337, 2022. URL: https://doi.org/10.1007/s00453-022-00965-5, doi:10.1007/S00453-022-00965-5.
[16] Édouard Bonnet, Eun Jung Kim, Stéphan Thomassé, and Rémi Watrigant. Twin-width I: tractable FO model checking. J. ACM, 69(1):3:1–3:46, 2022. doi:10.1145/3486655.
[17] Édouard Bonnet, Jaroslav Nešetřil, Patrice Ossona de Mendez, Sebastian Siebertz, and Stéphan Thomassé. Twin-width and permutations. Log. Methods Comput. Sci., 20(3), 2024. URL: https://doi.org/10.46298/lmcs-20(3:4)2024, doi:10.46298/LMCS-20(3:4)2024.
[18] Jean Cardinal, Rose McCarty, and Yelena Yuditsky. Biclique decompositions from Welzl orders, 2026. URL: https://arxiv.org/abs/2606.09785, arXiv:2606.09785.
[19] Timothy M. Chan, Hsien-Chih Chang, Jie Gao, Sándor Kisfaludi-Bak, Hung Le, and Da Wei Zheng. Truly subquadratic time algorithms for diameter and related problems in graphs of bounded VC-dimension. In 66th Annual Symposium on Foundations of Computer Science, FOCS 2025, Sydney, Australia, December 14-17, 2025, 2025. URL: https://arxiv.org/abs/2510.16346.
[20] Bernard Chazelle. A functional approach to data structures and its use in multidimensional searching. SIAM J. Comput., 17(3):427–462, 1988. doi:10.1137/0217026.
[21] Mark de Berg, Otfried Cheong, Marc J. van Kreveld, and Mark H. Overmars. Computational geometry: algorithms and applications, 3rd Edition. Springer, 2008. doi:10.1007/978-3-540-77974-2.
[22] Karolina Drabik, Maël Dumas, Colin Geniet, Jakub Nowakowski, Michał Pilipczuk, and Szymon Toruńczyk. Variants of merge-width and applications. CoRR, abs/2602.23867, 2026. URL: https://doi.org/10.48550/arXiv.2602.23867, arXiv:2602.23867, doi:10.48550/ARXIV.2602.23867.
[23] Jan Dreier and Clemens Kuske. Near-linear time computation of Welzl orders on graphs with linear neighborhood complexity. CoRR, abs/2602.14625, 2026. URL: https://doi.org/10.48550/arXiv.2602.14625, arXiv:2602.14625, doi:10.48550/ARXIV.2602.14625.
[24] Jan Dreier and Szymon Toruńczyk. Merge-width and first-order model checking. In Proceedings of the 57th Annual ACM Symposium on Theory of Computing, STOC '25, page 1944–1955, New York, NY, USA, 2025. Association for Computing Machinery. doi:10.1145/3717823.3718259.
[25] Lech Duraj, Filip Konieczny, and Krzysztof Potepa. Better diameter algorithms for bounded vcdimension graphs and geometric intersection graphs. In Timothy M. Chan, Johannes Fischer, John Iacono, and Grzegorz Herman, editors, 32nd Annual European Symposium on Algorithms, ESA 2024, Royal Holloway, London, United Kingdom, September 2-4, 2024, volume 308 of LIPIcs, pages 51:1–51:18. Schloss Dagstuhl - Leibniz-Zentrum für Informatik, 2024. URL: https://doi.org/10.4230/LIPIcs.ESA.2024.51, doi:10.4230/LIPIcs.ESA.2024.51.
[26] Harold N. Gabow and Robert Endre Tarjan. A linear-time algorithm for a special case of Disjoint Set Union. J. Comput. Syst. Sci., 30(2):209–221, 1985. doi:10.1016/0022-0000(85)90014-5.
[27] Jakub Gajarský, Petr Hliněný, Jan Obdržálek, Sebastian Ordyniak, Felix Reidl, Peter Rossmanith, Fernando Sánchez Villaamil, and Somnath Sikdar. Kernelization using structural parameters on sparse graph classes. Journal of Computer and System Sciences, 84:219–242, 2017. doi:10.1016/j.jcss.2016.09.002.
[28] Jakub Gajarský, Michał Pilipczuk, Wojciech Przybyszewski, and Szymon Toruńczyk. Twin-width and types. In Mikolaj Bojanczyk, Emanuela Merelli, and David P. Woodruff, editors, 49th International Colloquium on Automata, Languages, and Programming, ICALP 2022, Paris, France, July 4-8, 2022, volume 229 of LIPIcs, pages 123:1–123:21. Schloss Dagstuhl - Leibniz-Zentrum für Informatik, 2022. URL: https://doi.org/10.4230/LIPIcs.ICALP.2022.123, doi:10.4230/LIPICS.ICALP.2022.123.
[29] Robert Ganian, Filip Pokrývka, André Schidler, Kirill Simonov, and Stefan Szeider. Weighted model counting with twin-width. In Kuldeep S. Meel and Ofer Strichman, editors, 25th International Conference on Theory and Applications of Satisfiability Testing, SAT 2022, Haifa, Israel, August 2-5, 2022, volume 236 of LIPIcs, pages 15:1–15:17. Schloss Dagstuhl - Leibniz-Zentrum für Informatik, 2022. URL: https://doi.org/10.4230/LIPIcs.SAT.2022.15, doi:10.4230/LIPICS.SAT.2022.15.
[30] Martin Grohe, Stephan Kreutzer, and Sebastian Siebertz. Deciding first-order properties of nowhere dense graphs. J. ACM, 64(3):17:1–17:32, 2017. doi:10.1145/3051095.
[31] Martin Grohe and Daniel Neuen. Isomorphism for tournaments of small twin width. TheoretiCS, 5, 2026. URL: https://doi.org/10.46298/theoretics.26.4, doi:10.46298/THEORETICS.26.4.
[32] David Haussler. Sphere packing numbers for subsets of the boolean n-cube with bounded Vapnik-Chervonenkis dimension. J. Comb. Theory A, 69(2):217–232, 1995.
[33] Russell Impagliazzo, Ramamohan Paturi, and Francis Zane. Which problems have strongly exponential complexity? Journal of Computer and System Sciences, 63(4):512–530, 2001. doi:10.1006/jcss.2001.1774.
[34] Karthik C. S., Dániel Marx, Marcin Pilipczuk, and Uéverton S. Souza. Conditional lower bounds for sparse parameterized 2-CSP: A streamlined proof. In Merav Parter and Seth Pettie, editors, 2024 Symposium on Simplicity in Algorithms, SOSA 2024, Alexandria, VA, USA, January 8-10, 2024, pages 383–395. SIAM, 2024. doi:10.1137/1.9781611977936.35.
[35] László Kozma and Michal Opler. Fast and simple multiplication of bounded twin-width matrices. CoRR, abs/2602.20023, 2026. URL: https://doi.org/10.48550/arXiv.2602.20023, arXiv:2602.20023, doi:10.48550/ARXIV.2602.20023.
[36] Stefan Kratsch and Florian Nelles. Efficient parameterized algorithms for computing all-pairs shortest paths. Discret. Appl. Math., 341:102–119, 2023. URL: https://doi.org/10.1016/j.dam.2023.07.029, doi:10.1016/J.DAM.2023.07.029.
[37] Stefan Kratsch, Florian Nelles, and Alexandre Simon. On triangle counting parameterized by twin-width. CoRR, abs/2202.06708, 2022. URL: https://arxiv.org/abs/2202.06708, arXiv:2202.06708.
[38] Andrey Kupavskii and Nikita Zhivotovskiy. When are epsilon-nets small? Journal of Computer and System Sciences, 110:22–36, 2020. URL: https://www.sciencedirect.com/science/article/pii/S0022000020300027, doi:https://doi.org/10.1016/j.jcss.2019.12.006.
[39] Gad M. Landau and Uzi Vishkin. Fast string matching with k differences. J. Comput. Syst. Sci., 37(1):63–78, 1988. doi:10.1016/0022-0000(88)90045-1.
[40] László Lovász. Graph minor theory. Bulletin of the American Mathematical Society, 43(1):75–86, 2006. doi:10.1090/S0273-0979-05-01088-8.
[41] Dániel Marx. Can you beat treewidth? Theory Comput., 6(1):85–112, 2010. URL: https://doi.org/10.4086/toc.2010.v006a005, doi:10.4086/TOC.2010.V006A005.
[42] Jiří Matoušek. Geometric Discrepancy: An Illustrated Guide, volume 18 of Algorithms and Combinatorics. Springer Berlin Heidelberg, Berlin, Heidelberg, 1999. doi:10.1007/978-3-642-03942-3.
[43] Jaroslav Nešetril and Patrice Ossona de Mendez. Grad and classes with bounded expansion i. decompositions. Eur. J. Comb., 29(3):760–776, 2008. URL: https://doi.org/10.1016/j.ejc.2006.07.013, doi:10.1016/J.EJC.2006.07.013.
[44] Jaroslav Nešetril and Patrice Ossona de Mendez. Grad and classes with bounded expansion II. algorithmic aspects. Eur. J. Comb., 29(3):777–791, 2008. URL: https://doi.org/10.1016/j.ejc.2006.07.014, doi:10.1016/J.EJC.2006.07.014.
[45] Jaroslav Nešetril and Patrice Ossona de Mendez. First order properties on nowhere dense structures. J. Symb. Log., 75(3):868–887, 2010. URL: https://doi.org/10.2178/jsl/1278682204, doi:10.2178/JSL/1278682204.
[46] Jaroslav Nešetril and Patrice Ossona de Mendez. On nowhere dense graphs. Eur. J. Comb., 32(4):600–617, 2011. URL: https://doi.org/10.1016/j.ejc.2011.01.006, doi:10.1016/J.EJC.2011.01.006.
[47] R. Seidel. On the all-pairs-shortest-path problem in unweighted undirected graphs. Journal of Computer and System Sciences, 51(3):400–403, 1995. URL: https://www.sciencedirect.com/science/article/pii/S0022000085710781, doi:https://doi.org/10.1006/jcss.1995.1078.
[48] Szymon Toruńczyk. Flip-width: Cops and robber on dense graphs. In 64th IEEE Annual Symposium on Foundations of Computer Science, FOCS 2023, Santa Cruz, CA, USA, November 6-9, 2023, pages 663–700. IEEE, 2023. doi:10.1109/FOCS57990.2023.00045.
[49] Emo Welzl. Partition trees for triangle counting and other range searching problems. In Herbert Edelsbrunner, editor, Proceedings of the Fourth Annual Symposium on Computational Geometry, Urbana-Champaign, IL, USA, June 6-8, 1988, pages 23–33. ACM, 1988. doi:10.1145/73393.73397.
A Neighborhood complexity and versatile symmetric difference
We give a shorter (albeit non-algorithmic) proof for the inclusion of class families that can already be deduced in Lemma 26. In Theorem 33, we derive versatile symmetric difference from VC density thanks to the following fundamental result of Haussler.
Theorem 32 (Haussler's packing lemma [32]). Let be a set system of VC dimension with on a finite domain , and let be real numbers such that for every positive integer . Then , and there are distinct such that
Proof. Since , we have . Hence,
which implies that .
Let
By Theorem 1 of [32], more precisely by the proof of [42, Lemma 5.14],
Rearranging gives
as required.
We can now prove the main result of this section. Note that a stronger algorithmic result is proved in Lemma 26.
Theorem 33. For every fixed pair of real numbers , there is a constant such that every -vertex graph with -polynomial neighborhood complexity contains at least disjoint pairs of vertices satisfying .
Consequently, every hereditary graph class of VC density has versatile symmetric difference of exponent . In particular, every class of linear neighborhood complexity has bounded versatile symmetric difference.
Proof. Fix an -vertex graph with -polynomial neighborhood complexity. Let be a largest subset of vertices without twins in , that is, for any distinct . For each , let be the set of vertices in that are twins of . Then forms a partition of . We split the argument depending on whether .
Case : For every , pairing vertices arbitrarily inside gives disjoint pairs of twins. Thus, the total number of pairs is at least
The constant on page 158 of [42] is in our notation, and the last inequality on page 159, for , gives .
In particular, this gives at least pairs satisfying the claimed bound.
Case : Consider the set system of neighborhoods
over the domain . Its members are distinct and . Every subsystem satisfies
for every positive integer . By Theorem 32, there is a constant such that every subsystem with at least two members contains distinct with
The neighborhood will be referred to as when considered as a member of the set system. Starting with , repeat times: choose such a pair and remove both sets to obtain . Before every choice, fewer than sets have been removed, so the current subsystem has more than members and the preceding application of Theorem 32 applies. The corresponding vertex pairs are disjoint, and every chosen pair satisfies
Taking proves the first assertion. For the consequence, if has VC density , choose a constant witnessing this fact and apply the first assertion to every graph in . With , each -vertex graph in has at least disjoint pairs with symmetric difference at most . Thus, has versatile symmetric difference of exponent .