The Communication Complexity of Pattern Matching with Edits Revisited
Abstract
The decades-old Pattern Matching with Edits problem, given a length- string (the text), a length- string (the pattern), and a positive integer (the threshold), asks to list the -error occurrences of in , that is, all fragments of whose edit distance to is at most . The one-way communication complexity of this problem is the minimum number of bits that Alice, given an instance of the problem, must send to Bob so that Bob can reconstruct the answer solely from that message.
In recent work [STOC’24], we showed that, in the natural parameter regime , bits are necessary and bits are sufficient for this problem. More generally, for strings over an alphabet , we gave an -bit encoding that allows one to recover a shortest sequence of edits for every -error occurrence of in .
In this paper, we revisit the original proof and improve the encoding size to , which matches the lower bound for constant-sized alphabets. We further establish a new tight lower bound of for the edit sequence reporting variant we solve. Our encoding size also matches the communication complexity established for the simpler Pattern Matching with Mismatches problem in the context of streaming algorithms [Clifford, Kociumaka, Porat; SODA’19].
Keywords and phrases:
Edit distance, Pattern matching, Communication complexityCopyright and License:
2012 ACM Subject Classification:
Theory of computation Pattern matching ; Theory of computation Communication complexity ; Mathematics of computing Combinatorics on wordsEditors:
Philip Bille and Nicola PrezzaSeries and Publisher:
Leibniz International Proceedings in Informatics, Schloss Dagstuhl – Leibniz-Zentrum für Informatik
1 Introduction
In the more-than-classic Pattern Matching with Edits problem (PMWE) [22], we are given a text of length , a pattern of length , and a threshold , and the task is to compute the starting positions of all substrings of whose edit distance to is at most . Formally, we aim to compute the set
where denotes the edit (Levenshtein) distance [21]. This metric quantifies the (dis)similarity between strings by counting the minimum number of single-character edits (insertions, deletions, and substitutions) required to transform one string into the other.
Research into this problem has expanded far beyond the classical setting [22, 19, 20, 9, 5, 6], with modern variants exploring compressed [11, 24, 3, 5], dynamic [5], streaming [23, 17, 2], weighted [7], and quantum [13, 15] settings. We recently investigated the problem’s one-way communication complexity [13], which involves determining the minimum space required to encode an instance so that the set of -error occurrences can be reconstructed without further access to the original input.
The communication complexity framework models this as a two-party game: Alice, who holds the problem instance, transmits a single message to Bob. Bob’s task is to derive the full output solely from this message. Because Bob lacks any initial input of his own, the problem reduces to a one-way single-round protocol, and the primary objective is to minimize the number of bits Alice must transmit.
In [13], we established that, in the natural parameter regime of , bits are necessary for this problem, while bits are sufficient. More generally, we showed that if the shortest sequence of edits must be recovered for each -error occurrence, the upper bound increases to , where is the input alphabet. The former result is implied by the latter by performing a simple alphabet reduction: all characters of not present in are mapped to a single character. The result of [13] is significant for three reasons.
-
1.
A central open question [9, 6] for PMWE is whether a static algorithm can match the conditional lower bound [1]. The current state-of-the-art algorithm by Charalampopoulos, Kociumaka, and Wellnitz [6] runs in time, and relies on structural results [5] that allow it to return the required output using bits. This encoding is fundamentally incompatible with reaching the lower bound; however, the results of [13] demonstrate that this barrier can indeed be overcome.
-
2.
A similar question was previously settled for the simpler Pattern Matching with Mismatches problem (PMWM) [8]; here bits are necessary and bits suffice to also report the mismatches for all -mismatch occurrences. Thus, by [13] and up to essentially an factor, the edit distance setting behaves the same as the mismatch setting in terms of information density.
-
3.
Said result of [13] also paves the way for better algorithms in other computational models (e.g., the quantum algorithms for PMWE of [13, 15], which crucially rely on this result). The prior work on PMWM [8] suggests that one-way communication complexity is a stepping stone toward -space algorithms in the streaming and semi-streaming models. This is particularly relevant given the concurrent development of -size edit distance sketches [18]. Although the state-of-the-art sketches do not yet offer the space-efficient sketch construction needed for a full streaming implementation, the advances in [13] represent significant steps toward it.
Our Results.
We re-examine the encoding provided in [13] and, through a series of refinements, eliminate the term separating the upper and lower bounds. Thereby, we place PMWE on par with PMWM. Formally, we show the following result.
Theorem 1.1.
Fix integers with and an input alphabet . The Pattern Matching with Edits problem admits a one-way deterministic communication protocol that sends bits. Within the same communication complexity, one can also reconstruct the set of all fragments satisfying and, for each such fragment, the edit information (the positions and values of edited characters) of all optimal edit sequences transforming into the fragment .
Remark 1.2.
Our result extends routinely beyond . If , it suffices to apply Theorem 1.1 with the text replaced by , where is an arbitrary character. Applying Theorem 1.1 with threshold allows one to reconstruct the entire pattern from the edit sequence for an empty fragment of the text and the entire text from the edit sequences for single-character fragments; this covers . Finally, the case is no harder than . Thus, in full generality, the communication complexity becomes
Through the aforementioned alphabet reduction, we also achieve bits for the variant where only the positions (but not the values) of edited characters are reported. This suffices for the baseline problem asking for the starting positions of -error occurrences, which means that we match the lower bound of [13] unless both and .
It is not difficult to show that a single optimal edit sequence for a single -error occurrence can be encoded using bits. While the previous approach in [13] required storing information proportional to edit sequences for each length- block of the text, our improvement achieves the information content equivalent to edit sequences. Hence, in a -length block of , the cost of encoding all -error occurrences and their respective edit sequences is asymptotically no greater than the cost of encoding one!
We also establish a new lower bound proving that our protocol is optimal for edit retrieval.
Theorem 1.3.
Fix integers with and an input alphabet with and . Consider an encoding that, for each fragment with , allows to reconstruct an edit sequence and the corresponding edit information. Such an encoding must use bits for and some .
Our Techniques.
On a very high level, in [13], the text is first partitioned into partially overlapping blocks, each of length and such that each -error occurrence of in is fully contained in some block. For each such block, the encoding contains:
-
1.
a set of -error occurrences of in , each stored together with an optimal edit sequence using bits;
-
2.
the Lempel–Ziv LZ77 [25] compressed representation of a collection of fragments of selected based on . The total number of LZ77 phrases is proportional to the total cost of -error occurrences in , so they can be encoded using bits.
Overall, this yields an encoding cost of bits per block and bits for the entire text. The underlying construction is relatively complex, relying on recent insights relating edit distance to compressibility [4, 12] via the so-called self-edit distance. Nevertheless, our key improvement is simple to describe at a high level: In (1), we partition the -th -error occurrence into pieces and store the edit information only for the “cheapest” piece, incurring only edits, for a total of instead of . The fragments in (2) are defined essentially the same way and, thanks to the decreased total cost in (1), they can be encoded in bits.
Generalizing the relevant concepts to capture pieces of requires several delicate steps, which we discuss in Section 3. Moreover, our approach breaks for since -error pieces still need a -bit representation, which becomes a bottleneck when . In that case, through the structural characterization of Charalampopoulos, Kociumaka, and Wellnitz [5], the existence of occurrences implies that and the relevant part of are at edit distance from highly periodic strings. We then use this rigid structure to show that just three -error occurrences of in can play the role of in (1).
2 Preliminaries
Sets.
For integers , we write to denote the set and to denote the set ; we define the sets and similarly.
For a set of integers and a parameter , we also define .
Strings.
An alphabet is a set of characters. We write to denote a string of length over . For a position , we say that is the -th character of . A string is a substring of another string if holds for some integers . In this case, we say that there is an (exact) occurrence of starting at position in . The occurrence is a fragment of denoted ; formally, the fragment can be interpreted as a tuple consisting of a (reference to) and the two positions and . We may also write , , or for the fragment . A prefix of a string is a fragment of the form , and a suffix of a string is a fragment of the form .
For two strings and , we write for their concatenation. We write for the concatenation of copies of the string . Moreover, is an infinite string (indexed with non-negative integers) formed as the concatenation of an infinite number of copies of .
An integer is a period of a string if we have for all . In this case, we also say that the string is a string period of . In other words, a string is a string period of a string if is a prefix of and . The period of a non-empty string , denoted , is the smallest period of . A non-empty string is periodic if .
Periodicity Lemma.
For completeness, we restate Fine and Wilf’s Periodicity Lemma [10].
Lemma 2.1 (Periodicity Lemma [10]).
If are periods of a string of length , then is a period of .
Edit Distance and Alignments.
The edit distance (Levenshtein distance [21]) between two strings and , denoted by , is the minimum number of character insertions, deletions, and substitutions required to transform into . Formally, we first define an alignment between string fragments.
Definition 2.2 ([6, Definition 2.1]).
A sequence is an alignment of onto , denoted by , if it satisfies , for , and . Moreover, for :
-
If , we say that deletes .
-
If , we say that inserts .
-
If , we say that aligns to . If also , then matches and ; otherwise, substitutes with .
The cost of an alignment of onto , denoted by or , is the total number of characters that inserts, deletes, or substitutes. The edit distance is the minimum cost of an alignment of onto . An alignment of onto is optimal if its cost is equal to .
Given an alignment and a fragment contained in , we write for the fragment of that aligns against . As insertions and deletions may render this definition ambiguous, we set
This particular choice satisfies the following decomposition property.
Observation 2.3 ([6, Fact 2.2]).
For an alignment and a decomposition into fragments, is a decomposition into fragments with . If is optimal, then .
We use the following edit information notion to encode alignments.
Definition 2.4 (Edit information of an alignment).
For an alignment , the edit information is the set of 4-tuples , where
By monotonicity of the alignment, the order of the tuples with respect to coincides with their lexicographic order by and by .
Observe that, given two strings and , the endpoints , and the edit information of an alignment , we are able to fully reconstruct . Indeed, each tuple of specifies a non-matching operation, whereas all pairs of before the first tuple, between consecutive tuples, and after the last tuple must be matches. Moreover, given the characters of and the edit information , one can recover the characters of . Indeed, the tuples of reveal all characters of created by insertions and substitutions, while the remaining characters of correspond to matches and can therefore be copied from .
Pattern Matching with Edits.
In the context of two strings (referred to as the pattern) and (referred to as the text), along with a positive integer (referred to as the threshold), we say that is a -error occurrence of in if holds.
3 Upper Bound: Proof Overview
In this section, we provide an overview of the proof of Theorem 1.1111This paper provides an overview of the full version [16].. To this end, we fix two strings and , and a positive threshold . Throughout this section, we assume that , , and has -error occurrences as a prefix and as a suffix of . In [13, Claim 4.31222All references to numbers of theorems, lemmas, and definitions of [13] refer to their full version [14].], a standard block-splitting argument is employed to demonstrate that a protocol using bits for this specific case is sufficient to achieve bits in general. We improve the former communication bound to bits and a similar proof to [13, Claim 4.31] to drop the assumptions.
The remainder of this section is structured as follows. In Section 3.1, we provide a concise overview of the proof from [13], focusing specifically on the components we adapt to achieve our improvements. Subsequently, in Section 3.2, we outline our improved construction.
3.1 Previous Encoding
3.1.1 The Graph and the Induced Periodic Structure
The main ingredient of the encoding of [13] is a set of alignments of onto fragments of with cost at most each. The starting point of [13] is to analyze how much information such a set of alignments carries, in order to better understand how one should choose which alignments to include and what additional information is needed to fully encode . To enable this analysis, the set is associated with a graph , which we call the inference graph.
Definition 3.1 ([13, Definition 4.1]).
Let be a set of alignments . We define the undirected graph as follows. The vertex set contains
-
1.
vertices representing characters of ;
-
2.
vertices representing characters of ; and
-
3.
one special vertex .
The edge set contains the following edges for each alignment .
-
1.
for every character that deletes;
-
2.
for every character that inserts;
-
3.
for every pair of characters and that aligns.
We say that an edge is black if matches and . All other edges are red.
A connected component of is red if it contains at least one red edge; otherwise, the connected component is black. We denote the number of black components with .
Note that all vertices contained in black components correspond to characters of and . Moreover, all characters of a single black component are the same, because the presence of a black edge indicates that some alignment in matches the two corresponding characters.
The inference graph is represented implicitly via the edit information for each alignment in . In [13] we naively use the fact that bits suffice to encode this information; here, we provide a (slightly) more efficient encoding argument that is required to obtain our tight results for small alphabets.
Lemma 3.2.
Let be a set of alignments . The set together with the starting/ending points for each can be encoded using
This information, together with the bit encoding of and , suffices to fully reconstruct the complete edge set of and the color of each edge. Moreover, this information suffices to identify the character for every node in a red component.
Proof.
For each with , the elements in are monotone in their first and third components. Using a “stars and bars” encoding, these components take bits. If , this simplifies to . The second and fourth components are encoded separately using bits. For each with we only need to store the endpoints using bits each.
Finally, for every character in and within a red component, there exists a path of black edges (possibly of length zero) connecting that character to one incident to a red edge. Since black edges connect identical characters, the character value is invariant along this path. Because we explicitly store all characters incident to red edges, we can deduce the character at the origin of any such path.
Lemma 3.2 provides an encoding that reveals all characters contained in red components of in the inference graph . Thus, the case is easy as we can then fully retrieve and .
Consequently, we assume for the rest of the section, as this is the remaining case. Even though one cannot learn the characters in black components via the edit information for each alignment in (and storing all of them would be prohibitive), one can still infer which character belongs to which component.
The key observation of [13] is that black components are extremely structured and appear in a periodic fashion. To make this structure more formal, we define two strings, and , obtained by retaining only the characters that belong to black connected components.
Definition 3.3 ([13, Definition 4.3]).
Let and denote the subsequences of and , respectively, consisting of the characters contained in black components of . We denote the lengths of and by and , respectively.
The first structural observation is that the black edges of the inference graph induced by a single alignment correspond to an exact occurrence of in .
Lemma 3.4 ([13, Claim 4.5]).
Let , and define as the number of characters of contained in and , respectively. Then, we have , and induces edges between and for every , and no other edges incident to characters of or .
Many overlapping exact occurrences induce periods of the pattern; thus, in [13] we enforce the following condition on to ensure the induced exact matchings overlap.
Definition 3.5 ([13, Definition 4.2]).
We say encloses if and there exist two alignments such that aligns with a prefix of and aligns with a suffix of , or equivalently and .
Given this condition on , we show that not only are and periodic, but even the membership of their characters in black components follows a periodic structure.
Lemma 3.6 ([13, Lemma 4.4]).
If encloses , then, for every , there is a black connected component with node set , that is, a black connected component containing all characters of and appearing at positions congruent to modulo . Moreover, the last characters of and are contained in the same black connected component, that is, .
Lemma 3.6 allows us to define the following quantities related to the periodic structure:
-
For , we define the -th black connected component as the black connected component containing and set and as the number of characters in and , respectively, that belong to the -th black connected component.
-
For and , we define as the position of in . Similarly, for and , we define as the position of in . Note that, for any , the characters are exactly those in the -th black component. Consequently, they are all identical.
3.1.2 Constructing and the Encoding
In [13], based on and a weight , we identify a subset of black components so that the characters with belong to fragments of whose LZ77 parses consist of phrases in total. The construction ensures several desirable properties specified below. This is the most technical component of [13], and it is not significantly affected by our modifications, so we omit deeper insights here.
These desirable properties concern all fragments such that if we were to align onto , then would be close enough to for some . More formally:
Definition 3.7 ([13, Definition 4.28]).
We say that captures if encloses and either or holds for some .
For all such , the information carried by and is sufficient to infer whether and, if so, provide the exact distance and infer the edit sequence.
Theorem 3.8 ([13, Corollary 4.30]).
Let be a set of -edit alignments of onto fragments of such that encloses and . Construct and by replacing, for every , every character in the -th black component with a unique character .
If captures all -error occurrences, then
-
1.
and for all optimal alignments of cost at most .
-
2.
for all integers .
Theorem 3.8 makes sure that one can encode the desired information for all captured -error occurrences. For those that are not captured, the following result is shown in [13].
Lemma 3.9 ([13, Lemma 4.27]).
Let be an alignment of cost at most . If holds for every , then there is no such that aligns with for some .
An alignment as in Lemma 3.9 satisfies , since each black component becomes red or is merged with another black component. Thus, adding to allows for significant progress towards . Altogether, the construction proceeds as follows.
-
In the beginning, we set .
-
While does not capture all -error occurrences, select an uncaptured -error occurrence and add to an optimal alignment .
-
Return the edit information for alignments , encoded using Lemma 3.2, and the set , encoded using the LZ77-compressed fragments of .
Since the second step can be executed at most times before captures all -error occurrences, the entire encoding requires bits. To decode, it suffices to retrieve the inference graph from the edit information and, using the encoding of as described in Theorem 3.8, construct and , which preserve the solution to the original problem.
3.2 Improved Encoding
To tighten our upper bound on the communication complexity, we revisit the step where an uncaptured alignment is added to . For this, we strengthen the conclusion of Lemma 3.9, which applies only to the initial character of each black component . In the full version version, we prove that cannot match any characters within the same black component.
Lemma 3.10.
Let be an optimal alignment with . If and holds for every , then there is no such that aligns with for some and .
Lemma 3.10 brings us to the main idea of our improvement: rather than adding an entire uncaptured alignment to , it suffices to add only the subset of edges required to merge every black component with another component. More specifically, if we decompose into
then at least one of the middle fragments of in this decomposition carries at most edits in . So ideally, we would like to add to and the corresponding edges restricted to this fragment. If we managed to show that the periodic structure is preserved already by adding such a subset, then not only would halve, but also the parameter would at least double in each iteration. Hence, with this new strategy, we could hope that the total cost of alignment or partial alignment in is bounded by .
On a technical level, the proof is delicate: The selection of the fragment , as described so far, depends on and the black components defined relative to . However, the structure of the black components changes when going from to , and the fragment is not guaranteed to contain the same black components as in . Thus, for our proof of correctness, we need to be careful to get rid of any such undesired dependence on the future.
Finally, we note that Lemma 3.10 is not a strict strengthening of Lemma 3.9, as it introduces three additional conditions: now instead of , is optimal, and that . We observe that all conditions are relatively harmless. Since we are only concerned with capturing all optimal alignments, the first two conditions are perfectly acceptable. Moreover, whenever , we have and , where and are defined as in Theorem 3.8. At this point, we know that and already have a sufficiently cheap encoding to be sent directly.
3.2.1 Redefining
Let us start making our improvement formal. To this end, we relax the definition of : we let be a set of alignments of fragments of onto fragments of with cost at most , and we denote by the sum of all costs of the alignments contained in .
Based on such , we can define the inference graph as before and argue that all characters in red components follow from the edit information for all . We conclude again that is easy, and we assume that in this (sub)section. We also define and as before. Lemma 3.4 can be extended quite easily to fragments of ; see the full version.
Lemma 3.11.
Let and define as the number of characters of contained in and . Similarly, define as the number of characters of contained in and .
Then, , and induces edges between and for , and no other edges incident to characters of or .
We next give the new condition on needed to observe the periodic structure.
Definition 3.12.
We say encloses if and can be written as
such that the following conditions hold:
-
(a)
aligns the whole with a prefix of ;
-
(b)
aligns the whole with a suffix of ;
-
(c)
align the whole with fragments of .
We say is degenerate if . Moreover, we define
For each , we define We further say that succinctly encloses if the following condition holds for every .
-
(d)
The alignment satisfies .
If encloses , then each of the alignments aligns the entire string with a fragment of , and the edges they induce connect to all vertices of . Consequently, we have and . Moreover, note that whenever succinctly encloses and is degenerate, then , since the condition (d) cannot hold for if .
We can also prove something more about the exact matching induced by and .
Lemma 3.13.
If encloses , then , , and .
The proof, provided for completeness in the full version, is the same as [13, Claim 4.6]. This is because the argument relies exclusively on the alignments and (and not any ).
Lemma 3.13 also implies that, when is degenerate, then and every alignment induces in an edge iff . In this case, for each , there is a black component consisting solely of and .
The following generalization of the inference graph lets us work with graphs of more predictable structure.
Definition 3.14.
Suppose encloses . We define the sets and for .
Moreover, for , we define the graph obtained from as follows. We remove vertices (along with their incident edges) that are not in black components in (so only vertices in and remain), and we additionally remove any edge that is not induced by alignments in the set .
We now proceed to argue this definition successfully preserves the periodic structure.
Lemma 3.15.
Suppose encloses . Then, the following hold for each .
-
1.
If condition (d) in Definition 3.12 holds for all indices in , then, for each , the graph has a connected component with node set , where ranges over and , respectively.
In particular, in , for every , there exists a black connected component with node set .
-
2.
The last characters of and are in the same component of .
Proof.
We first prove (1). If is degenerate (and hence ), we have already argued that has the claimed structure. Therefore, we assume that is not degenerate.
Let us assign a unique label to each component of and define strings and of length and , respectively, as follows. For , set , where is the component of containing . Similarly, for , set , where is the black connected component of containing .
By Lemmas 3.11 and 3.13, . Since , we can use the following claim already proved in [13].
Claim 3.16 ([13, Lemma 3.2]).
Consider a non-empty pattern and a text with . If , that is, occurs both as a prefix and as a suffix of , then is a period of .
It follows that is a period of . Hence, is a period of both and its prefix , and thus is a period of both and .
We now prove by induction that and have period for all . The base case follows from the argument above. For , assuming and have period , we observe that the condition on ensures . The following new claim allows us to conclude that and have period .
Claim 3.17.
Consider strings and with a common string period . If there are matching fragments of length , then and also have a common period .
Proof.
The claim is trivial if , so we henceforth assume otherwise. By symmetry between the fragments, we can also assume without loss of generality that . Since and are prefixes of , we have . Observe that is a period of : for each , we indeed have . From the Periodicity Lemma (Lemma 2.1) applied for , we conclude that is a period of and hence of . As a divisor of , it is also a common period of , , and .
Consequently, for each , the set belongs to a single connected component of . It remains to prove . We do this by demonstrating that no edge of leaves . Note that Lemma 3.11 further implies that every edge incident to or connects with such that for some and . In particular, , so holds if and only if .
As for (2), since is a suffix of , the last characters of and are connected.
3.2.2 New Iterative Construction of
For the new construction of , we use the following key lemma.
Lemma 3.18.
Suppose encloses and condition (d) of Definition 3.12 holds up to (inclusive) for some (if , then this statement is void). Further, suppose that there exists an integer such that all characters of are in the pre-image of . Then, either or condition (d) also holds for .
Proof.
By Lemma 3.15(1), in the inference graph , for each , there is a black component with node set . Consider the graph . This graph is identical to except that the components that become red in are removed. Let index these removed components.
If , then , and the proof is complete. Otherwise, we proceed as follows. Choose an arbitrary , and consider the fragment
whose characters, by our assumption, are also contained in the pre-image of . The characters and belong to the same black component of . Since , these characters survive in and correspond to some characters and . Note that we must have as, by Lemma 3.15(1), characters in the same component of lie at least positions apart. Thus, . Since is contained in , we get .
Finally, we can provide the new construction of . As in [13], we construct, from , a set of black components and a parameter based on a weight function covering . We use the following facts (proved in the full version):
-
1.
Lemma 3.10 still holds, and after replacing “enclosure” with “succinct enclosure” in Definition 3.7, Theorem 3.8 still holds.
-
2.
We can improve the bound for encoding from additional bits (on top of the edit information of ) to bits.
-
3.
All of this is possible with instead of .
Lemma 3.19.
Suppose that and that there are -error occurrences of appearing as both a prefix and a suffix of . Then, Algorithm 1 computes a set of size and such that the following hold:
-
1.
succinctly encloses ,
-
2.
or captures all -error occurrences of in ,
-
3.
the set together with all starting/ending points of the alignments in can be encoded in bits.
Proof sketch (full proof in the full version).
In Algorithm 1, we maintain the invariant that succinctly encloses at the start of every iteration of the loops in Lines 2 and 7.
This invariant holds at the beginning as we set . We proceed by adding at most two alignments to corresponding to uncaptured -error occurrences in the loop of Line 2. After the -th iteration, one of , , or holds, where is the minimum number of characters of in a black component of . Indeed, by Lemma 3.10, after adding to , each black component of either becomes red or is merged with another component. Hence, unless , every black component of contains at least two black components of , so at least doubles.
Adding the two alignments of the form ensures that when we enter the loop at Line 7 (so that in Line 11, and the quantifier is well-defined). There, we start adding alignments of the form to . Each time we add such an alignment, we use Lemmas 3.18 and 3.10 to prove that still succinctly encloses . Using a similar argument as before, , , or at the end of the -th iteration. Since , this ensures that the loop finishes after iterations and . When it does, all -error occurrences are captured.
Next, we argue why the bound on holds. Since each of the alignments can overlap only with at most two others, we obtain that the sum of the costs of the alignments for all is at most . Consequently, in the -th iteration the cost of the alignment selected at Line 11 is at most . Thus, .
Lastly, we give the bound on the encoding size. The endpoints of the alignments can be encoded in bits. On top of that, by Lemma 3.2, the edit information can be encoded in space asymptotically bounded as follows, using and the monotonicity of for :
To show , we argue in the full proof that the alignments in Line 10 start at least positions away from each other.
Now, following the approach in [13], we can encode the set and the pairs using bits. Decoding would then proceed via an appropriately modified version of Theorem 3.8. Unfortunately, this falls short of proving Theorem 1.1 because the term might dominate the encoding size; consequently, we must develop an alternative for cases where this term is prohibitively large.
Workaround.
Note that , so holds as long as or . Thus, the critical scenario arises when and . Not coincidentally, we also proved in Lemma 3.19, which lets us derive in this case. This condition characterizes one of the two fundamental structural results for PMwE from [5]: in a setting (almost) identical to ours, there is a primitive string with such that the edit distance between and a prefix of does not exceed . Moreover, [5, Theorem 5.2] upper-bounds the distance between and a prefix of by . The subsequent characterization in [5, Section 5] implies that, for every -error occurrence of , there exists an exact occurrence of in that is matched perfectly both in the alignment from to the prefix of and in the alignment from via to a fragment of .
Our workaround is to initialize so that the periodic structure of essentially coincides with the structure induced by . Namely, every black component corresponds to a position and consists of all characters of and that the alignments with prefixes of match with characters of the form for . By Lemma 3.10 and the above characterization of -error occurrences, this guarantees that all -error occurrences are captured by . To achieve such , we include in alignments for the two approximate occurrences of as a prefix and a suffix of , and a third -edit alignment that, for every , aligns the th copy of in with the th copy of in . This yields the following lemma proved in the full version.
Lemma 3.20.
Suppose that , that there are -error occurrences of appearing as both a prefix and a suffix of , and that there is a primitive string with and . Then, we can construct a set of at most three -edit alignments of onto fragments of such that, when the notions of succinctly enclosing and capturing are interpreted with threshold , all of the following hold:
-
1.
succinctly encloses ,
-
2.
captures all -error occurrences of in ,
-
3.
the set together with all starting/ending points of the alignments in can be encoded in bits.
4 Lower Bound
Theorem 1.3. [Restated, see original statement.]
Fix integers with and an input alphabet with and . Consider an encoding that, for each fragment with , allows to reconstruct an edit sequence and the corresponding edit information. Such an encoding must use bits for and some .
Proof.
Set and , where are strings that contain at most characters from and all remaining characters are equal to . Clearly, for every . Moreover, for every , there is a unique optimal alignment that performs substitutions exactly in the positions where the non-zero characters appear (it is not difficult to verify that any deletions or insertions would increase the cost). Thus, allows us to fully recover from the edit information , and consequently can be fully recovered.
Finally, the number of possibilities for each block is . If , then this quantity is at least , and the standard estimate yields for and for . Otherwise, the sum contains the term . If , then this term is simply . If , then the term is at least . In either case, we have when . Therefore, the number of possibilities for is .
References
- [1] Arturs Backurs and Piotr Indyk. Edit distance cannot be computed in strongly subquadratic time (unless SETH is false). SIAM Journal on Computing, 2018. doi:10.1137/15M1053128.
- [2] Sudatta Bhattacharya and Michal Koucký. Streaming -edit approximate pattern matching via string decomposition. In 50th International Colloquium on Automata, Languages, and Programming, ICALP 2023, 2023. doi:10.4230/LIPIcs.ICALP.2023.22.
- [3] Philip Bille, Gad M. Landau, Rajeev Raman, Kunihiko Sadakane, Srinivasa Rao Satti, and Oren Weimann. Random access to grammar-compressed strings and trees. SIAM Journal on Computing, 2015. doi:10.1137/130936889.
- [4] Alejandro Cassis, Tomasz Kociumaka, and Philip Wellnitz. Optimal algorithms for bounded weighted edit distance. In 64th IEEE Annual Symposium on Foundations of Computer Science, FOCS 2023, 2023. doi:10.1109/FOCS57990.2023.00135.
- [5] Panagiotis Charalampopoulos, Tomasz Kociumaka, and Philip Wellnitz. Faster approximate pattern matching: A unified approach. In 61st IEEE Annual Symposium on Foundations of Computer Science, FOCS 2020, 2020. doi:10.1109/FOCS46700.2020.00095.
- [6] Panagiotis Charalampopoulos, Tomasz Kociumaka, and Philip Wellnitz. Faster pattern matching under edit distance: A reduction to dynamic puzzle matching and the seaweed monoid of permutation matrices. In 63rd IEEE Annual Symposium on Foundations of Computer Science, FOCS 2022, 2022. doi:10.1109/FOCS54457.2022.00072.
- [7] Panagiotis Charalampopoulos, Tomasz Kociumaka, and Philip Wellnitz. Pattern matching under weighted edit distance, 2025. Accepted at FOCS 2025. doi:10.48550/arXiv.2510.17752.
- [8] Raphaël Clifford, Tomasz Kociumaka, and Ely Porat. The streaming -mismatch problem. In 30th Annual ACM-SIAM Symposium on Discrete Algorithms, SODA 2019, 2019. doi:10.1137/1.9781611975482.68.
- [9] Richard Cole and Ramesh Hariharan. Approximate string matching: A simpler faster algorithm. SIAM Journal on Computing, 2002. doi:10.1137/S0097539700370527.
- [10] Nathan J. Fine and Herbert S. Wilf. Uniqueness theorems for periodic functions. Proceedings of the American Mathematical Society, 1965. doi:10.1090/S0002-9939-1965-0174934-9.
- [11] Paweł Gawrychowski and Damian Straszak. Beating in approximate LZW-compressed pattern matching. In 24th International Symposium on Algorithms and Computation, ISAAC 2013, LNCS, 2013. doi:10.1007/978-3-642-45030-3_8.
- [12] Daniel Gibney, Ce Jin, Tomasz Kociumaka, and Sharma V. Thankachan. Near-optimal quantum algorithms for bounded edit distance and Lempel-Ziv factorization. In 35th ACM-SIAM Symposium on Discrete Algorithms, SODA 2023, 2024. doi:10.1137/1.9781611977912.11.
- [13] Tomasz Kociumaka, Jakob Nogler, and Philip Wellnitz. On the communication complexity of approximate pattern matching. In Proceedings of the 56th Annual ACM Symposium on Theory of Computing, STOC 2024, 2024. doi:10.1145/3618260.3649604.
- [14] Tomasz Kociumaka, Jakob Nogler, and Philip Wellnitz. On the communication complexity of approximate pattern matching, 2024. doi:10.48550/arXiv.2403.18812.
- [15] Tomasz Kociumaka, Jakob Nogler, and Philip Wellnitz. Near-optimal-time quantum algorithms for approximate pattern matching. In Yossi Azar and Debmalya Panigrahi, editors, Proceedings of the 2025 Annual ACM-SIAM Symposium on Discrete Algorithms, SODA 2025, New Orleans, LA, USA, January 12-15, 2025, pages 517–534. SIAM, 2025. doi:10.1137/1.9781611978322.15.
- [16] Tomasz Kociumaka, Jakob Nogler, and Philip Wellnitz. The communication complexity of pattern matching with edits revisited, 2026. arXiv:2604.15601.
- [17] Tomasz Kociumaka, Ely Porat, and Tatiana Starikovskaya. Small-space and streaming pattern matching with edits. In 62nd IEEE Annual Symposium on Foundations of Computer Science, FOCS 2021, 2021. doi:10.1109/FOCS52979.2021.00090.
- [18] Michal Koucký and Michael Saks. Almost linear size edit distance sketch. In 56th Annual ACM Symposium on the Theory of Computing; STOC 2024, 2024.
- [19] Gad M. Landau and Uzi Vishkin. Fast string matching with differences. Journal of Computer and System Sciences, 1988. doi:10.1016/0022-0000(88)90045-1.
- [20] Gad M. Landau and Uzi Vishkin. Fast parallel and serial approximate string matching. Journal of Algorithms, 1989. doi:10.1016/0196-6774(89)90010-2.
- [21] Vladimir Iosifovich Levenshtein. Binary codes capable of correcting deletions, insertions and reversals. Doklady Akademii Nauk SSSR, 1965.
- [22] Peter H. Sellers. The theory and computation of evolutionary distances: Pattern recognition. Journal of Algorithms, 1980. doi:10.1016/0196-6774(80)90016-4.
- [23] Tatiana Starikovskaya. Communication and streaming complexity of approximate pattern matching. In 28th Annual Symposium on Combinatorial Pattern Matching, CPM 2017, 2017. doi:10.4230/LIPIcs.CPM.2017.13.
- [24] Alexander Tiskin. Threshold approximate matching in grammar-compressed strings. In Prague Stringology Conference, PSC 2014, 2014. URL: http://www.stringology.org/event/2014/p12.html.
- [25] Jacob Ziv and Abraham Lempel. A universal algorithm for sequential data compression. IEEE Transactions on Information Theory, 1977. doi:10.1109/TIT.1977.1055714.
