Abstract 1 Introduction 2 Preliminaries333In this section, we partially follow the narration of [8, 15]. 3 ~𝓞(𝒌𝟐)-Time Updates after ~𝓞(𝒏𝒌)-Time Preprocessing 4 Trade-Off Algorithm: Technical Overview 5 Lower Bounds: Technical Overview References

Bounded Weighted Edit Distance

Itai Boneh ORCID Reichman University, Herzliya, Israel
University of Haifa, Israel
Egor Gorbachev ORCID Saarland University and Max Planck Institute for Informatics, Saarland Informatics Campus, Saarbrücken, Germany Tomasz Kociumaka ORCID Max Planck Institute for Informatics, Saarland Informatics Campus, Saarbrücken, Germany
Abstract

The edit distance 𝖾𝖽(X,Y) of two strings X,YΣ is the minimum number of character edits (insertions, deletions, and substitutions) needed to transform X into Y. Its weighted counterpart 𝖾𝖽w(X,Y) minimizes the total cost of edits, where the costs of individual edits, depending on the edit type and the characters involved, are specified using a function w, normalized so that each edit costs at least one. The textbook dynamic-programming procedure, given strings X,YΣn and oracle access to w, computes 𝖾𝖽w(X,Y) in 𝒪(n2) time. Nevertheless, one can achieve better running times if the computed distance, denoted k, is small: 𝒪(n+k2) for unit weights [Landau and Vishkin; JCSS’88] and ~𝒪(n+nk3)111Henceforth, the ~𝒪() notation hides factors poly-logarithmic in n. for arbitrary weights [Cassis, Kociumaka, Wellnitz; FOCS’23].

In this paper, we study the dynamic version of the weighted edit distance problem, where the goal is to maintain 𝖾𝖽w(X,Y) for strings X,YΣn that change over time, with each update specified as an edit in X or Y. Very recently, Gorbachev and Kociumaka [STOC’25] showed that the unweighted distance 𝖾𝖽(X,Y) can be maintained in ~𝒪(k) time per update after ~𝒪(n+k2)-time preprocessing; here, k denotes the current value of 𝖾𝖽(X,Y). Their algorithm generalizes to small integer weights, but the underlying approach is incompatible with large weights.

Our main result is a dynamic algorithm that maintains 𝖾𝖽w(X,Y) in ~𝒪(k3γ) time per update after ~𝒪(nkγ)-time preprocessing. Here, γ[0,1] is a real trade-off parameter and k1 is an integer threshold fixed at preprocessing time, with returned whenever 𝖾𝖽w(X,Y)>k. We complement our algorithm with conditional lower bounds showing fine-grained optimality of our trade-off for γ[0.5,1) and justifying our choice to fix k.

We also generalize our solution to a much more robust setting while preserving the fine-grained optimal trade-off. Our full algorithm maintains XΣn subject not only to character edits but also substring deletions and copy-pastes, each supported in ~𝒪(k2) time. Instead of dynamically maintaining Y, it answers queries that, given any string Y specified through a sequence of 𝒪(k) arbitrary edits transforming X into Y, in ~𝒪(k3γ) time compute 𝖾𝖽w(X,Y) or report that 𝖾𝖽w(X,Y)>k.

Keywords and phrases:
Edit distance, dynamic algorithms, conditional lower bounds
Funding:
Itai Boneh: supported by Israel Science Foundation grant 810/21.
Egor Gorbachev: This work is part of the project TIPEA that has received funding from the European Research Council (ERC) under the European Unions Horizon 2020 research and innovation programme (grant agreement No. 850979).
Copyright and License:
[Uncaptioned image] © Itai Boneh, Egor Gorbachev, and Tomasz Kociumaka; licensed under Creative Commons License CC-BY 4.0
2012 ACM Subject Classification:
Theory of computation Pattern matching
Related Version:
Full Version: https://arxiv.org/abs/2507.02548v1 [6]
Editors:
Anne Benoit, Haim Kaplan, Sebastian Wild, and Grzegorz Herman

1 Introduction

Among the most fundamental string processing problems is the task of deciding whether two strings are similar to each other. A classic measure of string (dis)similarity is the edit distance, also known as the Levenshtein distance [22]. The (unit-cost) edit distance 𝖾𝖽(X,Y) of two strings X and Y is defined as the minimum number of character edits (insertions, deletions, and substitutions) needed to transform X into Y. In typical use cases, edits model naturally occurring modifications, such as typographical errors in natural-language texts or mutations in biological sequences. Some of these changes occur more frequently than others, which motivated introducing weighted edit distance already in the 1970s [33]. In this setting, each edit has a cost that may depend on its type and the characters involved (but nothing else), and the goal is to minimize the total cost of edits rather than their quantity. The costs of individual edits can be specified through a weight function w:Σ¯20, where Σ¯=Σ{ε} denotes the alphabet extended with a symbol ε representing the lack of a character. For a,bΣ, the cost of inserting b is w(ε,b), the cost of deleting a is w(a,ε), and the cost of substituting a for b is w(a,b). (Note that the cost of an edit is independent of the position of the edited character in the string.) Consistently with previous works, we assume that w is normalized: w(a,b)1 and w(a,a)=0 hold for every distinct a,bΣ¯. The unweighted edit distance constitutes the special case when w(a,b)=1 holds for ab.

The textbook dynamic-programming algorithm [32, 25, 26, 33] takes 𝒪(n2) time to compute the edit distance of two strings of length at most n, and some of its original formulations incorporate weights [26, 33, 27]. Unfortunately, there is little hope for much faster solutions: for any constant δ>0, an 𝒪(n2δ)-time algorithm would violate the Orthogonal Vectors Hypothesis [1, 7, 2, 5], and hence the Strong Exponential Time Hypothesis [16, 17]. The lower bound holds already for unit weights and many other fixed weight functions [7].

Bounded Edit Distance.

On the positive side, the quadratic running time can be improved when the computed distance is small. For unweighted edit distance, the algorithm by Landau and Vishkin [21], building upon the ideas of [30, 24], computes k𝖾𝖽(X,Y) in 𝒪(n+k2) time for any two strings X,YΣn. This running time is fine-grained optimal: for any δ>0, a hypothetical 𝒪(n+k2δ)-time algorithm, even restricted to instances satisfying k=Θ(nκ) for some constant κ(0.5,1], would violate the Orthogonal Vectors Hypothesis.

As far as the bounded weighted edit distance problem is concerned, a simple optimization by Ukkonen [30] improves the quadratic time complexity of the classic dynamic-programming algorithm to 𝒪(nk), where k𝖾𝖽w(X,Y). Recently, Das, Gilbert, Hajiaghayi, Kociumaka, and Saha [12] developed an 𝒪(n+k5)-time solution and, soon afterwards, Cassis, Kociumaka, and Wellnitz [8] presented an ~𝒪(n+nk3)-time algorithm. Due to the necessity to read the entire input, the latter running time is optimal for kn3. More surprisingly, there is a tight conditional lower bound for nkn [8], valid already for edit costs in the real interval [1,2]. For any constants κ[0.5,1] and δ>0, an 𝒪(nk3δ)-time algorithm restricted to instances satisfying k=Θ(nκ) would violate the All-Pairs Shortest Paths Hypothesis [31]. The optimal complexity remains unknown for n3<k<n, where the upper bound is ~𝒪(nk3), yet the lower-bound construction allows for an ~𝒪(n+k2.5)-time algorithm.

Dynamic Edit Distance.

Over the last decades, the edit distance problem has been studied in numerous variants, including the dynamic ones, where the input strings change over time. The most popular dynamic (weighed) edit distance formulation is the following one [9, 15].

Problem 1.1 (Dynamic Weighted Edit Distance).

Given an integer n and oracle access to a normalized weight function w:Σ¯20, maintain strings X,YΣn subject to updates (character edits in X and Y) and report 𝖾𝖽w(X,Y) after each update.222For clarity, the introduction focuses on the version of the problem where the value 𝖾𝖽w(X,Y) is reported after every update. In Theorem 1.7, we address a more general setting where queries may occur less frequently, allowing us to distinguish between update time and query time.

The time complexity of ˜1.1 is already well understood if it is measured solely in terms of the string length n. In case of unit weights, the algorithm of Charalampopoulos, Kociumaka, and Mozes [9] (building upon the techniques by Tiskin [28]) is characterized by ~𝒪(n) update time and 𝒪(n2) preprocessing time; any polynomial-factor improvement would violate the lower bound for the static edit distance problem. As far as arbitrary weights are concerned, the approach presented in [9, Section 4] achieves ~𝒪(nn) update time after ~𝒪(n2)-time preprocessing, and there is a matching fine-grained lower bound [8, Section 6] conditioned on the All-Pairs Shortest Paths Hypothesis.

In this work, we aim to understand ˜1.1 for small distances:

How fast can one dynamically maintain 𝖾𝖽w(X,Y) when this value is small?

Very recently, Gorbachev and Kociumaka [15] settled the parameterized complexity of ˜1.1 in the unweighted case. Their solution achieves ~𝒪(n+k2) preprocessing time and ~𝒪(k) update time; improving either complexity by a polynomial factor, even for instances satisfying k=Θ(nκ) for some κ(0,1], would violate the Orthogonal Vectors Hypothesis.

Interestingly, the approach of [15] builds upon the static procedure for bounded weighted edit distance [8] and, as a result, the dynamic algorithm seamlessly supports small integer weights, achieving 𝒪(W2k) update time for edit costs in [1..W]. Unfortunately, [15] does not provide any improvements for arbitrary weights; in that case, the results of [8] yield a solution to ˜1.1 with ~𝒪(n) preprocessing time and ~𝒪(min(k3,nk3)) update time. This is far from satisfactory: for kn3, the algorithm simply recomputes 𝖾𝖽w(X,Y) from scratch after every update, and for k<n3, it does not store (and reuse) anything beyond a dynamic data structure for checking the equality between fragments of X and Y.

Our Results: Lower Bounds

The reason why the approach of [15] is incompatible with large weights, e.g., W=Ω(k), is that their presence allows a single update to drastically change 𝖾𝖽w(X,Y). Our first result strengthens the lower bound of [8] and shows that the ~𝒪(n+nk3)-time static algorithm is fine-grained optimal already for instances that can be transformed from a pair of equal strings using four edits. The ideas behind the following theorem are presented in Section 5.

Theorem 1.2.

Let κ[0.5,1] and δ>0 be real parameters. Assuming the APSP Hypothesis, there is no algorithm that, given two strings X,YΣn satisfying 𝖾𝖽(X,Y)4, a threshold knκ, and oracle access to a normalized weight function w:Σ¯20, in time 𝒪(n0.5+1.5κδ) decides whether 𝖾𝖽w(X,Y)k.

As a simple corollary, we conclude that significantly improving upon the naïve update time of ~𝒪(nk3) for nkn requires large preprocessing time.

Corollary 1.3.

Suppose that ˜1.1 admits a solution with preprocessing time TP(n,𝖾𝖽w(X,Y)) and update time TU(n,𝖾𝖽w(X,Y)) for some non-decreasing functions TP and TU. If TP(n,0)=𝒪(n0.5+1.5κδ) and TU(n,nκ)=𝒪(n0.5+1.5κδ) hold for some real parameters κ[0.5,1] and δ>0, then the APSP Hypothesis fails.

Proof idea..

For an instance (X,Y) of the static problem of Theorem 1.2, we initialize the dynamic algorithm with (X,X) and transform one copy of X into Y using four updates.

As discussed in the full version of the paper [6], instead of initializing the dynamic algorithm with (X,X), we can initialize it with a pair of empty strings and gradually transform this instance to (X,X) using 𝒪(n) updates while keeping the weighted edit distance between 0 and 2 at all times. Hence, as long as the preprocessing of (ε,ε) takes n𝒪(1) time and is not allowed to access the entire weight function (e.g., weights are revealed online when an update introduces a fresh character for the first time) , we can replace TP(n,0)=𝒪(n0.5+1.5κδ) with TU(n,2)=𝒪(n1.5κ0.5δ) in the statement of Corollary 1.3.

Overall, we conclude that, in order to support updates with relatively large distances faster than naively (i.e., by computing 𝖾𝖽w(X,Y) from scratch using a static algorithm), one needs to pay a lot for both preprocessing and updates while 𝖾𝖽w(X,Y) is still very small. In particular, we should decide in advance how large distances need to be supported efficiently. This justifies a simplified variant of ˜1.1, where the parameter k is fixed at preprocessing time. Here, instead of 𝖾𝖽w(X,Y), the algorithm reports the following quantity:

𝖾𝖽kw(X,Y)={𝖾𝖽w(X,Y)if 𝖾𝖽w(X,Y)k,otherwise.
Problem 1.4 (Dynamic Weighted Edit Distance with Fixed Threshold).

Given integers 1kn and oracle access to a normalized weight function w:Σ¯20, maintain strings X,YΣn subject to updates (character edits in X and Y) and report 𝖾𝖽kw(X,Y) upon each update.

Corollary 1.3 can be rephrased in terms of ˜1.4, but its major limitation is that it only applies to kn. To overcome this issue, we compose multiple hard instances from Theorem 1.2. This results in the following theorem, discussed in Section 5.

Theorem 1.5.

Suppose that ˜1.4 admits a solution with preprocessing time TP(n,k) and update time TU(n,k) for some non-decreasing functions TP and TU. If TP(n,nκ)=~𝒪(n1+κγ) and TU(n,nκ)=𝒪(nκ(3γ)δ) hold for some parameters γ[0.5,1), κ(0,1/(32γ)], and δ>0, then the APSP Hypothesis fails.

Theorem 1.5 indicates that (conditioned on the APSP Hypothesis and up to subpolynomial-factor improvements), for a dynamic algorithm with preprocessing time ~𝒪(nkγ) for γ[0.5,1), the best possible update time is ~𝒪(k3γ). The lower bound does not extend to κ>1/(32γ); precisely then, the ~𝒪(nk3)-time static algorithm improves upon the ~𝒪(k3γ) update time.

Our Results: Algorithms

Our main positive result is an algorithm that achieves the fine-grained-optimal trade-off.

Theorem 1.6.

There exists an algorithm that, initialized with an extra real parameter γ[0,1], solves ˜1.4 with preprocessing time ~𝒪(nkγ) and update time ~𝒪(k3γ).

As a warm-up, in Section 3, we prove Theorem 1.6 for γ=1. Similarly to [15], the main challenge is that updates can make X and Y slide with respect to each other. If we interleave insertions at the end of Y and deletions at the beginning of Y, then, after Ω(k) updates, for every character X[i], the fragment Y[ik..i+k] containing the plausible matches of X[i] changes completely. The approach of [15] was to restart the algorithm every Θ(k) updates.

Our preprocessing time is too large for this, so we resort to a trick originating from dynamic edit distance approximation [20]: we maintain a data structure for aligning X with itself. Instead of storing Y, we show how to compute 𝖾𝖽kw(X,Y) for any string Y specified using 𝒪(k) edits (of arbitrary costs) transforming X into Y. To find such edits in the original setting of ˜1.4, one can use a dynamic unweighted edit distance algorithm. Already the folklore approach, based on [21, 23], with ~𝒪(k2) time per update is sufficiently fast.

In Section 4, we discuss how to generalize our dynamic algorithm to arbitrary γ[0,1]. This is our most difficult result – it requires combining the techniques of [8] and their subsequent adaptations in [15] with several new ideas, including a novel shifted variant of self-edit distance. We derive Theorem 1.6 as a straightforward corollary of the following result, which demonstrates that the same fine-grained optimal trade-off can be achieved in a much more robust setting compared to the one presented in ˜1.4.

Theorem 1.7.

There is a dynamic algorithm that, initialized with a real parameter γ[0,1], integers 1kn, and 𝒪(1)-time oracle access to a normalized weight function w:Σ¯20, maintains a string XΣn and, after ~𝒪(nkγ)-time preprocessing, supports the following operations (updates and queries):

  • Apply a character edit, substring deletion, or copy-paste to X in ~𝒪(k2) time.

  • Given u edits transforming X into a string Y, compute 𝖾𝖽kw(X,Y) in ~𝒪(u+k3γ) time.

We remark that our query algorithm for γ=1 extends a subroutine of [11], where the string X is static. In [11], this result is used for approximate pattern matching with respect to weighted edit distance. If the pattern is far from periodic, which is arguably true in most natural instances, the trade-off of Theorem 1.7 yields a faster pattern matching algorithm.

Open Problems

Recall that Theorem 1.5 proves fine-grained optimality of Theorem 1.6 only for γ[0.5,1). The omission of γ[0,0.5) stems from a gap between algorithms and lower bounds for the underlying static problem. Hence, we reiterate the open question of [8] asking for the complexity of computing 𝖾𝖽w(X,Y) when n3<𝖾𝖽w(X,Y)<n. Since our lower bounds arise from Theorem 1.2, it might be instructive to first try designing faster algorithms for the case of 𝖾𝖽(X,Y)4. Before this succeeds, one cannot hope for faster dynamic algorithms.

Wider gaps in our understanding of ˜1.4 remain in the regime of large preprocessing time. It is open to determine the optimal update time for γ=1 and to decide whether γ>1 can be beneficial. As far as γ=1 is concerned, we believe that [9, Section 4] can be used to obtain ~𝒪(kn) update time, which improves upon Theorem 1.6 for kn. Moreover, by monotonicity, the lower bound of [8, Section 6] excludes update times of the form 𝒪(k1.5δ).

Finally, we remark that all our lower bounds exploit the fact that 𝖾𝖽w(X,Y) can change a lot as a result of a single update. It would be interesting to see what can be achieved if the weights are small (but fractional) or when the update time is parameterized by the change in 𝖾𝖽w(X,Y). In these cases, we hope for non-trivial applications of the approach of [15].

2 Preliminaries333In this section, we partially follow the narration of [8, 15].

A string XΣn is a sequence of |X|n characters over an alphabet Σ. We denote the set of all strings over Σ by Σ, we use ε to represent the empty string, and we write Σ+Σ{ε}. For a position i[0..n), we say that X[i] is the i-th character of X. We say that a string X occurs as a substring of a string Y, if there exist indices i,j[0..|Y|] satisfying ij such that X=Y[i]Y[j1]. The occurrence of X in Y specified by i and j is a fragment of Y denoted by Y[i..j), Y[i..j1], Y(i1..j1], or Y(i1..j).

Weighted Edit Distances and Alignment Graphs

Given an alphabet Σ, we set Σ¯Σ{ε}. We call w a normalized weight function if w:Σ¯×Σ¯1{0} and, for a,bΣ¯, we have w(a,b)=0 if and only if a=b. Note that w does not need to satisfy the triangle inequality nor does w need to be symmetric.

We interpret weighted edit distances of strings as distances in alignment graphs.

Definition 2.1 (Alignment Graph, [8]).

For strings X,YΣ and a normalized weight function w:Σ¯20, we define the alignment graph 𝖠𝖦w(X,Y) to be a weighted directed graph with vertices [0..|X|]×[0..|Y|] and the following edges:

  • a horizontal edge (x,y)(x+1,y) of cost w(X[x],ε) representing a deletion of X[x], for every (x,y)[0..|X|)×[0..|Y|],

  • a vertical edge (x,y)(x,y+1) of cost w(ε,Y[y]) representing an insertion of Y[y], for every (x,y)[0..|X|]×[0..|Y|), and

  • a diagonal edge (x,y)(x+1,y+1) of cost w(X[x],Y[y]) representing a substitution of X[x] into Y[y] or, if X[x]=Y[y], a match of X[x] with Y[y], for every (x,y)[0..|X|)×[0..|Y|).

We visualize the graph 𝖠𝖦w(X,Y) as a grid graph with |X|+1 columns and |Y|+1 rows, where (0,0) and (|X|,|Y|) are the top-left and bottom-right vertices, respectively.

Alignments between fragments of X and Y can be interpreted as paths in 𝖠𝖦w(X,Y).

Definition 2.2 (Alignment).

Consider strings X,YΣ and a normalized weight function w:Σ¯20. An alignment 𝒜 of X[x..x) onto Y[y..y), denoted 𝒜:X[x..x)[Uncaptioned image]Y[y..y), is a path from (x,y) to (x,y) in 𝖠𝖦w(X,Y), often interpreted as a sequence of vertices. The cost of 𝒜, denoted by 𝖾𝖽𝒜w(X[x..x),Y[y..y)), is the total cost of edges belonging to 𝒜.

The weighted edit distance of strings X,YΣ with respect to a weight function w is 𝖾𝖽w(X,Y)min𝖾𝖽𝒜w(X,Y) where the minimum is taken over all alignments 𝒜 of X onto Y. An alignment 𝒜 of X onto Y is w-optimal if 𝖾𝖽𝒜w(X,Y)=𝖾𝖽w(X,Y).

We say that an alignment 𝒜 of X onto Y aligns fragments X[x..x) and Y[y..y) if (x,y),(x,y)𝒜. In this case, we also denote the cost of the induced alignment (the subpath of 𝒜 from (x,y) to (x,y)) by 𝖾𝖽𝒜w(X[x..x),Y[y..y)).

A normalized weight function satisfying w(a,b)=1 for distinct a,bΣ¯ gives the unweighted edit distance (Levenshtein distance [22]). In this case, we drop the superscript w.

Definition 2.3 (Augmented Alignment Graph, [15]).

For strings X,YΣ and a weight function w:Σ¯2[0,W], the augmented alignment graph 𝖠𝖦¯w(X,Y) is obtained from 𝖠𝖦w(X,Y) by adding, for every edge of 𝖠𝖦w(X,Y), a back edge of weight W+1.555These edges ensure that 𝖠𝖦¯w(X,Y) is strongly connected, and thus the distance matrices used throughout this work are Monge matrices (see Definition 2.11) rather than so-called partial Monge matrices.

The following fact shows several properties of 𝖠𝖦¯w(X,Y). Importantly, 𝖾𝖽w(X[x..x),Y[y..y)) is the distance from (x,y) to (x,y) in 𝖠𝖦¯w(X,Y).

Fact 2.4 ([15, Lemma 5.2]).

Consider strings X,YΣ and a weight function w:Σ¯2[0,W]. Every two vertices (x,y) and (x,y) of the graph 𝖠𝖦¯w(X,Y) satisfy the following properties:

Monotonicity.

Every shortest path from (x,y) to (x,y) in 𝖠𝖦¯w(X,Y) is (weakly) monotone in both coordinates.

Distance preservation.

If xx and yy, then

𝖽𝗂𝗌𝗍𝖠𝖦¯w(X,Y)((x,y),(x,y))=𝖽𝗂𝗌𝗍𝖠𝖦w(X,Y)((x,y),(x,y)).
Path irrelevance.

If (xx and yy) or (xx and yy), then every path from (x,y) to (x,y) in 𝖠𝖦¯w(X,Y) monotone in both coordinates is a shortest path between these two vertices.

Consistently with many edit-distance algorithms, we will often compute not only the distance from (0,0) to (|X|,|Y|) in 𝖠𝖦¯w(X,Y) but the entire boundary distance matrix 𝖡𝖬w(X,Y) that stores the distances from every input vertex on the top-left boundary to every output vertex on the bottom-right boundary of the graph 𝖠𝖦¯w(X,Y).

Definition 2.5 (Input and Output Vertices of an Alignment Graph, [15, Definition 5.5]).

Let X,YΣ be two strings and w:Σ¯2[0,W] be a weight function. Furthermore, for fragments X[x..x) and Y[y..y), let R=[x..x]×[y..y] be the corresponding rectangle in 𝖠𝖦¯w(X,Y). We define the input vertices of R as the sequence of vertices of 𝖠𝖦¯w(X,Y) on the left and top boundary of R in the clockwise order. Analogously, we define the output vertices of R as a sequence of vertices of 𝖠𝖦¯w(X,Y) on the bottom and right boundary of R in the counterclockwise order. Furthermore, the input and output vertices of X×Y are the corresponding boundary vertices of the whole graph 𝖠𝖦¯w(X,Y).

Definition 2.6 (Boundary Distance Matrix, [15, Definition 5.6]).

Let X,YΣ be two strings and w:Σ¯2[0,W] be a weight function. The boundary distance matrix 𝖡𝖬w(X,Y) of X and Y with respect to w is a matrix M of size (|X|+|Y|+1)×(|X|+|Y|+1), where Mi,j is the distance from the i-th input vertex to the j-th output vertex of X×Y in 𝖠𝖦¯w(X,Y).

The following fact captures the simple dynamic programming algorithm for bounded weighted edit distance.

Fact 2.7 ([15, Fact 3.3]).

Given strings X,YΣ, an integer k1, and 𝒪(1)-time oracle access to a normalized weight function w:Σ¯20, the value 𝖾𝖽kw(X,Y) can be computed in 𝒪(min(|X|+1,|Y|+1)min(k,|X|+|Y|+1)) time. Furthermore, if 𝖾𝖽w(X,Y)k, the algorithm returns a w-optimal alignment of X onto Y.

The proof of Fact 2.7 relies on the fact that a path of length k can visit only a limited area of the alignment graph 𝖠𝖦w(X,Y). This property can be formalized as follows:

Fact 2.8 ([15, Lemma 5.3]).

Let X,YΣ be two strings, k be an integer, and w:Σ¯20 be a normalized weight function. Consider a path P of cost at most k connecting (x,y) to (x,y) in 𝖠𝖦¯w(X,Y). All vertices (x,y)P satisfy |(xy)(xy)|k and |(xy)(xy)|k.

The breakpoint representation of an alignment 𝒜=(xt,yt)t=0m of X onto Y is the subsequence of 𝒜 consisting of pairs (xt,yt) such that t{0,m} or 𝒜 does not match X[xt] with Y[yt]. Note that the size of the breakpoint representation is at most 2+𝖾𝖽𝒜(X,Y) and that it can be used to retrieve the entire alignment and its cost: for any two consecutive elements (x,y),(x,y) of the breakpoint representation, it suffices to add (xδ,yδ) for δ(0..max(xx,yy)). We will also talk of breakpoint representations of paths in 𝖠𝖦¯w(X,Y) that are weakly monotone in both coordinates. If such a path starts in (x,y) and ends in (x,y) with xx and yy, then the breakpoint representation of such a path is identical to the breakpoint representation of the corresponding alignment. Otherwise, if x>x or y>y, we call the breakpoint representation of such a path a sequence of all its vertices; recall that all edges in such a path have strictly positive weights.

Planar Graphs, the Monge Property, and Min-Plus Matrix Multiplication

As alignment graphs are planar, we can use the following tool of Klein.

Fact 2.9 (Klein [19]).

Given a directed planar graph G of size n with non-negative edge weights, we can construct in 𝒪(nlogn) time a data structure that, given two vertices u,vV(G) at least one of which lies on the outer face of G, computes the distance 𝖽𝗂𝗌𝗍G(u,v) in 𝒪(logn) time. Moreover, the data structure can report the shortest uv path P in 𝒪(|P|loglogΔ(G)) time, where Δ(G) is the maximum degree of G.

The following lemma specifies a straightforward variation of Klein’s algorithm tailored for path reconstruction in alignment graphs.

Lemma 2.10.

Given strings X,YΣ+ and 𝒪(1)-time access to a normalized weight function w:Σ¯2[0,W], we can construct in 𝒪(|X||Y|log2(|X|+|Y|)) time a data structure that, given two vertices u,v𝖠𝖦¯w(X,Y) at least one of which lies on the outer face of 𝖠𝖦¯w(X,Y), computes the distance 𝖽𝗂𝗌𝗍𝖠𝖦¯w(X,Y)(u,v) in 𝒪(log(|X|+|Y|)) time. Moreover, the breakpoint representation of a shortest uv path can be constructed in 𝒪((1+𝖽𝗂𝗌𝗍𝖠𝖦¯w(X,Y)(u,v))log2(|X|+|Y|)) time.

Proof.

The data structure we build is recursive. We first build the data structure of Klein’s algorithm (Fact 2.9) for 𝖠𝖦¯w(X,Y), and then if |X|>1, recurse onto (X[0..|X|/2),Y) and (X[|X|/2..|X|),Y). Preprocessing costs 𝒪(|X||Y|log2(|X|+|Y|)) time. For distance queries, the top-level instance of Klein’s algorithm is sufficient. It remains to answer path reconstruction queries. We reconstruct the shortest uv path recursively. First, in 𝒪(log(|X|+|Y|)) time we query 𝖽𝗂𝗌𝗍𝖠𝖦¯w(X,Y)(u,v). If the distance is 0, we return the breakpoint representation of the trivial shortest uv path. Otherwise, we make further recursive calls. If u and v both lie in X[0..|X|/2)×Y or both lie in X[|X|/2..|X|)×Y, by the monotonicity property of Fact 2.4 we can recurse onto the corresponding small recursive data structure instance. Otherwise, every uv path contains a vertex (x,y) with x=|X|/2. Furthermore, due to Fact 2.8, there are 𝒪(𝖽𝗂𝗌𝗍𝖠𝖦¯w(X,Y)(u,v)) possible values for y. In 𝒪(𝖽𝗂𝗌𝗍𝖠𝖦¯w(X,Y)(u,v)log(|X|+|Y|)) time we query 𝖽𝗂𝗌𝗍𝖠𝖦¯w(X,Y)(u,(x,y)) and 𝖽𝗂𝗌𝗍𝖠𝖦¯w(X,Y)((x,y),v) using the smaller recursive data structure instances and find some y satisfying 𝖽𝗂𝗌𝗍𝖠𝖦¯w(X,Y)(u,v)=𝖽𝗂𝗌𝗍𝖠𝖦¯w(X,Y)(u,(x,y))+𝖽𝗂𝗌𝗍𝖠𝖦¯w(X,Y)((x,y),v). We then recursively find the breakpoint representations of the optimal u(x,y) path and the optimal (x,y)v path in the smaller recursive data structure instances. There are 𝒪(log(|X|+1)) recursive levels, on each one of them our total work is 𝒪((1+𝖽𝗂𝗌𝗍𝖠𝖦¯w(X,Y)(u,v))log(|X|+|Y|)); thus, the total time complexity is 𝒪((1+𝖽𝗂𝗌𝗍𝖠𝖦¯w(X,Y)(u,v))log2(|X|+|Y|)).

As discussed in [13, Section 2.3] and [15, Fact 3.7 and Section 5.1], the planarity of alignment graphs implies that the 𝖡𝖬w(X,Y) matrices satisfy the following Monge property:

Definition 2.11 (Monge Matrix).

A matrix A of size p×q is a Monge matrix if, for all i[0..p1) and j[0..q1), we have Ai,j+Ai+1,j+1Ai,j+1+Ai+1,j.

In the context of distance matrices, concatenating paths corresponds to the min-plus product of matrices; this operation preserves Monge property and can be evaluated fast.

Fact 2.12 (Min-Plus Matrix Product, SMAWK Algorithm [3], [29, Theorem 2]).

Let A and B be matrices of size p×q and q×r, respectively. Their min-plus product is a matrix ABC of size p×r such that Ci,k=minjAi,j+Bj,k for all i[0..p) and k[0..r).

If A and B are Monge matrices, then C is also a Monge matrix. Moreover, C can be constructed in 𝒪(pr+min(pq,qr)) time assuming 𝒪(1)-time random access to A and B.

3 ~𝓞(𝒌𝟐)-Time Updates after ~𝓞(𝒏𝒌)-Time Preprocessing

In this section, we present a dynamic algorithm that maintains 𝖾𝖽kw(X,Z) for two dynamic strings X,ZΣn with ~𝒪(nk) preprocessing time and ~𝒪(k2) update time. As all vertical and horizontal edges cost at least 1, the relevant part of the graph 𝖠𝖦¯w(X,Z) has size 𝒪(nk) (i.e., a band of width Θ(k) around the main diagonal), and thus we can afford to preprocess this part of 𝖠𝖦¯w(X,Z). Nevertheless, the curse of dynamic algorithms for bounded weighted edit distance is that, after Θ(k) updates (e.g., Θ(k) character deletions from the end of Z and Θ(k) character insertions at the beginning of Z), the preprocessed part of the original graph 𝖠𝖦¯w(X,Z) can be completely disjoint from the relevant part of the updated graph 𝖠𝖦¯w(X,Z), which renders the original preprocessing useless. To counteract this challenge, we use the idea from [20]: we dynamically maintain information about 𝖠𝖦¯w(X,X) instead of 𝖠𝖦¯w(X,Z). Every update to X now affects both dimensions of 𝖠𝖦¯w(X,X), so the relevant part of the graph does not shift anymore, and hence our preprocessing does not expire. Tasked with computing 𝖾𝖽kw(X,Z) upon a query, we rely on the fact that, unless 𝖾𝖽kw(X,Z)=, the graph 𝖠𝖦¯w(X,Z) is similar to 𝖠𝖦¯w(X,X).

Consistently with the previous works [8, 15], we cover the relevant part of 𝖠𝖦¯w(X,X) with m=𝒪(n/k) rectangular subgraphs Gi of size Θ(k)×Θ(k) each; see Figure 1. We preprocess each subgraph in ~𝒪(k2) time. A single update to X alters a constant number of subgraphs Gi, so we can repeat the preprocessing for such subgraphs in ~𝒪(k2) time. The string Z does not affect any subgraph Gi; we only store it in a dynamic strings data structure supporting efficient substring equality queries for the concatenation XZ.

Let Vi for i[1..m) be the set of vertices in the intersection of Gi and Gi+1; see Figure 1. Furthermore, let V0{(0,0)} and Vm{(|X|,|X|)}. Let G be the union of all graphs Gi. Let Di,j for i,j[0..m] with i<j denote the matrix of pairwise distances from Vi to Vj in G. Note that Da,c=Da,bDb,c holds for all a,b,c[0..m] with a<b<c.

Figure 1: The decomposition of the alignment graph of X onto X into subgraphs Gi of size Θ(k)×Θ(k) that cover the whole stripe of width Θ(k) around the main diagonal. Each matrix Di,i+1 represents the pairwise distances from Vi to Vi+1.

Upon a query for 𝖾𝖽w(X,Z), we note that only 𝒪(𝖾𝖽(X,Z)) subgraphs Gi in 𝖠𝖦¯w(X,X) differ from the corresponding subgraphs in 𝖠𝖦¯w(X,Z). (If 𝖾𝖽(X,Z)>k, then 𝖾𝖽kw(X,Z)=, so we can assume that 𝖾𝖽(X,Z)k.) We call such subgraphs affected. Let Gi, Vi, and Di,j be the analogs of Gi, Vi, and Di,j in 𝖠𝖦¯w(X,Z). Note that if 𝖾𝖽w(X,Z)k, then 𝖾𝖽w(X,Z) is the only entry of the matrix D0,m. Furthermore, we have D0,m=D0,1Dm1,m. We compute this product from left to right. For unaffected subgraphs Gi, we have Di1,i=Di1,i, and we can use precomputed information about 𝖠𝖦¯w(X,X). To multiply by Di1,i for affected subgraphs Gi, we use the following lemma, the proof of which can be found in the full version of the paper [6].

Lemma 3.1 (Generalization of [11, Claim 4.2]).

Let X,YΣ+ be nonempty strings and w:Σ¯2[0,W] be a weight function. Given 𝒪(1)-time oracle access to w, the strings X and Y can be preprocessed in 𝒪(|X||Y|log2(|X|+|Y|)) time so that, given a string YΣ and a vector v of size |X|+|Y|+1, the row vT𝖡𝖬w(X,Y) can be computed in 𝒪((𝖾𝖽(Y,Y)+1)(|X|+|Y|)log(|X|+|Y|)) time. Furthermore, given an input vertex a and an output vertex b of X×Y, the shortest path from a to b in 𝖠𝖦¯w(X,Y) can be computed in the same time complexity.

There are 𝖾𝖽(X,Z) edits that transform 𝖠𝖦¯w(X,X) into 𝖠𝖦¯w(X,Z), and each edit affects a constant number of subgraphs Gi. Therefore, applying Lemma 3.1 for all affected subgraphs takes time ~𝒪(k2) in total. Between two consecutive affected subgraphs Gi and Gj, we have Di,j1=Di,j1, and thus it is sufficient to store some range composition data structure over (Di,i+1)i=0m1 to quickly propagate between subsequent affected subgraphs.

As the information we maintain dynamically regards 𝖠𝖦¯w(X,X) and does not involve the string Z, we may generalize the problem we are solving. All we need upon a query is an alignment of X onto Z of unweighted cost at most k. Such an alignment can be obtained, for example, from a dynamic bounded unweighted edit distance algorithm [15] in ~𝒪(k) time per update. Alternatively, it is sufficient to have ~𝒪(1)-time equality tests between fragments of X and Z. In this case, we can run the classical Landau–Vishkin [21] algorithm from scratch after every update in ~𝒪(k2) time to either get an optimal unweighted alignment or learn that 𝖾𝖽w(X,Z)𝖾𝖽(X,Z)>k. Efficient fragment equality tests are possible in a large variety of settings [10] including the dynamic setting [23, 4, 14, 18], so we will not focus on any specific implementation. Instead, we assume that the string Z is already given as a sequence of uk edits of an unweighted alignment transforming X into Z, and our task is to find a w-optimal alignment. We are now ready to formulate the main theorem of this section.

Theorem 3.2.

There is a dynamic data structure that, given a string XΣ, a threshold k1, and 𝒪(1)-time oracle access to a normalized weight function w:Σ¯20, can be initialized in 𝒪((|X|+1)klog2(|X|+2)) time and allows for the following operations:

  • Apply a character edit to X in 𝒪(k2log2(|X|+2)) time.

  • Given uk edits transforming X into a string ZΣ, compute 𝖾𝖽kw(X,Z) in 𝒪(k(u+log(|X|+2))log(|X|+2)) time. Furthermore, if 𝖾𝖽w(X,Z)k, the algorithm returns the breakpoint representation of a w-optimal alignment of X onto Z.

Proof Sketch.

At the initialization phase, we decompose 𝖠𝖦¯w(X,X) into subgraphs Gi and, for each subgraph Gi, initialize the algorithm of Lemma 3.1 and compute Di1,i using Lemma 2.10. We also build a dynamic range composition data structure over (Di,i+1)i=0m1, implemented as a self-balancing binary tree. Given a range [a..b), in 𝒪(logn) time, this data structure returns (pointers to) =𝒪(logn) matrices S1,,S such that Da,b=S1S.

When an update to X comes, it affects a constant number of subgraphs Gi, which we locally adjust and recompute the initialization for in ~𝒪(k2) time.

Upon a query, we are tasked with computing D0,1Dm1,m. We locate the 𝒪(u) affected subgraphs Gi and process them one-by-one. We use Lemma 3.1 to multiply the currently computed row vT=D0,1Di2,i1 by Di1,i. The algorithm then uses the range composition data structure over (Di,i+1)i=0m1 to obtain =𝒪(logn) matrices S1,,S that correspond to the segment of matrices between the current affected subgraph Gi and the next affected subgraph Gj. We use SMAWK algorithm (Fact 2.12) to multiply vT by matrices S1,,S. After processing all the matrices, we obtain D0,1Dm1,m, the only entry of which is equal to 𝖾𝖽w(X,Z) if 𝖾𝖽kw(X,Z). The applications of Lemma 3.1 work in 𝒪(kulogn) time in total. Each of the 𝒪(u) blocks of unaffected subgraphs is treated by invoking SMAWK algorithm (Fact 2.12) 𝒪(logn) times for a total of 𝒪(kulogn) time.

See the full version of the paper [6] for a formal proof including the alignment reconstruction procedure. We complete this section with a simple corollary improving the query time if 𝖾𝖽w(X,Z)k.

Corollary 3.3.

There is a dynamic data structure that, given a string XΣ, a threshold k1, and 𝒪(1)-time oracle access to a normalized weight function w:Σ¯20 can be initialized in 𝒪((|X|+1)klog2(|X|+2)) time and allows for the following operations:

  • Apply a character edit to X in 𝒪(k2log2(|X|+2)) time.

  • Given uk edits transforming X into a string ZΣ, compute 𝖾𝖽kw(X,Z) in 𝒪(1+(u+d)(u+log(|X|+2))log(|X|+2)) time, where dmin(𝖾𝖽w(X,Z),k). Furthermore, if 𝖾𝖽w(X,Z)k, the algorithm returns the breakpoint representation of a w-optimal alignment of X onto Z.

Proof.

We maintain the data structures of Theorem 3.2 for thresholds 1,2,4,,2logk. Upon a query, we query the data structures for subsequent thresholds starting from 2logu until we get a positive result or reach 2logk.

As discussed earlier, in a variety of settings, upon a query, in ~𝒪(k2) time we can compute an optimal unweighted alignment of X onto Z or learn that 𝖾𝖽w(X,Z)𝖾𝖽(X,Z)>k. Therefore, we may assume that whenever Corollary 3.3 is queried, we have u=𝖾𝖽(X,Z)k. In this case, the query time complexity can be rewritten as 𝒪(1+min(𝖾𝖽w(X,Z),k)(𝖾𝖽(X,Z)+log(|X|+2))log(|X|+2)).

Due to the robustness of the setting of Corollary 3.3, there are many problems beyond dynamic weighted edit distance that can be solved using Corollary 3.3. For example, given strings X,Y0,,Ym1Σn, we can find 𝖾𝖽kw(X,Yi) for all i[0..m) in ~𝒪(nm+nk+mk2) time, compared to ~𝒪(m(n+nk3)) time arising from m applications of the optimal static algorithm [8].

4 Trade-Off Algorithm: Technical Overview

In the full version of the paper [6], we generalize the result of Theorem 3.2 in two ways. First, we extend the set of updates the string X supports from character edits to block edits, which include substring deletions and copy-pastes. More importantly, rather than having ~𝒪(nk) preprocessing time and ~𝒪(k2) query time, we allow for a complete trade-off matching the lower bound of Theorem 1.5, i.e., ~𝒪(nkγ) preprocessing and ~𝒪(k3γ) update time for any γ[0,1].

A major challenge for γ<1 is that we cannot preprocess the whole width-Θ(k) band around the main diagonal of 𝖠𝖦¯w(X,X). In the proof of Theorem 3.2, we cover the band with Θ(k)×Θ(k)-sized subgraphs Gi and preprocess each of them in ~𝒪(k2) time for a total of ~𝒪(nk). To achieve ~𝒪(nkγ)-time preprocessing, we are forced to instead use Θ(k2γ)×Θ(k2γ)-sized subgraphs Gi and still spend just ~𝒪(k2) preprocessing time per subgraph.

To remedy the shortage of preprocessing time, we use the ideas behind the recent static algorithms [8, 15]. At the expense of a logarithmic-factor slowdown, they allow us to answer queries only for “repetitive” fragments of X rather than the whole X. More precisely, we are tasked to answer queries involving fragments X^ of X satisfying 𝗌𝖾𝗅𝖿-𝖾𝖽(X^)k, where the self-edit distance 𝗌𝖾𝗅𝖿-𝖾𝖽(X^) is the minimum unweighted cost of an alignment of X^ onto itself that does not match any character of X^ with itself. We can use this to our advantage: the subgraphs Gi corresponding to more “repetitive” fragments Xi allow for more thorough preprocessing in ~𝒪(k2) time since we can reuse some computations. On the other hand, upon a query, we can afford to spend more time on subgraphs Gi with less “repetitive” fragments Xi as their number is limited due to 𝗌𝖾𝗅𝖿-𝖾𝖽(X^)k.

This approach requires the repetitiveness measure to be super-additive: i𝗌𝖾𝗅𝖿-𝖾𝖽(Xi)𝗌𝖾𝗅𝖿-𝖾𝖽(X^). Unfortunately, self-edit distance is sub-additive: i𝗌𝖾𝗅𝖿-𝖾𝖽(Xi)𝗌𝖾𝗅𝖿-𝖾𝖽(X^). To circumvent this issue, we introduce a better-suited notion of repetitiveness we call k-shifted self-edit distance 𝗌𝖾𝗅𝖿-𝖾𝖽k(X^): a relaxed version of 𝗌𝖾𝗅𝖿-𝖾𝖽(X^) allowed to delete up to k first characters of X^ and insert up to k last characters of X^ for free. In contrast to self-edit distance, the k-shifted variant 𝗌𝖾𝗅𝖿-𝖾𝖽k satisfies i𝗌𝖾𝗅𝖿-𝖾𝖽k(Xi)𝗌𝖾𝗅𝖿-𝖾𝖽(X^) if 𝗌𝖾𝗅𝖿-𝖾𝖽(X^)k.

By using the value of 𝗌𝖾𝗅𝖿-𝖾𝖽k(Xi) to determine the level of preprocessing performed on Gi, upon a query, similarly to Theorem 3.2, we have 𝒪(k) “interesting” subgraphs Gi (subgraphs that are either affected by the input edits or satisfy 𝗌𝖾𝗅𝖿-𝖾𝖽k(Xi)>0) that we process one-by-one in time ~𝒪((ui+𝗌𝖾𝗅𝖿-𝖾𝖽k(Xi))k2γ) each using a generalization of Lemma 3.1. The super-additivity property of 𝗌𝖾𝗅𝖿-𝖾𝖽k guarantees that this sums up to a total of ~𝒪(k3γ). The remaining subgraphs Gi are not affected by the input edits and satisfy 𝗌𝖾𝗅𝖿-𝖾𝖽k(Xi)=0, which means that Xi has a period of at most k. For such subgraphs Gi, we can afford the complete preprocessing and, upon a query, processing such subgraphs in chunks in ~𝒪(k2) time in total precisely as in the proof of Theorem 3.2. Furthermore, similarly to Theorem 3.2, all the information the data structure stores is either local or cumulative, and thus block edits can be supported straightforwardly. This rather simple high-level approach runs into several low-level technical complications that are discussed in detail in the full version of the paper [6].

5 Lower Bounds: Technical Overview

As discussed in Section 1, our conditional lower bounds stem from the following result: See 1.2

The reduction provided in [8] is insufficient because the instances it produces satisfy 𝖾𝖽(X,Y)=Θ(k) rather than 𝖾𝖽(X,Y)4. Still, we reuse hardness of the following problem:

Problem 5.1 (Batched Weighted Edit Distance [8]).

Given a batch of strings X1,,XmΣx, a string YΣy, a threshold k0, and oracle access to a weight function w:Σ¯20, decide if mini=1m𝖾𝖽w(Xi,Y)k.

The hard instances of ˜5.1, which cannot be solved in 𝒪(x2δm) time for any δ>0 assuming the APSP Hypothesis, satisfy many technical properties, including hmaxi=1m1𝗁𝖽(Xi,Xi+1)=𝒪(x/m), where 𝗁𝖽(Xi,Xi+1) is the Hamming distance, i.e., the number of positions in which Xi differs from Xi+1.

The approach of [8, Section 7] is to construct strings X¯ and Y¯ that take the following form if we ignore some extra gadgets: X¯=X1YX2Xm1YXm and Y¯=X0YX1Xm1YXm, where XiΣx is chosen so that 𝖾𝖽w(Xi,Xi1)=𝖾𝖽w(Xi,Xi)=h. The ignored gadgets let us focus on alignments 𝒜i:X¯[Uncaptioned image]Y¯ that satisfy the following properties for i[1..m]:

  • the fragment Xi is aligned with the copy of Y in Y¯ located between Xi1 and Xi;

  • the m1 copies of Y in X¯ are matched with the remaining m1 copies of Y in Y¯;

  • all the characters within the fragments Xi1 and Xi of Y¯ are inserted;

  • for ji, the fragment Xj is aligned with Xj1 if j<i and with Xj if j>i.

This ensures that the cost of 𝒜i is equal to a baseline cost (independent of i) plus 𝖾𝖽w(Xi,Y).

Our reduction uses three types of “X gadgets”: Xi, Xi, and Xi, with the latter two playing similar roles. We also introduce a new symbol $ that is extremely expensive to delete, insert, or substitute with any other symbol. Modulo some extra gadgets, our strings are of the following form:

X~ =X0YX0Y$i=1m1(XiYXiYXiY)XmYXmYXm$,
Y~ =$X0YX0Yi=1m1(XiYXiYXiY)XmYXm$YXm.

Notice that removing the two $ symbols from X~ or from Y~ results in the same string, so we have 𝖾𝖽(X~,Y~)4. Due to the expensive cost for editing a $, any optimal alignment must match the two $ symbols in X~ with the two $ symbols in Y~, deleting a prefix of X~ and a suffix of Y~ for some predictable cost. Thus, we can focus our analysis on 𝖾𝖽w(X^,Y^), where

X^=X1YX1YX1YXmYXmYXmandY^=X0YX0YX1YXm1YXmYXm.

Observe that both X^ and Y^ consists of “X gadgets” interleaved with Y, and that Y^ contains one more copy of Y and one more “X gadget”. Analogously to [8], the ignored extra gadgets let us focus on the alignments 𝒜i:X^[Uncaptioned image]Y^ satisfying the following properties for i[1..m]:

  • the fragment Xi in X^ is aligned with the copy of Y in Y^ located between Xi1 and Xi1;

  • the 3m1 copies of Y in X^ are matched with the remaining 3m1 copies of Y in Y^;

  • all characters within the fragments Xi1 and Xi1 of Y^ are inserted;

  • the remaining “X gadgets” in X^ are aligned with the remaining “X gadgets” in Y^.

To perfectly mimic [8], we should ensure that all the “X gadgets” that we can possibly align are at weighted edit distance h. We only managed to construct Xi and Xi so that:

  • 𝖾𝖽w(Xi,Xi1)=𝖾𝖽w(Xi,Xi1)=𝖾𝖽w(Xi,Xi)=𝖾𝖽w(Xi,Xi)=2h, and

  • 𝖾𝖽w(Xi,Xi1)=𝖾𝖽w(Xi,Xi)=4h.

Although we have two different distances between the relevant pairs of “X gadgets”, it is easy to see the number of pairs of either type is constant across all the alignments 𝒜i. This is sufficient to guarantee that the cost of 𝒜i is equal to some baseline cost plus 𝖾𝖽w(Xi,Y). Moreover, as in [8], the costs of alignments 𝒜i is 𝒪(x+mh)=𝒪(x) and, if we denote n|X~|=|Y~|, then the lower bound derived from the lower bound for ˜5.1 excludes running times of the form 𝒪(x2δm)=𝒪(x2δn/x)=𝒪(nx32δ).

Lower Bounds for Dynamic Weighed Edit Distance

From Theorem 1.2 we derive two dynamic lower bounds, each justifying a different limitation of our algorithm given in Theorem 1.6. Our first lower bound, formalized in the following lemma and proved in the full version of the paper [6], concerns our choice to fix a threshold k at the preprocessing phase. If, instead, we aimed for time complexities depending on the current value of 𝖾𝖽w(X,Y), then, for sufficiently large values of 𝖾𝖽w(X,Y), we could not achieve update times improving upon the static algorithm.

Lemma 5.2.

Consider the following dynamic problem: Given an integer n1 and 𝒪(1)-time oracle access to a normalized weight function w:Σ¯20, maintain two initially empty strings X,YΣn that throughout the lifetime of the algorithm satisfy 𝖾𝖽(X,Y)4 subject to updates (character edits) and output 𝖾𝖽w(X,Y) after every update. Suppose that there is an algorithm that solves this problem with TP(n) preprocessing and TU(n,𝖾𝖽w(X,Y)) update time, where TU is non-decreasing. If TP(n)=𝒪(n0.5+1.5κδ), TU(n,2)=𝒪(n1.5κ0.5δ), and TU(n,nκ)=𝒪(n0.5+1.5κδ) hold for some real parameters κ[0.5,1] and δ>0, then the APSP Hypothesis fails.

Our second dynamic lower bound justifies the specific trade-off between the preprocessing and update time in Theorem 1.6. In simple words, we prove that, with preprocessing time ~𝒪(nkγ) for γ[0.5,1), the best possible update time is 𝒪(k3γo(1)). For that, we note that Theorem 1.2 is based on a reduction from the Negative Triangle problem, which is self-reducible: solving m instances of bounded weighted edit distance from Theorem 1.2 is hence, in general, m times harder than solving a single instance. Given such m instances (X0,Y0),,(Xm1,Ym1), we initialize a dynamic algorithm with a pair of equal strings X^=Y^=i=0m1(Xi), where is an auxiliary symbol that is very expensive to edit. For i[0..m), in 𝖾𝖽(Xi,Yi)=𝒪(1) updates, we can transform the fragment Xi of Y^ into Yi and retrieve 𝖾𝖽kw(X^,Y^)=𝖾𝖽kw(Xi,Yi). By applying and reverting these updates for every i[0..m), we can thus find 𝖾𝖽kw(Xi,Yi) for all i. If we pick mn/k32γ2δ for an arbitrary small constant δ>0, then the static lower bound requires m((n/m)k3)1o(1)(nkγ+δ)1o(1) total time. Our preprocessing time is asymptotically smaller, so, among 𝒪(m) updates, some must take Ω(((n/m)k3)1o(1))=Ω(k3γδo(1)) time. See the full version of the paper [6] for a formal proof.

References

  • [1] Amir Abboud, Arturs Backurs, and Virginia Vassilevska Williams. Tight hardness results for LCS and other sequence similarity measures. In FOCS 2015, pages 59–78. IEEE Computer Society, 2015. doi:10.1109/FOCS.2015.14.
  • [2] Amir Abboud, Thomas Dueholm Hansen, Virginia Vassilevska Williams, and Ryan Williams. Simulating branching programs with edit distance and friends: or: a polylog shaved is a lower bound made. In STOC 2016, pages 375–388. ACM, 2016. doi:10.1145/2897518.2897653.
  • [3] Alok Aggarwal, Maria M. Klawe, Shlomo Moran, Peter W. Shor, and Robert E. Wilber. Geometric applications of a matrix-searching algorithm. Algorithmica, 2:195–208, 1987. doi:10.1007/BF01840359.
  • [4] Stephen Alstrup, Gerth Stølting Brodal, and Theis Rauhe. Pattern matching in dynamic texts. In SODA 2000, pages 819–828. ACM/SIAM, 2000. URL: http://dl.acm.org/citation.cfm?id=338219.338645.
  • [5] Arturs Backurs and Piotr Indyk. Edit distance cannot be computed in strongly subquadratic time (unless SETH is false). SIAM J. Comput., 47(3):1087–1097, 2018. doi:10.1137/15M1053128.
  • [6] Itai Boneh, Egor Gorbachev, and Tomasz Kociumaka. Bounded weighted edit distance: Dynamic algorithms and matching lower bounds, 2025. arXiv:2507.02548v1.
  • [7] Karl Bringmann and Marvin Künnemann. Quadratic conditional lower bounds for string problems and dynamic time warping. In FOCS 2015, pages 79–97. IEEE Computer Society, 2015. doi:10.1109/FOCS.2015.15.
  • [8] Alejandro Cassis, Tomasz Kociumaka, and Philip Wellnitz. Optimal algorithms for bounded weighted edit distance. In FOCS 2023, pages 2177–2187. IEEE, 2023. doi:10.1109/FOCS57990.2023.00135.
  • [9] Panagiotis Charalampopoulos, Tomasz Kociumaka, and Shay Mozes. Dynamic string alignment. In CPM 2020, volume 161 of LIPIcs, pages 9:1–9:13. Schloss Dagstuhl – Leibniz-Zentrum für Informatik, 2020. doi:10.4230/LIPIcs.CPM.2020.9.
  • [10] Panagiotis Charalampopoulos, Tomasz Kociumaka, and Philip Wellnitz. Faster approximate pattern matching: A unified approach. In FOCS 2020, pages 978–989. IEEE, 2020. doi:10.1109/FOCS46700.2020.00095.
  • [11] Panagiotis Charalampopoulos, Tomasz Kociumaka, and Philip Wellnitz. Pattern matching under weighted edit distance. In FOCS 2025, 2025.
  • [12] Debarati Das, Jacob Gilbert, MohammadTaghi Hajiaghayi, Tomasz Kociumaka, and Barna Saha. Weighted edit distance computation: Strings, trees, and Dyck. In STOC 2023, STOC 2023, pages 377–390, New York, NY, USA, 2023. Association for Computing Machinery. doi:10.1145/3564246.3585178.
  • [13] Jittat Fakcharoenphol and Satish Rao. Planar graphs, negative weight edges, shortest paths, and near linear time. J. Comput. Syst. Sci., 72(5):868–889, 2006. doi:10.1016/j.jcss.2005.05.007.
  • [14] Paweł Gawrychowski, Adam Karczmarz, Tomasz Kociumaka, Jakub Łącki, and Piotr Sankowski. Optimal dynamic strings. In SODA 2018, pages 1509–1528. SIAM, 2018. doi:10.1137/1.9781611975031.99.
  • [15] Egor Gorbachev and Tomasz Kociumaka. Bounded edit distance: Optimal static and dynamic algorithms for small integer weights. In 57th Annual ACM Symposium on Theory of Computing, STOC 2025, pages 2157–2166, New York, NY, USA, 2025. Association for Computing Machinery. doi:10.1145/3717823.3718168.
  • [16] Russell Impagliazzo and Ramamohan Paturi. On the complexity of k-SAT. J. Comput. Syst. Sci., 62(2):367–375, 2001. doi:10.1006/jcss.2000.1727.
  • [17] Russell Impagliazzo, Ramamohan Paturi, and Francis Zane. Which problems have strongly exponential complexity? J. Comput. Syst. Sci., 63(4):512–530, 2001. doi:10.1006/jcss.2001.1774.
  • [18] Dominik Kempa and Tomasz Kociumaka. Dynamic suffix array with polylogarithmic queries and updates. In STOC 2022, pages 1657–1670. ACM, 2022. doi:10.1145/3519935.3520061.
  • [19] Philip N. Klein. Multiple-source shortest paths in planar graphs. In SODA, pages 146–155. SIAM, 2005. URL: http://dl.acm.org/citation.cfm?id=1070432.1070454.
  • [20] Tomasz Kociumaka, Anish Mukherjee, and Barna Saha. Approximating edit distance in the fully dynamic model. In FOCS 2023, pages 1628–1638. IEEE, 2023. doi:10.1109/FOCS57990.2023.00098.
  • [21] Gad M. Landau and Uzi Vishkin. Fast string matching with k differences. J. Comput. System Sci., 37(1):63–78, 1988. doi:10.1016/0022-0000(88)90045-1.
  • [22] Vladimir I. Levenshtein. Binary codes capable of correcting deletions, insertions and reversals. Dokl. Akad. Nauk SSSR, 163:845–848, 1965. URL: http://mi.mathnet.ru/eng/dan31411.
  • [23] Kurt Mehlhorn, Rajamani Sundar, and Christian Uhrig. Maintaining dynamic sequences under equality tests in polylogarithmic time. Algorithmica, 17:183–198, 1997. doi:10.1007/bf02522825.
  • [24] Eugene W. Myers. An 𝒪(ND) difference algorithm and its variations. Algorithmica, 1(2):251–266, 1986. doi:10.1007/BF01840446.
  • [25] Saul B. Needleman and Christian D. Wunsch. A general method applicable to the search for similarities in the amino acid sequence of two proteins. J. Mol. Biol., 48(3):443–453, 1970. doi:10.1016/b978-0-12-131200-8.50031-9.
  • [26] Peter H. Sellers. On the theory and computation of evolutionary distances. SIAM J. Appl. Math., 26(4):787–793, 1974. doi:10.1137/0126070.
  • [27] Peter H. Sellers. The theory and computation of evolutionary distances: Pattern recognition. J. Algorithms, 1(4):359–373, 1980. doi:10.1016/0196-6774(80)90016-4.
  • [28] Alexander Tiskin. Semi-local string comparison: Algorithmic techniques and applications. Math. Comput. Sci., 1(4):571–603, 2008. doi:10.1007/s11786-007-0033-3.
  • [29] Alexander Tiskin. Fast distance multiplication of unit-Monge matrices. Algorithmica, 71(4):859–888, 2015. doi:10.1007/S00453-013-9830-Z.
  • [30] Esko Ukkonen. Finding approximate patterns in strings. J. Algorithms, 6(1):132–137, 1985. doi:10.1016/0196-6774(85)90023-9.
  • [31] Virginia Vassilevska Williams and R. Ryan Williams. Subcubic equivalences between path, matrix, and triangle problems. Journal of the ACM, 65(5):27:1–27:38, 2018. doi:10.1145/3186893.
  • [32] Taras K. Vintsyuk. Speech discrimination by dynamic programming. Cybernetics, 4(1):52–57, 1968. doi:10.1007/BF01074755.
  • [33] Robert A. Wagner and Michael J. Fischer. The string-to-string correction problem. J. ACM, 21(1):168–173, 1974. doi:10.1145/321796.321811.