Conceptio › Archive › arXiv CS
arXiv CS open access

Location-Aware Matching Statistics

Lorraine A. K. Ayad et al. · arxiv_cs
arXiv CS · Papers
Open Source ↗Direct PDF ↓
data-managementdatabasessqlstorage
Edit distance is the standard measure of string similarity, but its quadratic-time complexity is prohibitive for long strings. Popular linear-time alternatives, such as the $q$-gram distance, or the average common substring measure (ACS) that is based on matching statistics (MS), consider the substr
Conceptio Open Archive

Analyze & explore related research in Conceptio

Connect this record directly into your research workflow or AI agent. Explore citations across open repositories, query full text, and export structured proof bundles.

Location-Aware Matching Statistics Lorraine A. K. Ayad

1 , Grigorios Loukides

2 , and Solon P. Pissis

3

1 Brunel University of London, United Kingdom 2 King’s College London, United Kingdom

arXiv:2611.30206v1 [cs.DS] 23 Nov 2026

3 The Cyprus Institute, Nicosia, Cyprus

Abstract Edit distance is the standard measure of string similarity, but its quadratic-time complexity is prohibitive for long strings. Popular linear-time alternatives, such as the 𝑞-gram distance, or the average common substring measure (ACS) that is based on matching statistics (MS), consider the substrings shared by the two input strings but not where they occur in each string. Yet in many real-world applications, e.g., when comparing document versions or co-recorded time series, a shared substring is really relevant only if its occurrences are close in position. We introduce Location-Aware Matching Statistics (LAMAS). Given strings 𝑋 and 𝑌 and a displacement tolerance 𝑑, LAMAS reports, for every position 𝑖 of 𝑌 , the longest substring starting at 𝑖 that occurs in 𝑋 at a position 𝑗 with | 𝑗 − 𝑖| ≤ 𝑑, together with the displacement ( 𝑗 − 𝑖). MS is the special case of LAMAS with unbounded 𝑑. Our main result is an algorithm that solves LAMAS in O (𝑛) time and space for strings of length at most 𝑛 and any 𝑑; this is optimal and matches the complexity of MS. The algorithm reduces LAMAS to predecessor and successor queries over a sliding window of suffix ranks and answers them in linear total time via a window decomposition and interval union-find. Experiments on 20 real datasets and synthetic data show that LAMAS substantially improves over MS and 𝑞-gram distance in similarity-based classification, top-𝐾 retrieval, and clustering. It is competitive with edit distance and a constrained dynamic time warping variant in classification and generally outperforms a state-of-the-art method for top-𝐾 retrieval under edit distance. Finally, our implementation of the main algorithm for LAMAS scales linearly in 𝑛 and does not slow down as 𝑑 grows.

1

Introduction

Strings (i.e., sequences of elements over an alphabet) are a fundamental data type in domains ranging from databases [SKS20] and information retrieval [BR11] to bioinformatics [Gus97]. For example, time series are often discretized into strings over a small alphabet [PKS25, LKWL07], and DNA sequences are naturally represented as strings over the four-letter alphabet of nucleotides. Measuring the similarity of two strings is central to many real-world applications, such as top-𝐾 similarity search [ZZ20a, LPS23], record linkage [CRS20], clustering [Yan14], and classification [MRS08]. Perhaps the most common way to compare two strings is to compute their edit distance (ED), also known as the Levenshtein distance [Lev66]: the minimum number of character insertions, deletions, and substitutions required to transform one string into another. For two strings, each of length at most 𝑛, the classical dynamic-programming algorithm computes their ED in O (𝑛2 ) time [WF74]. Unfortunately, this upper bound has been improved only by polylogarithmic factors [CLZ03, BF08, Gra16], while conditional lower bounds suggest that no truly subquadratic algorithm exists [BI18, ABW15, BK15, AHWW16]. To bypass this quadratic barrier, many efficiently computable measures have been developed that compare the constituent patterns of the two strings, which we denote by 𝑋 and 𝑌 . The widely used 𝑞-gram distance [Ukk92] compares the frequencies of length-𝑞 substrings of 𝑋 and 𝑌 , while the average common substring (ACS) measure averages, over all positions of each string, the length of the longest substring starting at that position that also occurs in the other string [UBTC06]. Unlike ED, both measures can be computed in O (𝑛) time (cf. [Ukk92, CL90]). However, they capture only which patterns the two strings share, not where these patterns occur: an occurrence in 𝑋 contributes equally to ACS whether it lies close to the corresponding position of 𝑌 or far away from it.

1.1

Motivation

In many applications, positions in strings 𝑋 and 𝑌 are comparable, and the relevance of a shared pattern depends on where its occurrences are located. For example, when comparing two versions of a document to identify unchanged content [MM85], a shared phrase occurring near the same position is more informative than one appearing only in an unrelated section. Yet exact positional agreement is too restrictive, since insertions and deletions shift subsequent text. A similar issue arises for time series discretized into strings. Consider two stock-price series recorded over the same period and encoded as strings 𝑋 and 𝑌 . A shared rise-and-fall pattern in two stock-price series indicates similar behavior more strongly when it occurs at approximately the same time. In fact, allowing limited temporal shifts is well established in time-series matching. For example, the well-known dynamic time warping (DTW) [Keo02] measure aligns observations at different positions, while banded DTW restricts the alignment path to a band of radius 𝑑 around the diagonal [SC78], like the diagonal-band version of ED [Ukk85]. As for ED, the textbook O (𝑛2 )-time algorithm for DTW [SC78] has been improved only by a sub-logarithmic factor [GS18] and is unlikely to admit significant improvements [ABW15, BK15], whereas banded DTW takes O (𝑛𝑑) time. Positional constraints are also used in time-series database querying [FKLR05] and in string indexing, where pattern searches are confined to a specified text interval [MN06]. The following folklore observation underlies many algorithms for computing ED and justifies the above intuition; see Section 3 for the definition of alignments. Lemma 1.1 ([Ukk85]). Fix any alignment of 𝑋 and 𝑌 of cost at most 𝑘. If 𝑋 [ 𝑗] is aligned with 𝑌 [𝑖] (as a match or a substitution), then | 𝑗 − 𝑖| ≤ 𝑘. This leads to the central question of this work: Can we design a string-similarity measure based on shared patterns that takes the positions of these patterns into consideration and is still computable in linear time?

1

1.2

Our approach

To answer this question, we build on the matching statistics (MS) primitive [CL90, Gus97, LMP26], which underlies ACS, rather than on 𝑞-grams, because MS does not fix the length of the patterns: it maximizes the match length at every position of 𝑌 , capturing arbitrarily long matches. Formally, given two strings 𝑋 = 𝑋 [0 . . |𝑋 |) and 𝑌 = 𝑌 [0 . . |𝑌 |), the matching statistics of 𝑌 with respect to 𝑋 is the array MS𝑋 = MS𝑋 [0 . . |𝑌 |) defined, for all 𝑖 ∈ [0 . . |𝑌 |), by  MS𝑋 [𝑖] = max LCP 𝑋 [ 𝑗 . . |𝑋 |), 𝑌 [𝑖 . . |𝑌 |) , (1) 0≤ 𝑗<| 𝑋 |

where LCP(𝑈, 𝑉) denotes the length of the longest common prefix (LCP) of two strings 𝑈 and 𝑉. Intuitively, MS𝑋 [𝑖] is the length of the longest substring of 𝑌 that starts at position 𝑖 and occurs anywhere in 𝑋. The definition of the array MS𝑌 is analogous. Both arrays can be computed in O (|𝑋 | + |𝑌 |) time [CL90]. The ACS measure for 𝑋 and 𝑌 is defined as:1 ACS(𝑋, 𝑌 ) =

|𝑌 | −1 | 𝑋 | −1  1  1 ∑︁ 1 ∑︁ MS𝑋 [𝑖] + MS𝑌 [𝑖] . 2 |𝑌 | 𝑖=0 |𝑋 | 𝑖=0

The unrestricted choice of 𝑗 in Equation (1) allows a longer distant match to be selected instead of a shorter nearby one, which is undesirable when positions in the two strings are comparable. Moreover, simply discarding distant matches from the output of MS does not recover the best nearby match, since shorter alternatives are not reported. We therefore introduce Location-Aware Matching Statistics (LAMAS), which restricts the starting position of each match to lie within a displacement tolerance 𝑑 of the query position: for each position 𝑖 of 𝑌 , LAMAS finds the longest substring of 𝑌 starting at position 𝑖 that occurs in 𝑋 starting at a position 𝑗 with | 𝑗 − 𝑖| ≤ 𝑑, and returns its length ℓ𝑖 and displacement 𝛿𝑖 = 𝑗 − 𝑖. Problem 1 (LAMAS). Given two strings 𝑋 and 𝑌 , each of length at most 𝑛, and an integer 𝑑 ≥ 0, output, for every 𝑖 ∈ [0 . . |𝑌 |), a pair (ℓ𝑖 , 𝛿𝑖 ), where  ℓ𝑖 = max LCP 𝑋 [ 𝑗 . . |𝑋 |), 𝑌 [𝑖 . . |𝑌 |) 0≤ 𝑗<| 𝑋 | | 𝑗 −𝑖 | ≤𝑑

and 𝛿𝑖 = 𝑗 − 𝑖 for a position 𝑗 attaining this maximum (ties are broken arbitrarily). If no position 𝑗 ∈ [0 . . |𝑋 |) satisfies | 𝑗 − 𝑖| ≤ 𝑑, then ℓ𝑖 = 0 and 𝛿𝑖 is undefined. As for MS, we denote the array of lengths by LMS𝑋 , i.e., LMS𝑋 [𝑖] = ℓ𝑖 , and define LMS𝑌 analogously. Example 1.2. Let 𝑋 = abcdef and 𝑌 = defabc. The longest prefix of 𝑌 [0 . . 6) occurring in 𝑋 is def, at 𝑗 = 3, so MS𝑋 [0] = 3; similarly, MS𝑋 = MS𝑌 = (3, 2, 1, 3, 2, 1). For LAMAS with 𝑑 = 2, the admissible positions for 𝑖 = 0 are 𝑗 ∈ {0, 1, 2}, none of which starts with 𝑌 [0] = d, so LMS𝑋 [0] = 0. Likewise, every letter of 𝑌 occurs in 𝑋 only at displacement ±3, so LMS𝑋 = (0, 0, 0, 0, 0, 0), and (ℓ𝑖 , 𝛿𝑖 ) = (0, 0) for every 𝑖 is a valid output. The tolerance 𝑑 can be set from domain knowledge. In time series, it is the largest acceptable delay between corresponding events, as for the warping window of banded DTW [SC78]. When the strings are expected to be within ED 𝑘, as is the case for closely related DNA sequences, setting 𝑑 = 𝑘 ensures that every exact match of an alignment of cost at most 𝑘 starts at an admissible position (Lemma 1.1). When no such knowledge is available, 𝑑 can be estimated from a sample of the data (e.g., from the EDs of a few sampled pairs), or tuned on labeled validation data, as in our experiments (see Section 5.2). Example 1.3 shows, on real stock prices, where the timing of price movements matters [Mac97], that ignoring positions can invert a similarity ranking, and that LAMAS corrects it. 1We omit logarithmic correction terms from this formula for simplicity [UBTC06].

2

Z-normalized price

Apple

Microsoft

Displaced (shift 3)

Moderna Aligned (shift 0)

2 0 −2 Feb

Moderna Apple Microsoft

Apr

Jun

Feb

Apr

Jun

a a a a a a a a b b c c c d d d d d d d c c c b b a a a a b a b b c c c d d d d c c c b a a a a a b b c c c c c d d d d

Figure 1: Shared patterns in stock-price time series. Example 1.3. We discretize the daily adjusted closing prices of Apple, Microsoft, and Moderna stocks from 3 February to 30 June 2020 [Yah20] using SAX [LKLC03] into strings of length 𝑛 = 20 over 𝜎 = 4 letters, so that each letter spans about one trading week (Figure 1). Apple and Moderna share the long pattern abbcccdddd, but its occurrences are three positions (about three weeks) apart, whereas Apple and Microsoft share the shorter pattern cccdddd at the same position. Hence, ACS ranks Moderna more similar to Apple than Microsoft (4.35 vs. 3.85). Replacing MS in ACS with LAMAS at 𝑑 = 1 excludes the displaced match and reverses the ranking (1.425 vs. 3.1), as does using LAMAS at 𝑑 = 0 or 𝑑 = 2. This ranking agrees with the Pearson correlation of daily log returns, an established measure of stock co-movement [PGR+ 02]: 0.9374 for Apple–Microsoft versus only 0.0027 for Apple–Moderna. Example 1.4 shows that ACS based on MS can rate two strings as highly similar when their ED is maximal, whereas LAMAS avoids this when 𝑑 excludes the distant matches. Example 1.4. Let 𝑛 be divisible by 3, and consider 𝑋 = a𝑛/3 c𝑛/3 g𝑛/3

and 𝑌 = g𝑛/3 t𝑛/3 a𝑛/3 ,

where 𝑈 𝑘 denotes the concatenation of 𝑘 copies of string 𝑈. The ED of 𝑋 and 𝑌 is 𝑛, the maximum possible. Nevertheless, MS matches the shared blocks a𝑛/3 and g𝑛/3 , so ACS rates 𝑋 and 𝑌 as highly similar. In contrast, all shared letters lie more than 𝑛/3 positions apart, so for every 𝑑 ≤ 𝑛/3, we have LMS𝑋 [𝑖] = LMS𝑌 [𝑖] = 0 for all 𝑖, and so LAMAS reports no similarity at all, agreeing with the ED.

1.3

Contributions

In addition to introducing the LAMAS problem, our work makes the following contributions. A time-optimal algorithm for LAMAS. Standard string indexes support longest common extension (LCE) queries in O (1) time after O (𝑛)-time preprocessing [KSB06, KLA+ 01, BF00]. Thus, computing LAMAS by checking all O (𝑑) admissible positions in one string for each starting position in the other takes O (𝑛𝑑) total time. Our central contribution is an O (𝑛)-time and O (𝑛)-space algorithm for LAMAS. We observe that, for each starting position in one string, at most two admissible suffixes of the other need to be checked: the lexicographically nearest admissible suffix on either side of the query suffix (formally, the predecessor and successor of 𝑌 [𝑖 . . |𝑌 |) among suffixes of 𝑋 starting at positions 𝑗 with | 𝑗 − 𝑖| ≤ 𝑑). Maintaining their ranks in a balanced search tree as the admissible window slides yields a simple O (𝑛 log 𝑑)-time algorithm. We improve this algorithm by: • Reducing the search space. Each group of nearby queries involves only a small subset of the globally ordered suffixes. We exploit this locality by partitioning the queries into blocks and replacing global suffix ranks with local ranks, which preserves the answers while shrinking the search universe. This yields O (𝑛 log log 𝑑) time, and O (𝑛) time when 𝑑 = log O (1) 𝑛. 3

• Exploiting the window structure. Consecutive query windows overlap substantially and change predictably. Decomposing each window into a fixed part and two parts that shrink under suitable query orders lets us replace general-purpose dynamic search by sorted scans and interval unionfind [GT85], which process all queries in O (𝑛) total time, independently of 𝑑. Thus, we achieve optimal O (𝑛) time and O (𝑛) space, matching the asymptotic complexity of classical MS despite the additional displacement constraint and answering our central question in the affirmative. Experimental evaluation. We evaluate LAMAS on 20 real datasets and synthetic data, comparing it with MS, 𝑞-gram distance, ED, banded DTW [SC78], and MinSearch [ZZ20a], a state-of-the-art method for top-𝐾 retrieval under ED. We consider three common similarity-based tasks: (1) Pair classification. LAMAS outperforms MS on all 15 tested datasets, achieving a mean 𝐹1 of 0.7644, which is 9.2% and 8.7% higher than MS and 𝑞-gram distance, respectively. It also achieves effectiveness comparable to ED and banded DTW [SC78]. (2) Top-𝐾 retrieval. LAMAS outperforms MS and 𝑞-gram distance on all 15 tested datasets; its mean 𝐹1 @10 [MRS08] is 0.7516; 74.9%, 57%, and 15% higher than MS, 𝑞-gram distance, and MinSearch, respectively. It also achieves the highest mean retrieval effectiveness for 𝐾 ≥ 5. (3) Clustering. LAMAS outperforms MS and 𝑞-gram distance on four quality measures across two real datasets, improving ARI [HA85] by up to 146% and 154%, respectively. It also outperforms ED by up to 96% in ARI. Efficiency. Our LAMAS algorithm takes a similar time with MS and less memory on DNA sequencing datasets. It also scales linearly in 𝑛 and does not slow down as 𝑑 grows.

1.4

Paper organization

Section 2 discusses related work and Section 3 the preliminaries. Section 4 presents our LAMAS algorithm and Section 5 our experiments. Section 6 concludes the paper.

2

Related Work

Classical string-similarity measures. Classical string-similarity measures include Hamming distance, ED, longest common subsequence (LCS), and their variants; see [Nav01] for a survey. Hamming distance counts positional mismatches, while ED allows insertions, deletions, and substitutions. Damerau– Levenshtein distance additionally allows adjacent transpositions [Dam64]. LCS permits only insertions and deletions (gaps) [Hir75], whereas longest common substring [CKRP26] requires contiguity. Unlike these, LAMAS records, at each position, the longest exact match within a bounded displacement, providing an efficient, location-aware, proxy for ED-based similarity. Edit-distance embeddings and learned similarities. Metric embeddings map strings into Hamming space while approximately preserving ED [CGK16, CGKK18]. EmbedJoin uses such embeddings for edit-similarity joins [ZZ17]. Learning-based methods instead learn edit costs [RY98] or similarity representations [DYZ+ 20, LF22, LWYH25]. Unlike these methods, LAMAS requires no training, and, unlike the (randomized) embeddings, it is deterministic; however, it offers no formal ED approximation guarantees.

4

Alignment-free string measures. Alignment-free measures compare strings through shared or absent patterns. The 𝑞-gram distance compares substring frequencies [Ukk92], while its variant, threshold 𝑞-gram distance, caps multiplicities to reduce space [CFLM25]. 𝑞-gram-based distances are used in several bioinformatics tools, e.g., in [GIM+ 16, AP17]. Minimal-absent-word (MAW) measures compare absent patterns [CC12, CCF+ 18]. Matching statistics (MS) [CL94] is a widely used primitive; see [LMP26] for a recent survey. It also underpins software tools such as those in [ARK+ 21, ROL+ 22]. LAMAS generalizes MS by bounding the displacement between matching starting positions, which benefits multiple applications as we show experimentally, and it can be computed within the same (optimal) time complexity. Distances for time series. Time series can be compared using elastic measures, e.g., DTW [Keo02], and LCSS [VGK02]; see [HMB24] for a survey. Order-preserving matching statistics (OPMS) instead captures similarity in relative value order, enabling trend-based comparison [LZL+ 26]; this is orthogonal to LAMAS. Dynamic sub-sequence warping (DSSW) compares extracted numerical features [ZHD26]. Another popular way to compare time series is to first discretize them into strings, e.g., using SAX (symbolic aggregate approximation ) [LKWL07, LKLC03]. This reduces dimensionality and storage while enabling string-based processing. LAMAS operates on symbolic sequences, and, unlike these elastic measures, which require quadratic time to be computed in general, it can be computed in the optimal O (𝑛) time.

3

Preliminaries

Model of computation. Throughout this paper, we assume the standard word RAM model with machine words of 𝑤 = Ω(log 𝑛) bits, where 𝑛 is the total size of the input. Strings. For integers 𝑖 and 𝑗, we write [𝑖 . . 𝑗] for {𝑖, . . . , 𝑗 } and [𝑖 . . 𝑗) for {𝑖, . . . , 𝑗 − 1}; both are empty if 𝑖 > 𝑗, and [𝑖 . . 𝑗) = ∅ also if 𝑖 = 𝑗. An alphabet Σ is a finite totally ordered set, whose elements are called letters. We assume an integer alphabet Σ = [0 . . 𝜎) with 𝜎 = 𝑛 O (1) , so that letters fit in machine words. A string 𝑋 = 𝑋 [0] 𝑋 [1] · · · 𝑋 [|𝑋 | − 1] over Σ is a sequence of |𝑋 | letters, where |𝑋 | is its length; the empty string 𝜀 has length 0. For 0 ≤ 𝑖 ≤ 𝑗 ≤ |𝑋 |, the fragment 𝑋 [𝑖 . . 𝑗) is the string 𝑋 [𝑖] 𝑋 [𝑖 + 1] · · · 𝑋 [ 𝑗 − 1] (it is empty if 𝑖 = 𝑗), and we write 𝑋 [𝑖 . . 𝑗] for 𝑋 [𝑖 . . 𝑗 + 1). A fragment 𝑋 [0 . . 𝑗) is a prefix of 𝑋 and a fragment 𝑋 [𝑖 . . |𝑋 |) is a suffix of 𝑋; a prefix or suffix is proper if it differs from 𝑋. The concatenation of two strings 𝑈 and 𝑉 is denoted by 𝑈𝑉 A string 𝑊 occurs in 𝑋 at position 𝑖 if 𝑊 = 𝑋 [𝑖 . . 𝑖 + |𝑊 |). Lexicographic order and longest common prefixes. The longest common prefix (LCP) of two strings 𝑈 and 𝑉 is the longest string that is a prefix of both; we denote its length by LCP(𝑈, 𝑉). The lexicographic order ≺ on strings is defined by 𝑈 ≺ 𝑉 if and only if either 𝑈 is a proper prefix of 𝑉, or ℓ = LCP(𝑈, 𝑉) < min(|𝑈|, |𝑉 |) and 𝑈 [ℓ] < 𝑉 [ℓ]. We write 𝑈 ⪯ 𝑉 if 𝑈 ≺ 𝑉 or 𝑈 = 𝑉. We use Fact 3.1 extensively. Fact 3.1 ([MM93]). Let 𝑈 ⪯ 𝑉 ⪯ 𝑊 be strings. Then LCP(𝑈, 𝑊) = min{LCP(𝑈, 𝑉), LCP(𝑉, 𝑊)}. Edit distance  and alignments. An alignment of two strings 𝑋 and 𝑌 is a sequence (𝑢 1 , 𝑣 1 ), . . . , (𝑢 𝑧 , 𝑣 𝑧 ) of columns (𝑢 𝑡 , 𝑣 𝑡 ) ∈ (Σ ∪ {𝜀}) 2 \ {(𝜀, 𝜀)} such that 𝑢 1 𝑢 2 · · · 𝑢 𝑧 = 𝑋 and 𝑣 1 𝑣 2 · · · 𝑣 𝑧 = 𝑌 . A column (𝑢 𝑡 , 𝑣 𝑡 ) is a match if 𝑢 𝑡 = 𝑣 𝑡 , a substitution if 𝑢 𝑡 ≠ 𝑣 𝑡 and 𝑢 𝑡 , 𝑣 𝑡 ∈ Σ, a deletion if 𝑣 𝑡 = 𝜀, and an insertion if 𝑢 𝑡 = 𝜀. If (𝑢 𝑡 , 𝑣 𝑡 ) is a match or a substitution, with 𝑢 𝑡 = 𝑋 [ 𝑗] and 𝑣 𝑡 = 𝑌 [𝑖], we say that 𝑋 [ 𝑗] is aligned with 𝑌 [𝑖], and we call 𝑗 − 𝑖 the displacement of the column. Under unit costs, the cost of an alignment is its number of non-match columns, and the edit distance (or Levenshtein distance [Lev66]) ED(𝑋, 𝑌 ) is the minimum cost of an alignment of 𝑋 and 𝑌 .

5

𝑞-gram distance. The 𝑞-gram distance [Ukk92] is the ℓ1 distance between the occurrence-count vectors of all substrings of length 𝑞 in 𝑋 and 𝑌 . It can be computed in linear time [Ukk92]. Suffix array, inverse suffix array, and LCP array. Let 𝑆 be a string of length 𝑚 over an integer alphabet. All suffixes of 𝑆 are distinct, so the suffix array of 𝑆 is the unique permutation SA𝑆 [0 . . 𝑚) of [0 . . 𝑚) such that SA𝑆 [𝑟] is the starting position of the lexicographically 𝑟-th smallest suffix of 𝑆. The inverse suffix array iSA𝑆 [0 . . 𝑚) is defined by iSA𝑆 [ SA𝑆 [𝑟]] = 𝑟; thus iSA𝑆 [𝑖] is the rank of the suffix 𝑆[𝑖 . . 𝑚) among all suffixes of 𝑆, and 𝑆[𝑖 . . 𝑚) ≺ 𝑆[ 𝑗 . . 𝑚) if and only if iSA𝑆 [𝑖] < iSA𝑆 [ 𝑗]. The LCP array LCP𝑆 [0 . . 𝑚) stores the LCP lengths of lexicographically consecutive suffixes: LCP𝑆 [0] = 0 and  LCP𝑆 [𝑟] = LCP 𝑆[ SA𝑆 [𝑟 − 1] . . 𝑚), 𝑆[ SA𝑆 [𝑟] . . 𝑚) , for 𝑟 ∈ [1 . . 𝑚). The suffix array of a string of length 𝑚 over an integer alphabet of size 𝑚 O (1) can be constructed in O (𝑚) time [KSB06]; the inverse suffix array then follows in O (𝑚) time, and the LCP array can be computed in O (𝑚) time from 𝑆, SA𝑆 , and iSA𝑆 [KLA+ 01]. In Section 4, these arrays are built for the string 𝑆 = 𝑋#𝑌 , where # ∉ Σ is a sentinel letter, which we assume to be lexicographically larger than every letter of Σ; the alphabet of 𝑆 is thus [0 . . 𝜎] with # = 𝜎, and |𝑆| = |𝑋 | + |𝑌 | + 1. The suffix of 𝑆 starting at position |𝑋 | is the only suffix starting with #; every other suffix of 𝑆 starts either in 𝑋 (positions [0 . . |𝑋 |)) or in 𝑌 (positions [|𝑋 | + 1 . . |𝑆|)). Range minimum queries. Let 𝐴[0 . . 𝑚) be an array. A range minimum query RMQ 𝐴 (𝑖, 𝑗), for 0 ≤ 𝑖 ≤ 𝑗 < 𝑚, returns an index 𝑡 ∈ [𝑖 . . 𝑗] such that 𝐴[𝑡] = min 𝐴[𝑖 . . 𝑗] (ties are broken arbitrarily). After preprocessing 𝐴 in O (𝑚), any range minimum query (RMQ) can be answered in O (1) time [BF00]. Longest common extension queries. A longest common extension (LCE) query on a string 𝑆 of length 𝑚 asks, for two positions 𝑖, 𝑗 ∈ [0 . . 𝑚), for the value LCE𝑆 (𝑖, 𝑗) = LCP(𝑆[𝑖 . . 𝑚), 𝑆[ 𝑗 . . 𝑚)). By Fact 3.1 applied to the sorted sequence of suffixes, LCE queries reduce to RMQs on the LCP array: for 𝑖 ≠ 𝑗, letting 𝑟 = iSA𝑆 [𝑖] and 𝑠 = iSA𝑆 [ 𝑗] with 𝑟 < 𝑠 without loss of generality, LCE𝑆 (𝑖, 𝑗) = min LCP𝑆 [𝑟 + 1 . . 𝑠] = LCP𝑆 [𝑡 ∗ ], where 𝑡 ∗ = RMQLCP𝑆 (𝑟 + 1, 𝑠), while LCE𝑆 (𝑖, 𝑖) = 𝑚 − 𝑖. Hence, after an O (𝑚)-time preprocessing of 𝑆 (suffix array, inverse suffix array, LCP array, and the RMQ structure on it), every LCE query is answered in O (1) time; we refer to this combination as the LCE data structure of 𝑆. For 𝑆 = 𝑋#𝑌 , the LCE data structure also answers LCP queries between a suffix of 𝑋 and a suffix of 𝑌 : since # does not occur in 𝑌 , a common prefix of 𝑆[ 𝑗 . . |𝑆|) and 𝑆[|𝑋 | + 1 + 𝑖 . . |𝑆|) cannot extend past #, so for all 𝑗 ∈ [0 . . |𝑋 |) and 𝑖 ∈ [0 . . |𝑌 |),  LCP 𝑋 [ 𝑗 . . |𝑋 |), 𝑌 [𝑖 . . |𝑌 |) = LCE𝑆 ( 𝑗, |𝑋 | + 1 + 𝑖). The sentinel may change the relative order of such a pair, but never its LCP value. By Fact 3.1 applied to the suffixes of 𝑆 in suffix-array order, among a set 𝑅 of ranks of suffixes of 𝑋 in SA𝑆 , the LCP with 𝑌 [𝑖 . . |𝑌 |), whose suffix of 𝑆 has rank 𝜌 = iSA𝑆 [|𝑋 | + 1 + 𝑖], is maximized by max{𝑟 ∈ 𝑅 : 𝑟 < 𝜌} or by min{𝑟 ∈ 𝑅 : 𝑟 > 𝜌}. Predecessor and successor queries. Given a set 𝐾 of integers and an integer 𝑥, the predecessor (resp. successor) of 𝑥 in 𝐾 is defined as pred𝐾 (𝑥) = max{𝑦 ∈ 𝐾 | 𝑦 ≤ 𝑥} (resp. succ𝐾 (𝑥) = min{𝑦 ∈ 𝐾 | 𝑦 ≥ 𝑥}); these are undefined if the corresponding set is empty. A dynamic predecessor data structure maintains a set 𝐾 under insertions and deletions and answers predecessor and successor queries. We use three classic implementations. A balanced binary search tree (e.g., an AVL tree) supports all operations in O (log |𝐾 |) time using O (|𝐾 |) space. For a universe [0 . . 𝑢) of integers, a van Emde Boas (vEB) tree [vEB77] supports all operations in O (log log 𝑢) time, using O (𝑢) space and O (𝑢) initialization time. A dynamic fusion tree [PT14] supports all operations in O (log𝑤 |𝐾 |) = O (log |𝐾 |/log 𝑤) time using O (|𝐾 |) space; in particular, in O (1) time when |𝐾 | = log O (1) 𝑛. 6

Disjoint sets. A union-find data structure maintains a partition of a ground set [0 . . 𝑚), initially consisting of singleton sets, under the operations find (𝑘), which returns the representative of the set containing 𝑘, and union (𝑘, 𝑘 ′ ), which merges the sets containing 𝑘 and 𝑘 ′ . In the static tree set union problem, a rooted tree 𝑇 on [0 . . 𝑚) is given in advance, and every union merges the set containing a non-root node 𝑘 with the set containing its parent; thus, the possible unions are fixed before any operation is performed, whereas the order of the operations is arbitrary. Gabow and Tarjan [GT85] showed that, in this case, any sequence of 𝑞 operations takes O (𝑚 + 𝑞) total time. We use the special case in which 𝑇 is the path where 𝑘 + 1 is the parent of 𝑘, for every 𝑘 ∈ [0 . . 𝑚 − 1): every set is then a contiguous interval of [0 . . 𝑚), and every union merges two adjacent intervals [𝑙 . . 𝑘] and [𝑘 + 1 . . 𝑟]. This is known as the interval union-find problem.

4

LAMAS in Linear Time

We first present a simple O (𝑛 log 𝑑)-time algorithm for LAMAS and then improve it to O (𝑛) time. Our improvements are related to the way queries are answered. Throughout, we set 𝑆 := 𝑋#𝑌 (the string of Section 3), so that |𝑆| = |𝑋 | + |𝑌 | + 1 ≤ 2𝑛 + 1. Without loss of generality, we assume 1 ≤ 𝑑 < 𝑛: for 𝑑 = 0, we have ℓ𝑖 = LCP(𝑋 [𝑖 . . |𝑋 |), 𝑌 [𝑖 . . |𝑌 |)) and 𝛿𝑖 = 0 for every 𝑖 < |𝑋 | (and ℓ𝑖 = 0 otherwise), which is one LCE query per position; for 𝑑 ≥ 𝑛, the output is the same as for 𝑑 = 𝑛 − 1, since every 𝑗 ∈ [0 . . |𝑋 |) satisfies | 𝑗 − 𝑖| ≤ 𝑛 − 1.

4.1

The Simple Algorithm

Main idea. For each position 𝑖 in 𝑌 , the algorithm considers the suffixes of 𝑋 starting within distance 𝑑 of 𝑖. These starting positions form a sliding window [𝑖 − 𝑑 . . 𝑖 + 𝑑], restricted to the valid positions of 𝑋. As 𝑖 increases, the window moves one position to the right. By Fact 3.1, the suffix sharing the longest prefix with 𝑌 [𝑖 . . |𝑌 |) is either its lexicographic predecessor or successor among the admissible suffixes. The algorithm computes the LCP length of both candidates and reports the larger one as ℓ𝑖 (breaking ties arbitrarily), together with the displacement 𝛿𝑖 = 𝑗 ∗ − 𝑖 of the selected suffix 𝑋 [ 𝑗 ∗ . . |𝑋 |). Thus, after constructing the suffix array of 𝑆 = 𝑋#𝑌 , LAMAS reduces to predecessor and successor queries among the suffix-array ranks of a sliding window. These ranks are maintained in a balanced search tree (e.g., an AVL tree), supporting queries and updates in O (log 𝑑) time. As the window slides O (𝑛) times in total, the algorithm takes O (𝑛 log 𝑑) time. Figure 2 illustrates this idea for 𝑋 = banana, 𝑌 = anana, and 𝑑 = 1 at 𝑖 = 1: the window {0, 1, 2} has ranks {6, 3, 9}, and the query suffix 𝑌 [1 . . |𝑌 |) = nana has rank 8, whose predecessor 6 (banana) and successor 9 (nana) have LCP lengths 0 and 4; hence, 𝑗 ∗ = 2 and (ℓ1 , 𝛿1 ) = (4, 1). The algorithm. Algorithm 1 presents the simple algorithm, which consists of four steps: (1) It computes SA𝑆 , iSA𝑆 , and the LCE structure of 𝑆 (Section 3), allowing constant-time LCP queries between suffixes of 𝑋 and 𝑌 (lines 1–2). (2) It constructs arrays 𝐴 and 𝐵 containing the ranks of the suffixes of 𝑋 and 𝑌 , respectively, in SA𝑆 (lines 3–4). Since the suffix of 𝑆 starting with # has the largest rank, the values of 𝐴 and 𝐵 are pairwise distinct and form exactly the set [0 . . | 𝐴| + |𝐵|). (3) For each position 𝑖, it computes the predecessor 𝑟 𝑝 and successor 𝑟 𝑠 of 𝐵[𝑖] among the ranks in the window 𝑊𝑖 := { 𝐴[ 𝑗] : 𝑗 ∈ [0 . . |𝑋 |), | 𝑗 − 𝑖| ≤ 𝑑}. To this end, it maintains 𝑊𝑖 , which has at most 2𝑑 + 1 elements, in an AVL tree updated as the window slides (lines 5–15). (4) It uses at most two LCE queries, one for each candidate, and reports the maximum LCP length ℓ𝑖 and the corresponding displacement 𝛿𝑖 = 𝑗 ∗ − 𝑖, where 𝑗 ∗ is the starting position of a maximizing suffix of 𝑋 (lines 16–21). Correctness follows from Fact 3.1: the ranks in 𝑊𝑖 are exactly the ranks of the admissible suffixes 𝑋 [ 𝑗 . . |𝑋 |) with | 𝑗 − 𝑖| ≤ 𝑑, and, as noted in Section 3, the LCP with 𝑌 [𝑖 . . |𝑌 |) is maximized by the nearest rank below or above 𝐵[𝑖]. Steps 1, 2, and 4 take O (𝑛) time and space. Step 3 performs O (𝑛) AVL 7

(a) Sliding window and query suffix add 𝑗 = 2

0

1

2

3

4

5

𝑋:

b

a

n

rank:

6

3

9

a

n

a

4

10

5

𝑖 = 1: admissible ranks {6, 3, 9}

𝑌:

a

a

n

a

n

𝑌 [1 . . |𝑌 | ) = nana has rank 8

(b) Predecessor and successor among window ranks query rank 8 0

1

2

3

4

5

6

predecessor 6: LCP 0

7

8

9

10

11

successor 9: LCP 4

Selected 𝑗 ∗ = 2; output (ℓ1 , 𝛿1 ) = (4, 1)

Figure 2: Main idea of the simple algorithm: (a) moving the window to 𝑖 = 1 adds position 2 of 𝑋, of rank 9; (b) the predecessor and successor of the query rank 8 have LCP lengths 0 and 4, respectively. Algorithm 1 Simple algorithm for LAMAS Require: Strings 𝑋, 𝑌 and displacement tolerance 𝑑 Ensure: Arrays ℓ and 𝛿 1: 𝑆 ← 𝑋#𝑌 2: Compute SA𝑆 , iSA𝑆 , and the LCE structure of 𝑆 3: 𝐴[ 𝑗] ← iSA𝑆 [ 𝑗] for 𝑗 ∈ [0 . . |𝑋 |) 4: 𝐵[𝑖] ← iSA𝑆 [|𝑋 | + 1 + 𝑖] for 𝑖 ∈ [0 . . |𝑌 |) 5: Initialize an empty AVL tree 𝑊 6: for 𝑗 = 0 to min(𝑑, |𝑋 | − 1) do 7: 𝑊 .Insert( 𝐴[ 𝑗]) 8: for 𝑖 = 0 to |𝑌 | − 1 do 9: if 𝑖 > 0 then 10: if 𝑖 + 𝑑 < |𝑋 | then 11: 𝑊 .Insert( 𝐴[𝑖 + 𝑑]) 12: if 𝑖 > 𝑑 then 13: 𝑊 .Delete( 𝐴[𝑖 − 𝑑 − 1]) 14: 𝑟 𝑝 ← 𝑊 .Predecessor(𝐵[𝑖]) 15: 𝑟 𝑠 ← 𝑊 .Successor(𝐵[𝑖]) 16: (ℓ𝑖 , 𝛿𝑖 ) ← (0, ⊥) 17: for 𝑟 ∈ {𝑟 𝑝 , 𝑟 𝑠 } \ {⊥} do 18: 𝑗 ← SA𝑆 [𝑟] 19: 𝐿 ← LCE( 𝑗, |𝑋 | + 1 + 𝑖) 20: if 𝐿 > ℓ𝑖 or 𝛿𝑖 = ⊥ then 21: (ℓ𝑖 , 𝛿𝑖 ) ← (𝐿, 𝑗 − 𝑖) 22: return (ℓ, 𝛿)

tree operations on a tree of at most 2𝑑 + 1 elements, i.e., O (log 𝑑) time each, and uses O (𝑑) space. Thus, we obtain: Proposition 4.1. The LAMAS problem can be solved in O (𝑛 log 𝑑) time using O (𝑛) space. Example 4.2 (Simple Algorithm). Let 𝑋 = banana, 𝑌 = anana, and 𝑑 = 1. Steps 1–2 compute the suffix arrays of 𝑆 = 𝑋#𝑌 (Figure 3a) and the rank arrays 𝐴 = (6, 3, 9, 4, 10, 5) and 𝐵 = (2, 8, 1, 7, 0) (Figure 3b). For 𝑖 = 0, 𝑊0 = {6, 3} contains no predecessor of 𝐵[0] = 2. Its successor, rank 3, corresponds to 𝑋 [1 . . |𝑋 |) = anana, yielding (ℓ0 , 𝛿0 ) = (5, 1). For 𝑖 = 1, inserting 𝐴[2] = 9 gives 8

𝑡

0

1 2 3

4

5

6

7

8 9 10 11

𝑆[𝑡]

b a n a n a

#

a n a n 4 7

SA𝑆 [𝑡] 11 9 7 1 3 5 0 10 8 2 iSA𝑆 [𝑡] 6 3 9 4 10 5 11 2 8 1

a 6 0

(a) Step 1: 𝑆 = 𝑋#𝑌 with its suffix array and inverse suffix array. 𝑗 (resp. 𝑖)

0

1

2

3

4

5

𝐴[ 𝑗] = iSA𝑆 [ 𝑗] 𝐵[𝑖] = iSA𝑆 [7 + 𝑖]

6 2

3 8

9 1

4 7

10 0

5 –

(b) Step 2: ranks 𝐴 of the suffixes of 𝑋 and 𝐵 of the suffixes of 𝑌 . 𝑖

0

1

2

3

4

𝐵[𝑖] 2 8 1 7 0 𝑊𝑖 {6, 3} {6, 3, 9} {3, 9, 4} {9, 4, 10} {4, 10, 5} 𝑟 𝑝 , 𝑟 𝑠 ⊥, 3 6, 9 ⊥, 3 4, 9 ⊥, 4 ℓ 𝑝 , ℓ𝑠 −∞, 5 0, 4 −∞, 3 0, 2 −∞, 1 ℓ𝑖 5 4 3 2 1 𝑗∗ 1 2 1 2 3 𝛿𝑖 1 1 −1 −1 −1

(c) Steps 3 and 4: windows, nearest ranks 𝑟 𝑝 , 𝑟 𝑠 , their LCP lengths ℓ 𝑝 , ℓ𝑠 with 𝑌 [𝑖 . . |𝑌 |), and output (⊥ and −∞ denote undefined).

Figure 3: The simple algorithm on 𝑋 = banana, 𝑌 = anana, and 𝑑 = 1 (Example 4.2). 𝑊1 = {6, 3, 9} (Figure 2). The predecessor 6 and successor 9 of 𝐵[1] = 8 give LCP lengths 0 and 4, respectively, yielding (ℓ1 , 𝛿1 ) = (4, 1). For 𝑖 = 2, removing 𝐴[0] = 6 and inserting 𝐴[3] = 4 gives 𝑊2 = {3, 9, 4}. The successor of 𝐵[2] = 1 is rank 3, corresponding to 𝑗 = 1, yielding (ℓ2 , 𝛿2 ) = (3, −1). Although 𝑗 = 3 also attains length 3, its rank 4 need not be examined: any maximizing position suffices. Figure 3c shows the complete execution.

4.2

Improvement 1: Universe Reduction

Main idea. The O (log 𝑑) cost per operation of the algorithm in Section 4.1 comes from comparisonbased predecessor search. A vEB tree answers predecessor queries in O (log log 𝑢) time over a universe of size 𝑢. However, our ranks range over [0 . . |𝑆|), making 𝑢 too large. Our key observation is that the windows of 𝑑 consecutive query positions involve at most 3𝑑 consecutive entries of 𝐴 and 𝑑 query keys from 𝐵. Since the queries only depend on the relative order of keys, we can replace the global ranks of keys with local ranks without changing the answers. We therefore cut the problem into O (𝑛/𝑑) independent blocks, each with at most 4𝑑 keys, and re-rank the keys of every block to [0 . . 4𝑑) by a single global radix sort; this makes the universe small enough for vEB trees. Each sliding window can then be processed in O (log log 𝑑) time using a vEB tree, yielding O (𝑑 log log 𝑑) time per block and O (𝑛 log log 𝑑) time overall. An auxiliary problem. We isolate the task of finding the predecessor and successor of each query suffix rank within its admissible window by defining and solving Problem 2. Problem 2 (Sliding-Window Predecessor/Successor (SWPS)). Given a positive integer 𝑁 and arrays 𝑎 = (𝑎 0 , . . . , 𝑎 3𝑁 −1 ) and 𝑏 = (𝑏 0 , . . . , 𝑏 𝑁 −1 ) of pairwise distinct integers in [0 . . 4𝑁),2 output, for every 𝑖 ∈ [0 . . 𝑁), the predecessor and successor of 𝑏 𝑖 in the window {𝑎 𝑗 : 𝑗 ∈ [𝑖 . . 𝑖 + 2𝑁]}; an answer is reported as undefined if no such element exists. 2 Some entries of 𝑎 may be undefined, and 𝑏 may have fewer than 𝑁 entries, to handle the boundaries of 𝑋 and 𝑌 ; undefined

entries are ignored.

9

Proposition 4.3. The SWPS problem can be solved in O (𝑁 log log 𝑁) time using O (𝑁) space. Proof. Initialize a vEB tree over [0 . . 4𝑁); insert the defined values among 𝑎 0 , . . . , 𝑎 2𝑁 into it. This takes O (𝑁) time and space. For 𝑖 ∈ [0 . . 𝑁), we query the tree for the predecessor and the successor of 𝑏 𝑖 , and then remove 𝑎 𝑖 and insert 𝑎 𝑖+2𝑁 +1 (if 𝑖 + 2𝑁 + 1 < 3𝑁; undefined entries are skipped), so that the tree contains exactly the window of 𝑏 𝑖+1 . Each operation takes O (log log 𝑁) time, and there are O (𝑁) of them. □ The algorithm. Steps 1, 2, and 4 of the simple algorithm remain unchanged; we replace Step 3 by a reduction to O (𝑛/𝑑) instances of SWPS. The first step of the reduction is to partition 𝐵 into blocks 𝐵 𝑘 := 𝐵[𝑘 𝑑 . . (𝑘 + 1)𝑑) of 𝑑 positions, for 𝑘 ∈ [0 . . ⌈|𝑌 |/𝑑⌉), and pair every 𝐵 𝑘 with the block 𝐴 𝑘 := 𝐴[(𝑘−1)𝑑 . . (𝑘+2)𝑑) of 3𝑑 entries of 𝐴. This is exactly the SWPS structure: the window of 𝐵[𝑘 𝑑+𝑖 ′ ], for 𝑖 ′ ∈ [0 . . 𝑑), is 𝐴[(𝑘−1)𝑑+𝑖 ′ . . (𝑘 −1)𝑑+𝑖 ′ +2𝑑], i.e., the positions [𝑖 ′ . . 𝑖 ′ + 2𝑑] of 𝐴 𝑘 . Entries of 𝐴 𝑘 outside [0 . . |𝑋 |) are undefined, and the last block of 𝐵 may be shorter than 𝑑. Consecutive blocks of 𝐴 overlap by 2𝑑 positions, so every entry of 𝐴 belongs to at most three blocks and the total size of all instances is O (𝑛). The second step is to reduce the universe of each instance to [0 . . 4𝑑) to be able to apply Proposition 4.3. We form, for every 𝑘, the set 𝑀𝑘 of the (defined) values of 𝐴 𝑘 and 𝐵 𝑘 , each tagged with its block 𝑘 and its index in 𝐴 𝑘 or 𝐵 𝑘 . We sort all 𝑀𝑘 ’s together by one radix sort: a counting sort of all tags by value, over the universe [0 . . |𝑆|), followed by a stable counting sort by block index. This takes O (𝑛) time. Replacing every value by its position in the sorted 𝑀𝑘 yields arrays 𝐴′𝑘 and 𝐵′𝑘 over [0 . . 4𝑑) that have the same relative order as 𝐴 𝑘 and 𝐵 𝑘 ; hence predecessors and successors are preserved. Finally, we solve each SWPS instance 𝑎 := 𝐴′𝑘 , 𝑏 := 𝐵′𝑘 , 𝑁 := 𝑑 by Proposition 4.3, in O (𝑑 log log 𝑑) time, reusing (and re-initializing, in O (𝑑) time) a single vEB tree for all instances. Complexity. The total time is O (𝑛) for Steps 1, 2, and 4 and for the radix sort, plus O (𝑛/𝑑) · O (𝑑 log log 𝑑) = O (𝑛 log log 𝑑) for the SWPS instances. If 𝑑 = log O (1) 𝑛, we replace the vEB tree by a dynamic fusion tree [PT14], which supports every operation on at most 2𝑑 + 1 keys in O (log𝑤 𝑑) = O (log 𝑑/log 𝑤) ⊆ O (log 𝑑/log log 𝑛) = O (1) time, where 𝑤 = Ω(log 𝑛) is the word size in bits. Proposition 4.4. The LAMAS problem can be solved in O (𝑛 log log 𝑑) time using O (𝑛) space. If 𝑑 = log O (1) 𝑛, then it can be solved in O (𝑛) time using O (𝑛) space.

4.3

Improvement 2: Window Decomposition and Union-Find

Main idea. We remove the dependency on 𝑑, showing that each SWPS instance can be solved in O (𝑁) time, and thus LAMAS in the optimal O (𝑛) time. We observe that the windows of SWPS have a rigid structure. Partition the input array 𝑎 into three equal parts, (left) 𝑎 𝐿 , (middle) 𝑎 𝑀 , and (right) 𝑎 𝑅 . For each query key 𝑏 𝑖 in 𝑏, its window consists of a suffix of 𝑎 𝐿 , the entire 𝑎 𝑀 , and a prefix of 𝑎 𝑅 , as illustrated in Figure 4. The middle part 𝑎 𝑀 is static, so a single sorted scan answers all queries on it. The suffix of 𝑎 𝐿 only shrinks as 𝑖 increases, and the prefix of 𝑎 𝑅 only shrinks if we process the queries in decreasing order of 𝑖. Thus, all remaining queries are predecessor/successor queries on a sorted sequence that only undergoes deletions, which is the interval union-find problem admitting a linear-time solution. Since 𝑖 ∈ [0 . . 𝑁), every window of 𝑏 𝑖 decomposes as [𝑖 . . 𝑖 + 2𝑁] = [𝑖 . . 𝑁) ∪ [𝑁 . . 2𝑁) ∪ [2𝑁 . . 2𝑁 + 𝑖]. Namely, let 𝑎 𝐿 := 𝑎 0 , . . . , 𝑎 𝑁 −1 , 𝑎 𝑀 := 𝑎 𝑁 , . . . , 𝑎 2𝑁 −1 , and 𝑎 𝑅 := 𝑎 2𝑁 , . . . , 𝑎 3𝑁 −1 . Denoting by pred 𝐿 (𝑖), pred 𝑀 (𝑖), and pred𝑅 (𝑖) the predecessor of 𝑏 𝑖 in {𝑎 𝑖 , . . . , 𝑎 𝑁 −1 }, {𝑎 𝑁 , . . . , 𝑎 2𝑁 −1 }, and {𝑎 2𝑁 , . . . , 𝑎 2𝑁 +𝑖 }, respectively (and analogously for succ), we have pred(𝑖) = max{pred 𝐿 (𝑖), pred 𝑀 (𝑖), pred𝑅 (𝑖)}, succ(𝑖) = min{succ 𝐿 (𝑖), succ 𝑀 (𝑖), succ𝑅 (𝑖)}, where undefined values are ignored. We answer the three kinds of queries using the following tool. 10

𝑎𝐿 𝑎0 . . . 𝑎5

𝑎𝑀 𝑎6 . . . 𝑎11

𝑎𝑅 𝑎12 . . . 𝑎17

𝑊1 for 𝑏 1

𝑖 increases left suffix shrinks right prefix grows Reverse order: right prefix shrinks

𝑊4 for 𝑏 4 Colored entries belong to 𝑊𝑖 ; grey entries are excluded.

Figure 4: Decomposition of SWPS windows for 𝑁 = 6. Lemma 4.5 (Interval Union-Find [GT85]). Let 𝑒 0 , . . . , 𝑒 𝑚−1 be a sequence of elements, all initially present. There is a data structure that supports the following operations: delete (𝑘), which marks 𝑒 𝑘 as deleted; next (𝑘), which returns the smallest 𝑘 ′ ≥ 𝑘 such that 𝑒 𝑘 ′ is present (or reports that no such 𝑘 ′ exists); and prev (𝑘), which returns the largest 𝑘 ′ ≤ 𝑘 such that 𝑒 𝑘 ′ is present (or reports that no such 𝑘 ′ exists). Any sequence of 𝑞 such operations takes O (𝑚 + 𝑞) total time. Proof. We maintain a partition of [0 . . 𝑚) into intervals of the following form: every interval [𝑙 . . 𝑟] is such that 𝑒 𝑙 , . . . , 𝑒𝑟 −1 are deleted and 𝑒𝑟 is present, except possibly for the rightmost interval, whose elements may all be deleted. Initially, every element forms a singleton interval. Each interval is stored as a set in a union-find data structure, and its representative stores 𝑙 and 𝑟. Operation delete (𝑘) unites the interval containing 𝑘 with the interval containing 𝑘 + 1 (if 𝑘 < 𝑚 − 1); this preserves the invariant and takes O (1) time on top of the union operation. For next (𝑘), we find the interval [𝑙 . . 𝑟] containing 𝑘 and return 𝑟 if 𝑒𝑟 is present (otherwise, no such element exists). For prev (𝑘), we find the interval [𝑙 . . 𝑟] containing 𝑘; if 𝑘 = 𝑟 and 𝑒𝑟 is present we return 𝑘; otherwise, 𝑒 𝑘 is deleted and we return 𝑙 − 1 (if 𝑙 > 0; otherwise, no such element exists), which is present by the maximality of the intervals. Since every union merges the set containing some 𝑘 with the set containing 𝑘 + 1, this is the interval union-find problem: the union tree is the path with parent(𝑘) = 𝑘 + 1, which is fixed in advance, while the deletions may arrive in any order. Any sequence of 𝑞 operations takes O (𝑚 + 𝑞) total time [GT85]. □ Lemma 4.6. The SWPS problem can be solved in O (𝑁) time using O (𝑁) space. Proof. As all (defined) values of 𝑎 and 𝑏 are pairwise distinct integers in [0 . . 4𝑁), we first use counting sort to obtain, in O (𝑁) time, the sorted sequence of all these values, where every value is annotated with its origin (𝑎 𝐿 , 𝑎 𝑀 , 𝑎 𝑅 , or 𝑏) and its index in 𝑎 or 𝑏. A single scan over this sequence yields: • the sorted sequences 𝑐 0𝐿 < 𝑐 1𝐿 < · · · , 𝑐 0𝑀 < 𝑐 1𝑀 < · · · , and 𝑐 0𝑅 < 𝑐 1𝑅 < · · · of the (defined) values of 𝑎 𝐿 , 𝑎 𝑀 , and 𝑎 𝑅 , respectively, together with the rank 𝜌( 𝑗) of every defined 𝑎 𝑗 within the sorted sequence of its own part; • for every 𝑖 ∈ [0 . . 𝑁), the numbers 𝜋𝑖𝐿 , 𝜋𝑖𝑀 , and 𝜋𝑖𝑅 of values of 𝑎 𝐿 , 𝑎 𝑀 , and 𝑎 𝑅 , respectively, that are smaller than 𝑏 𝑖 . Note that the predecessor (resp. successor) of 𝑏 𝑖 in any subset 𝑃 of 𝑎 𝑅 is the element of 𝑃 with the largest rank at most 𝜋𝑖𝑅 − 1 (resp. the smallest rank at least 𝜋𝑖𝑅 ) in 𝑐 𝑅 , and analogously for 𝑎 𝐿 and 𝑎 𝑀 . Middle part. Since the set {𝑎 𝑁 , . . . , 𝑎 2𝑁 −1 } is the same for all queries, we have pred 𝑀 (𝑖) = 𝑐 𝑀 𝜋 𝑀 −1 𝑖

(undefined if 𝜋𝑖𝑀 = 0) and succ 𝑀 (𝑖) = 𝑐 𝑀 (undefined if 𝜋𝑖𝑀 equals the number of defined values in 𝑎 𝑀 ). 𝜋𝑀 𝑖

This takes O (1) time per query. Right part. We process the queries in the order 𝑖 = 𝑁 −1, 𝑁 −2, . . . , 0, so that the set {𝑎 2𝑁 , . . . , 𝑎 2𝑁 +𝑖 } only shrinks. We initialize the data structure of Lemma 4.5 over the sorted sequence 𝑐 𝑅 (so 𝑚 is the number 𝑅 of defined values in 𝑎 𝑅 ). For 𝑖 = 𝑁 − 1 down to 0, we first answer the query for 𝑏 𝑖 : pred𝑅 (𝑖) = 𝑐 prev ( 𝜋 𝑅 −1) 𝑖

𝑅 (undefined if 𝜋𝑖𝑅 = 0 or prev reports no element) and succ𝑅 (𝑖) = 𝑐 next (undefined if 𝜋𝑖𝑅 = 𝑚 or next ( 𝜋𝑅 ) 𝑖

reports no element); then, if 𝑎 2𝑁 +𝑖 is defined, we perform delete (𝜌(2𝑁 + 𝑖)). By induction, when the 11

query for 𝑏 𝑖 is answered, exactly the defined values among 𝑎 2𝑁 , . . . , 𝑎 2𝑁 +𝑖 are present, as required. We perform O (𝑁) operations in total, which takes O (𝑁) time by Lemma 4.5. Left part. This is symmetric: we process the queries in the order 𝑖 = 0, 1, . . . , 𝑁 − 1, so that the set {𝑎 𝑖 , . . . , 𝑎 𝑁 −1 } only shrinks. We initialize the data structure of Lemma 4.5 over 𝑐 𝐿 , and, for 𝑖 = 0 to 𝑁 − 1, we answer the query for 𝑏 𝑖 using prev (𝜋𝑖𝐿 − 1) and next (𝜋𝑖𝐿 ) exactly as above, and then perform delete (𝜌(𝑖)) if 𝑎 𝑖 is defined. Again, this takes O (𝑁) time. We combine the partial answers into pred(𝑖) and succ(𝑖) for every 𝑖 in O (1) time each to get O (𝑁) time and space. □ The final algorithm. The algorithm is that of Section 4.2, with Lemma 4.6 used in place of Proposition 4.3: Steps 1, 2, and 4 and the universe reduction take O (𝑛) time, and the O (𝑛/𝑑) SWPS instances take O (𝑛/𝑑) · O (𝑑) = O (𝑛) time in total. The space is O (𝑛) for the LCE data structure and the sorted arrays, plus O (𝑑) = O (𝑛) for the data structures of Lemma 4.5, which are reused across instances. Theorem 4.7. The LAMAS problem can be solved in O (𝑛) time using O (𝑛) space, for any 𝑑 ≥ 0. This bound is optimal: Ω(𝑛) time is required to read the input, and it matches the time to compute the MS array [CL90].

5

Experimental Evaluation

Our experimental evaluation addresses five questions. Q1 How closely does LAMAS correlate with ED as sequence divergence increases? (Section 5.1). Q2 How effectively does LAMAS classify time-series pairs? (Section 5.2). Q3 How accurately does LAMAS recover the top-𝐾 results under ED? (Section 5.3). Q4 How effectively does LAMAS recover reference classes through clustering? (Section 5.4). Q5 How efficient in terms of running time and space is our O (𝑛)-time LAMAS algorithm? (Section 5.5). We use 20 real datasets together with synthetic datasets. We compare our O (𝑛)-time LAMAS algorithm to: (1) our own implementation of MS, (2) our own implementation of 𝑞-gram distance, (3) the ED implementation of Edlib [ŠŠ17], which uses the efficient Myers’ bit-vector algorithm, (4) our O (𝑛 log 𝑑)-time algorithm of Section 4.1, referred to as LAMAS (Simple), and (5) our O (𝑛 log log 𝑑)-time algorithm of Section 4.2, referred to as LAMAS (vEB). All LAMAS implementations and MS use SDSL-lite [GBMP14]. For the classification experiments, we also compare against banded DTW [SC78], which bounds the displacement between aligned positions and is thus a natural baseline. For the top-𝐾 retrieval experiments, we additionally compare against an adapted version of MinSearch [ZZ20a]. We do not report results for the edit-distance embedding method of [CGK16], as it underperformed LAMAS consistently in our setting. For example, in the experiment of Section 5.1, its mean Pearson correlation with ED was 70% lower than that of the worst competitor. All experiments ran on an Intel(R) Xeon(R) Gold 6248 CPU at 2.50GHz with 188GB of RAM. Our code and datasets are available at https://github.com/lorrainea/LAMAS.

5.1

Correlation with ED

Task and data. We evaluate how closely LAMAS, MS, and 𝑞-gram distance correlate with ED, and how their correlations with ED vary with divergence (i.e., the number of edit operations applied to a sequence, divided by its length). For LAMAS and MS, we convert match lengths into symmetric ACS-based dissimilarities; see [UBTC06]. We use 400 pairs of DNA sequences of length 𝑛 ≈ 100,000, generated with the generate dataset tool of the Wavefront alignment algorithm [MMME21], which simulates genomic variability: 100 pairs at each of the divergence levels 15%, 20%, 25%, and 30%.

12

9

Spearman Rank

0.6 0.4 0.2 0.0

0 0 0 0 0 0 50 100 150 200 250 300

0 0 0 0 0 0 50 100 150 200 250 300

q

d

8

9

10 11 12 13 14

0.4 0.2 0.0

0 0 0 0 0 0 50 100 150 200 250 300

d

8

9

9

0.4 0.2 0.0

8

9

q

(a)

10 11 12 13 14

0.4 0.2 0.0

0 0 0 0 0 0 50 100 150 200 250 300

d

8

9

MS

0.2

8

9

0.6 0.4 0.2 0.0

0 0 0 0 0 0 50 100 150 200 250 300

8

9

0.6 0.4 0.2 0.0

0 0 0 0 0 0 50 100 150 200 250 300

d

(b)

(c)

8

9

10 11 12 13 14

q

q-gram

MS

0.2

0 0 0 0 0 0 50 100 150 200 250 300

8

9

10 11 12 13 14

q

d

0.6 0.4 0.2 0.0

0 0 0 0 0 0 50 100 150 200 250 300

q

d

q

10 11 12 13 14

LAMAS

0.4

0.0

10 11 12 13 14

q

d

10 11 12 13 14

0.6

Pearson's

q-gram

0 0 0 0 0 0 50 100 150 200 250 300

q

0.6

LAMAS

0.4

0.0

q

d

10 11 12 13 14

0.6

10 11 12 13 14

0.6

0 0 0 0 0 0 50 100 150 200 250 300

Kendall Rank

0.6

8

d

q

d

0.2 0.0

10 11 12 13 14

MS

Spearman Rank

8

q-gram

0.4

8

9

10 11 12 13 14

q

d

Kendall Rank

0 0 0 0 0 0 50 100 150 200 250 300

LAMAS

Pearson's

0.2 0.0

Kendall Rank

0.6

Spearman Rank

MS

Kendall Rank

q-gram

Pearson's

LAMAS

0.4

Spearman Rank

Pearson's

0.6

0.6 0.4 0.2 0.0

0 0 0 0 0 0 50 100 150 200 250 300

d

8

9

10 11 12 13 14

q

(d)

Figure 5: Pearson’s, Spearman Rank and Kendall Rank correlation between LAMAS and ED, MS and ED and 𝑞-gram distance and ED, for 100 pairs of sequences of length 𝑛 ≈ 100, 000 and a divergence of: (a) 15%, (b) 20%, (c) 25%, and (d) 30%. Measures. We compute LAMAS with varying 𝑑 ∈ {500, 1000, . . . , 3000}, 𝑞-gram distance with varying 𝑞 ∈ {8, 9, . . . , 14}, and MS. We assess their correlation with ED using three well-known correlation measures: Pearson’s [Pea95], Spearman’s [Spe04], and Kendall’s Rank [Ken38] correlation. Results. Figure 5 shows that LAMAS achieves substantially stronger correlations with ED than MS; larger by 12.4% on average and up to 30.8%. LAMAS also compares favorably to 𝑞-gram distance: averaged over all tested parameter values and divergence levels, it achieves 11.3%, 10.6%, and 12.2% higher Pearson’s, Spearman’s, and Kendall’s Rank correlation, respectively. Its advantage increases at 30% divergence, where these improvements are up to 42.4%, 45.1%, and 48.3%, respectively. LAMAS outperforms even the best 𝑞-gram distance configuration in this divergence level by 26%–31%.

5.2

Pair Classification

Task and data. We evaluate whether the locations of shared substrings help distinguish time series from the same class from those belonging to different classes. We use the 15 real datasets in Table 1, each containing 𝑁 labeled time series. We discretize each time series of every dataset into a string of length 𝑛, as explained below. We construct pairs of strings and call a pair positive if the source time series have the same class label, and negative otherwise. For example, in the PenDigits [UCRm] dataset, two recordings of the same digit form a positive pair. Then, we compute a similarity score for the pair using one of the tested measures, as explained below, and compare it with a validation-selected threshold to predict whether the pair is positive. Class labels establish the ground truth, for parameter selection and evaluation. From time series to strings. We convert each numeric dimension into a string using standard SAX preprocessing [LKWL07]: 𝑧-normalization, overlap-weighted piecewise aggregate approximation (PAA) [KCPM01], and discretization using Gaussian breakpoints. If all time series in a dataset have length 𝐿, we set the string length to 𝑛 = min{128, 𝐿}. Otherwise, we use 𝑛 = 128; overlap-weighted aggregation maps series with length less than 128 to 128 symbols. For each dataset, we select each method’s alphabet size 𝜎 ∈ {2, 4, 6, 8, 12, 16}, parameters, and decision threshold by maximizing validation 𝐹1 [MRS08]. This allows each method to use its best validation-selected configuration. We report 𝐹1 on the test pairs using the selected settings. From matches to a pair decision. We summarize the matching lengths using five statistics. For each 𝑘 ∈ {1, 2, 3, 5, 8}, we define 𝑓 𝑘 (𝑋, 𝑌 ) as the average of the fraction of positions in 𝑌 with matching length at least 𝑘 in 𝑋 and the corresponding fraction with 𝑋 and 𝑌 exchanged. For each statistic, we standardize 𝑓 𝑘 (𝑋, 𝑌 ) using its mean 𝜇 𝑘 and standard deviation 𝑠 𝑘 estimated from the fitting pairs, and 13

Table 1: Datasets and positive-class test 𝐹1 . 𝑛 is SAX length and 𝑁 the total series count. Best (second-best) results are bold (underlined). LAMAS Dataset

𝑛

𝑁

EOGHorizontalSignal [UCRg] 128 724 Chinatown [UCRe] 24 363 WordSynonyms [UCRq] 128 905 Meat [UCRk] 128 120 ACSF1 [UCRb] 128 200 CharacterTrajectories [UCRd] 128 2858 ArticularyWordRecognition [UCRc] 128 575 GesturePebbleZ1 [UCRj] 128 304 UWaveGestureLibrary [UCRp] 128 440 PenDigits [UCRm] 8 10992 FacesUCR [UCRh] 128 2250 ShakeGestureWiimoteZ [UCRn] 128 100 Fish [UCRi] 128 350 AconityMINIPrinterSmall [UCRa] 128 881 MixedShapesSmallTrain [UCRl] 128 2525 Mean ± SD

–

𝐹1 𝜎

MS

𝑞-gram

ED

banded DTW

𝑑

𝐹1 𝜎

𝐹1 𝜎 𝑞

𝐹1 𝜎

𝐹1

0.7383 6 19 0.7612 16 0 0.6894 6 37 0.7843 12 1 0.7348 4 20 0.8840 6 10 0.8852 8 12 0.8609 4 9 0.7718 4 16 0.7524 2 1 0.6892 6 5 0.8101 6 21 0.6846 16 6 0.7012 8 0 0.7184 12 13

0.6958 8 0.6276 8 0.6748 4 0.7442 8 0.7244 4 0.7809 16 0.8134 16 0.7248 12 0.6927 2 0.7145 2 0.6378 6 0.6748 8 0.6670 16 0.6660 8 0.6569 16

0.6956 6 4 0.7074 6 3 0.6772 6 8 0.7880 12 8 0.7521 2 6 0.7905 4 8 0.8415 16 2 0.7540 4 1 0.6327 4 4 0.7053 2 4 0.6688 4 3 0.5484 12 1 0.6900 8 1 0.6651 4 1 0.6299 16 8

0.7362 6 0.7111 8 0.6821 4 0.7840 12 0.7016 4 0.8726 2 0.9218 8 0.8951 4 0.8169 2 0.7440 4 0.7383 6 0.8210 8 0.7507 8 0.6840 8 0.7203 12

0.7102 0.6851 0.6797 0.7789 0.6870 0.8991 0.9220 0.7699 0.8050 0.7999 0.7294 0.8407 0.6786 0.7195 0.7096

0.7644 – ±0.0688

–

0.6997 – ±0.0516

0.7031 – ±0.0741

0.7720 – – ±0.0770

–

0.7610 ±0.0792

apply tanh(( 𝑓 𝑘 (𝑋, 𝑌 ) − 𝜇 𝑘 )/(2𝑠 𝑘 )) to bound its contribution to (−1, 1). Tanh-based normalization has been used for combining matching scores [JNR05]. The same scoring procedure is used for LAMAS and MS. We classify each pair using a validation-selected threshold. For multivariate time series, scores are averaged across dimensions. ED and 𝑞-gram distances are converted into similarity scores. As a baseline, we apply banded DTW [RK04] to normalized PAA sequences before SAX, selecting its warping band and decision threshold on validation pairs. Parameter selection and evaluation. We retain the training/test split of each dataset and divide the training strings into fitting (60%) and validation (40%) subsets, preserving class proportions. Within each subset, we construct balanced positive/negative pairs, using up to 2000 fitting, 2000 validation, and 20000 test pairs. Fitting pairs determine feature standardization; validation pairs select each method’s alphabet size and threshold, as well as LAMAS’s 𝑑 ∈ {0, . . . , 𝑛 − 1} and the baseline’s 𝑞 ∈ {1, 2, 3, 4, 6, 8}. Banded DTW’s radius and threshold are selected by maximizing validation 𝐹1 . All configurations use the same subsets and pairs, with no sequence shared across subsets. We evaluate the selected configurations on test pairs using 𝐹1 [MRS08]. Predicting every pair positive scores 2/3 on our balanced pairs. Results. Among the three ED proxies in Table 1, LAMAS achieves the highest mean 𝐹1 (0.7644), outperforming MS and 𝑞-gram distance by 9.2% and 8.7%, respectively, and approaching the effectiveness of ED (0.7720). Banded DTW has a lower mean 𝐹1 (0.7610). LAMAS outperforms MS on all 15 datasets, ranks first among all methods on 3, and ranks second on 7. A two-sided paired Wilcoxon signed-rank test across the 15 datasets confirms that LAMAS significantly outperforms MS (𝑝 < 0.001) and 𝑞-gram distance (𝑝 < 0.01). Its differences from ED and banded DTW are not statistically significant (𝑝 = 0.64 and 𝑝 = 0.98, respectively). The selected 𝑑’s are much smaller than 𝑛 (in MS 𝑑 = 𝑛 − 1), which shows the benefit of restricting match positions in classification.

5.3

Top-𝐾 Retrieval

Task and data. We evaluate the effectiveness of LAMAS, MS, 𝑞-gram distance, and MinSearch [ZZ20a] in retrieving the same top-𝐾 most similar strings to a query string (pattern) as ED. We include MinSearch, 14

Table 2: Direct retrieval 𝐹1 @10. LAMAS and MS use the same five-statistic score. 𝑛 is the SAX length and 𝑁 the total series count. Best (second-best) scores are bold (underlined). Dataset

𝑛

𝑁

LAMAS

𝑑

MS

𝑞-gram

𝑞

MinSearch

EOGHorizontalSignal [UCRg] Chinatown [UCRe] WordSynonyms [UCRq] Meat [UCRk] ACSF1 [UCRb] CharacterTrajectories [UCRd] ArticularyWordRecognition [UCRc] GesturePebbleZ1 [UCRj] UWaveGestureLibrary [UCRp] PenDigits [UCRm] FacesUCR [UCRh] ShakeGestureWiimoteZ [UCRn] Fish [UCRi] AconityMINIPrinterSmall [UCRa] MixedShapesSmallTrain [UCRl]

128 24 128 128 128 128 128 128 128 8 128 128 128 128 128

724 363 905 120 200 2858 575 304 440 10992 2250 100 350 881 2525

0.8500 0.9033 0.6467 1.0000 0.9367 0.5467 0.6567 0.7600 0.7400 0.9800 0.6033 0.7300 0.5867 0.6000 0.7333

5 1 10 0 1 5 5 8 15 0 6 5 3 7 10

0.3133 0.8200 0.2167 0.9467 0.5567 0.1333 0.2033 0.4467 0.3033 0.8267 0.2567 0.4500 0.3567 0.1233 0.4933

0.4467 0.8233 0.2867 0.9533 0.5500 0.2667 0.1967 0.4600 0.3967 0.8267 0.3000 0.4900 0.4867 0.2300 0.4667

8 3 4 4 4 4 8 3 4 3 4 4 8 3 4

0.9167 0.3740 0.6567 0.9900 0.9200 0.8867 0.5333 0.5104 0.6861 0.6606 0.2595 0.3213 0.9767 0.4370 0.6733

Mean ± SD

—

—

0.7516 ±0.1502

—

0.4298 ±0.2593

0.4787 ±0.2289

—

0.6535 ±0.2448

a state-of-the-art approach for top-𝐾 retrieval under ED, with probabilistic correctness guarantees.3 We do not compare against the newer heuristic of [LPS23] whose advantage is efficiency, since our focus is on effectiveness. We use all 15 datasets in Table 2. From the datasets that contain multivariate timeseries, we retain one dimension uniformly at random per timeseries. For each dataset, we search its original training sequences using 10 validation and 30 disjoint test queries sampled from its test partition. All methods use the same sequences and queries. Sequences are 𝑧-normalized and converted to SAX strings using PAA and Gaussian breakpoints [LKWL07]. All methods use 𝜎 = 8. Scoring and parameter selection. For MS and LAMAS, we use the same five-statistic similarity score described in Section 5.2, with normalization based on unlabeled database pairs. The 𝑞-gram baseline ranks by the ℓ1 distance between substring-count vectors. We retain LAMAS’s displacement tolerance 𝑑 ∈ {0, . . . , 𝑛 − 1} and the 𝑞-gram length 𝑞 ∈ {1, 2, 3, 4, 6, 8} previously selected by maximizing validation 𝐹1 @10; these choices remain fixed across 𝐾. Evaluation and results. ED supplies the ground truth. Let 𝑟 be the 𝐾th smallest distance, 𝐿 the records closer than 𝑟, 𝐸 those at distance 𝑟, and 𝑅 the returned records. 𝐹1 @𝐾 = 2𝑐/(|𝑅| + 𝐾), where 𝑐 = |𝑅 ∩ 𝐿| + min{|𝑅 ∩ 𝐸 |, 𝐾 − |𝐿|}. Thus, boundary-tied records are interchangeable and missing closer records is penalized. We average 𝐹1 @𝐾 over test queries within each dataset and then across datasets with equal weight. Table 2 shows that LAMAS outperforms both MS and 𝑞-gram distance on all 15 datasets at 𝐾 = 10 (Wilcoxon signed-rank tests across datasets, 𝑝 < 0.001 for both). The improvement over MS is 74.9%. LAMAS also outperforms MinSearch on 11 out of 15 datasets, although the difference is not statistically significant (𝑝 = 0.107). Figure 6 reports sensitivity to 𝐾. LAMAS outperforms both MS and 𝑞-gram distance at every evaluated 𝐾, with lower variation across datasets. It also outperforms MinSearch on average for 𝐾 ≥ 5 (e.g., its 𝐹1 @100 is 0.8565 vs. 0.5656). The values of 𝑑 are smaller than 𝑛, showing the effectiveness of restricting match positions in LAMAS compared to MS (𝑑 = 𝑛 − 1). 3We adapt the authors’ code [ZZ20b] to accept short strings and safely verify ED on unpadded inputs.

No exhaustive fallback is added, so fewer than 𝐾 results may be returned. We set the internal gram length to 𝑞 MSrch = ⌈log8 𝑛⌉. We select 𝛼 ∈ {0.5, 1, 2, 3}, which controls the partition levels searched, separately for each 𝐾 by maximizing mean validation 𝐹1 @𝐾.

15

LAMAS

MS

5

10

q-gram

MinSearch

Mean F1@K

1.0 0.8 0.6 0.4 0.2 0.0

1

20

K

50

100

Figure 6: Mean 𝐹1 @𝐾 vs. 𝐾; error bars show the sample standard deviation; datasets with size ≤ 𝐾 are excluded.

5.4

Clustering

Tasks. We evaluate clustering quality using ARI [HA85], NMI [SG02], purity [MRS08], and classsupport-weighted 𝐹1 [sci], computed after optimally matching clusters to reference classes using a 1-to-1 assignment; higher values are better, ARI lies in [−0.5, 1] and all other measures in [0, 1]. We use real datasets and smaller real-data subsets selected for clear class separation under ED. Table 3: Clustering datasets and selected parameters: 𝑁 strings of length 𝑛, alphabet size 𝜎, and 𝑘 classes. Parameters 𝑑 and 𝑞 are selected on training data for the first two datasets and on the evaluated subsets for the remaining three. Dataset Crop [UCRf] StarLightCurves [UCRo]

𝑁

𝑛

16,800 128 8,236 128

CinCECGTorso [DBK+ 19] ECG5000 [DBK+ 19] ADFA-LD [CH13]

𝜎

𝑘

𝑑 𝑞

8 24 8 6 8 3 16 8

235 512 8 408 140 8 24 500 ≈ 170

4 24 4 5 26 2 2 3 6

Real datasets. We show that LAMAS can cluster real datasets substantially more effectively than MS and 𝑞-gram distance, while remaining competitive with ED. We use two real datasets (see Table 3): Crop, containing image-derived time series of length 𝐿 = 46, and StarLightCurves, containing stellar-brightness series of length 𝐿 = 1024. We cluster their test partitions and select parameters using training data. Specifically, we use complete-linkage agglomerative clustering [JD88], cutting each dendrogram into 𝑘 clusters, where 𝑘 is the number of reference classes (Table 3). For LAMAS and MS, dissimilarity is 1 − ℓ/𝑛, where ℓ is the mean match length over both directions; 𝑞-gram distance is the ℓ1 difference of substring-count vectors, including overlaps. Both datasets undergo Gaussian smoothing with standard deviation max(1, 0.01𝐿), 𝑧-normalization, overlap-weighted PAA [KCPM01], and SAX discretization using standard-normal breakpoints [LKWL07]. We use 𝑛 = 128 and 𝜎 = 8; for Crop, this increases the representation length without adding information. A fixed uniform sample of 500 training sequences per dataset, drawn without inspecting labels or distances, is used to select parameters by maximizing ARI over 𝑑 ∈ {0, 1, 2, 4, 8, 16, 32, 64} and 𝑞 ∈ {1, 2, 3, 4, 6, 8}, breaking ties toward smaller values. LAMAS outperforms MS and 𝑞-grams on all four measures (Figure 7). For Crop, its ARI is 146% higher than MS and 154% higher than 𝑞-grams, while ED performs slightly better. For StarLightCurves, LAMAS ranks first on all four measures, improving ARI and weighted 𝐹1 by 6.8% and 12.8% over MS, and by 13.1% and 4.5% over 𝑞-grams, respectively; its ARI is also 96% higher than that of ED. The selected bounds 𝑑 = 8, 16 are far smaller than 𝑛 = 128, whereas MS corresponds to 𝑑 = 127. ED-selected case studies. We show that LAMAS recovers reference-class structure much better than MS and 𝑞-gram distance, often outperforming ED itself, even on collections selected to favor class 16

LAMAS

MS

q-gram

ED

LAMAS

q-gram

MS

ED

Clustering score

Clustering score

0.4 0.3 0.2 0.1 0.0

ARI

NMI

Purity

0.8 0.6 0.4 0.2 0.0

Weighted F1

ARI

NMI

(a)

Purity

Weighted F1

(b)

Figure 7: Clustering performance on the complete test partitions of (a) Crop and (b) StarLightCurves. MS

q-gram

ED

LAMAS

Clustering score

Clustering score

0.8 0.6 0.4 0.2 0.0

ARI

NMI

Purity

Weighted F1

(a)

MS

q-gram

ED

0.8 0.6 0.4 0.2 0.0

LAMAS

MS

q-gram

ED

1.0

Clustering score

LAMAS

1.0

0.8 0.6 0.4 0.2 0.0

ARI

NMI

(b)

Purity

Weighted F1

ARI

NMI

Purity

Weighted F1

(c)

Figure 8: Clustering of (a) CinCECGTorso, (b) ECG5000, and (c) ADFA-LD. separation under ED. We use three real datasets (see Table 3): CinCECGTorso, ECG5000, and the system-call dataset ADFA-LD. For CinCECGTorso and ECG5000, we use the same normalization, PAA, and SAX discretization as above, without Gaussian smoothing. For ADFA-LD, we collapse consecutive repeated calls, concatenate traces within each class using unique boundary tokens, and extract length-500 windows with stride 250; system calls are the alphabet letters. After constructing these strings, we compute each class medoid under ED and retain strings with the largest difference between their distance to the nearest other-class medoid and their distance to their own-class medoid. The resulting subset sizes are given in Table 3. Reference labels guide subset selection, tuning of 𝑑 and 𝑞 on the selected subsets and evaluation; they are not inputs to the pairwise string-comparison scores or the clustering merge decisions. As can be seen in Figure 8, LAMAS outperforms both MS and 𝑞-gram distance and also outperforms ED in nearly all comparisons, despite the subsets being selected to favor class separation under ED. For example, LAMAS improves ARI and weighted 𝐹1 over ED by approximately 31% and 26% on ECG5000, and improves ARI and NMI over the strongest competitor by 53% and 70% on ADFA-LD.

5.5

Time and Space Efficiency

Real DNA sequencing data. We use two datasets of Oxford Nanopore Technologies (ONT) reads (sequenced DNA fragments): ONT1, with read lengths 40,000–50,000 and 12% divergence [MEG+ 23]; and ONT2, with 50 pairs of ultra-long reads of length 500,135–848,888, mapped to the CHM13 v1.1 human reference genome, with average divergence 6.1% [Pai24]. For both datasets, we set 𝑞 = 4 and 𝑑 = ⌊0.1 · min(|𝑋 |, |𝑌 |)⌋ for each string pair (𝑋, 𝑌 ). We compare LAMAS to its non-optimized versions and to the string-based distance measures. Figure 9 shows that LAMAS takes 11% longer than ED on ONT1 reads, but is 8.5 times faster on the much longer ONT2 reads. LAMAS is 61% and 65% faster than LAMAS (Simple) and LAMAS (vEB), respectively, on ONT1, and 78% and 80% faster on ONT2. Its running time is comparable to 𝑞-gram distance on ONT1 but larger in ONT2. LAMAS is 27% and 26% slower than MS on ONT1 and ONT2, respectively, a modest overhead for enforcing the displacement constraint that improves effectiveness in

17

0.01 0.00

2 1 0

(a)

q-gram

MS

ED Memory (MB)

0.02

LAMAS (vEB) Memory (MB)

0.03

LAMAS (Simple)

Time (s)

Time (s)

LAMAS

6 4 2 0

(b)

120 80 40 0

(c)

(d)

Figure 9: Running time in seconds for (a) ONT1 and (b) ONT2. Peak memory in MB for (c) ONT1 and (d) ONT2.

200

0

0

10 20 n (Millions)

(a)

40

LAMAS (vEB)

q-gram

DTW (Banded)

1000

4000 2000 0

MS

Memory (MB)

Memory (MB)

Time (s)

400

LAMAS (Simple) 6000

Time (s)

LAMAS

100 10 1 0.1

0

10 20 n (Millions)

40

1k

(b)

5k 10k 20k 40k 100k d

(c)

200 150 100 50 0

1k

5k 10k 20k 40k 100k d

(d)

Figure 10: (a) Running time in seconds and (b) peak memory in MB, for varying 𝑛. (c) Running time in seconds and (d) peak memory in MB, for varying 𝑑. our experiments. Figure 9 shows that LAMAS uses 9% and 41% less memory than MS on ONT1 and ONT2, respectively. It also uses 20% and 38% less memory than LAMAS (Simple) and LAMAS (vEB), respectively, on ONT1, and 54% and 77% less on ONT2. Although ED and 𝑞-gram distance use less memory, LAMAS requires only 21.4 MB on average on ONT2, where it is 8.5 times faster than ED. Scalability. We use substrings of Chromosomes 1 and 2 of the human reference genome [Nat13, Nat18]. We compare LAMAS with its non-optimized versions, MS, and 𝑞-gram distance. We omit ED, as it was much slower, and include banded DTW for reference, after encoding DNA letters as integers. Impact of 𝑛. Figure 10(a) shows that the running times grow linearly with 𝑛. We fix 𝑑 = 1000, the DTW band radius 𝑑 = 1000, and 𝑞 = 12; a 𝑞 value in [8, 16] is usually used for DNA sequences [Ken02]. LAMAS consistently outperforms LAMAS (Simple) and LAMAS (vEB) for 𝑛 ≥ 105 . At 𝑛 = 4 · 107 , its running time is 43% lower than that of LAMAS (Simple) and 51% lower than that of LAMAS (vEB). LAMAS is on average 11.3% faster than 𝑞-gram distance and 81.4% faster than banded DTW. MS is much faster than LAMAS, but it does not enforce the displacement constraint, which is useful in the above applications. Figure 10(b) shows that LAMAS achieves its running-time improvements while also reducing memory use. At 𝑛 = 4 · 107 , it uses 53% and 78% less peak memory than LAMAS (Simple) and LAMAS (vEB), respectively. It also uses 46% less memory than MS and 56% less than 𝑞-gram distance, but 49% more than banded DTW. Thus, Improvement 2 in Section 4.3 improves both time and space over the other LAMAS implementations. Impact of 𝑑. Figure 10(c) (𝑛 = 106 ) shows that increasing 𝑑 from 1000 to 105 reduces LAMAS’s running time by 70%. On average over the six values of 𝑑, LAMAS is 68.6%, 70.5%, and 97.5% faster than LAMAS (Simple), LAMAS (vEB), and banded DTW, respectively. 𝑞-gram distance is fastest, followed by MS, which at 𝑑 = 105 is only 22% faster than LAMAS. Figure 10(d) shows that LAMAS uses 52%–54%, 77%–78%, and 42%–45% less memory than LAMAS (Simple), LAMAS (vEB), and MS, respectively; it is comparable to banded DTW, and 𝑞-gram distance uses the least.

18

6

Conclusion

We introduced LAMAS, a location-aware generalization of the well-known MS primitive [CL94], and developed a time-optimal algorithm for computing it that requires O (𝑛) time and space. Our experiments show that LAMAS improves similarity-based classification, retrieval, and clustering. The implementation of our LAMAS algorithm scales linearly in 𝑛 and does not slow down as the displacement tolerance grows.

Declarations The conceptualization, key ideas, and research design originated from the authors. We used GPT-6 Astra and Claude Fable 5.1 to improve the paper’s presentation (including the design of figures and plots), optimize the source code, and assist with the preparation of experiments. The authors remain fully responsible for the correctness and originality of the content, the references, and for the interpretation of the results.

References [ABW15]

Amir Abboud, Arturs Backurs, and Virginia Vassilevska Williams. Tight hardness results for LCS and other sequence similarity measures. In Venkatesan Guruswami, editor, IEEE 56th Annual Symposium on Foundations of Computer Science, FOCS 2015, Berkeley, CA, USA, 17-20 October, 2015, pages 59–78. IEEE Computer Society, 2015. doi: 10.1109/FOCS.2015.14.

[AHWW16] 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 Daniel Wichs and Yishay Mansour, editors, Proceedings of the 48th Annual ACM SIGACT Symposium on Theory of Computing, STOC 2016, Cambridge, MA, USA, June 18-21, 2016, pages 375–388. ACM, 2016. doi:10.1145/2897518.2897653. [AP17]

Lorraine A. K. Ayad and Solon P. Pissis. MARS: improving multiple circular sequence alignment using refined sequences. BMC Genomics, 18:86, 2017. doi: 10.1186/s12864-016-3477-5.

[ARK+ 21]

Omar Ahmed, Massimiliano Rossi, Sam Kovaka, Michael C. Schatz, Travis Gagie, Christina Boucher, and Ben Langmead. Pan-genomic matching statistics for targeted nanopore sequencing. iScience, 24(6):102696, 2021. doi:10.1016/j.isci.2021.102696.

[BF00]

Michael A. Bender and Martin Farach-Colton. The LCA problem revisited. In Gaston H. Gonnet, Daniel Panario, and Alfredo Viola, editors, LATIN 2000: Theoretical Informatics, 4th Latin American Symposium, Punta del Este, Uruguay, April 10-14, 2000, Proceedings, volume 1776 of Lecture Notes in Computer Science, pages 88–94. Springer, 2000. doi: 10.1007/10719839\_9.

[BF08]

Philip Bille and Martin Farach-Colton. Fast and compact regular expression matching. Theor. Comput. Sci., 409(3):486–496, 2008. doi:10.1016/J.TCS.2008.08.042.

[BI18]

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.

[BK15]

Karl Bringmann and Marvin Künnemann. Quadratic conditional lower bounds for string problems and dynamic time warping. In Venkatesan Guruswami, editor, IEEE 56th Annual Symposium on Foundations of Computer Science, FOCS 2015, Berkeley, CA, USA, 17-20 19

October, 2015, pages 79–97. IEEE Computer Society, 2015. doi:10.1109/FOCS.2015. 15. [BR11]

Ricardo Baeza-Yates and Berthier A. Ribeiro-Neto. Modern Information Retrieval - the concepts and technology behind search, Second edition. Pearson Education Ltd., Harlow, England, 2011. URL: http://www.mir2ed.org/.

[CC12]

Supaporn Chairungsee and Maxime Crochemore. Using minimal absent words to build phylogeny. Theor. Comput. Sci., 450:109–116, 2012. doi:10.1016/J.TCS.2012.04.031.

[CCF+ 18]

Panagiotis Charalampopoulos, Maxime Crochemore, Gabriele Fici, Robert Mercas, and Solon P. Pissis. Alignment-free sequence comparison using absent words. Inf. Comput., 262:57–68, 2018. doi:10.1016/J.IC.2018.06.002.

[CFLM25]

Davide Cenzato, Giuditta Franco, Zsuzsanna Lipták, and Alessio Milanese. The threshold q-gram distance: a simple, efficient, and effective distance measure for genomic sequence comparison. Nat. Comput., 24(4):973–989, 2025. doi:10.1007/S11047-025-10054-5.

[CGK16]

Diptarka Chakraborty, Elazar Goldenberg, and Michal Koucký. Streaming algorithms for embedding and computing edit distance in the low distance regime. In Daniel Wichs and Yishay Mansour, editors, Proceedings of the 48th Annual ACM SIGACT Symposium on Theory of Computing, STOC 2016, Cambridge, MA, USA, June 18-21, 2016, pages 712–725. ACM, 2016. doi:10.1145/2897518.2897577.

[CGKK18] Moses Charikar, Ofir Geri, Michael P. Kim, and William Kuszmaul. On estimating edit distance: Alignment, dimension reduction, and embeddings. In Ioannis Chatzigiannakis, Christos Kaklamanis, Dániel Marx, and Donald Sannella, editors, 45th International Colloquium on Automata, Languages, and Programming, ICALP 2018, July 9-13, 2018, Prague, Czech Republic, volume 107 of LIPIcs, pages 34:1–34:14. Schloss Dagstuhl Leibniz-Zentrum für Informatik, 2018. doi:10.4230/LIPICS.ICALP.2018.34. [CH13]

Gideon Creech and Jiankun Hu. Generation of a new IDS test dataset: Time to retire the KDD collection. In 2013 IEEE Wireless Communications and Networking Conference (WCNC), Shanghai, Shanghai, China, April 7-10, 2013, pages 4487–4492. IEEE, 2013. doi:10.1109/WCNC.2013.6555301.

[CKRP26]

Panagiotis Charalampopoulos, Tomasz Kociumaka, Jakub Radoszewski, and Solon P. Pissis. Faster algorithms for longest common substring. ACM Trans. Algorithms, 22(2):19:1–19:47, 2026. doi:10.1145/3774754.

[CL90]

William I. Chang and Eugene L. Lawler. Approximate string matching in sublinear expected time. In 31st Annual Symposium on Foundations of Computer Science, St. Louis, Missouri, USA, October 22-24, 1990, Volume I, pages 116–124. IEEE Computer Society, 1990. doi:10.1109/FSCS.1990.89530.

[CL94]

William I. Chang and Eugene L. Lawler. Sublinear approximate string matching and biological applications. Algorithmica, 12(4/5):327–344, 1994. doi:10.1007/BF01185431.

[CLZ03]

Maxime Crochemore, Gad M. Landau, and Michal Ziv-Ukelson. A subquadratic sequence alignment algorithm for unrestricted scoring matrices. SIAM J. Comput., 32(6):1654–1673, 2003. doi:10.1137/S0097539702402007.

[CRS20]

Peter Christen, Thilina Ranbaduge, and Rainer Schnell. Linking Sensitive Data - Methods and Techniques for Practical Privacy-Preserving Information Sharing. Springer, 2020. doi:10.1007/978-3-030-59706-1.

20

[Dam64]

Fred J. Damerau. A technique for computer detection and correction of spelling errors. Commun. ACM, 7(3):171–176, 1964. doi:10.1145/363958.363994.

[DBK+ 19]

Hoang Anh Dau, Anthony J. Bagnall, Kaveh Kamgar, Chin-Chia Michael Yeh, Yan Zhu, Shaghayegh Gharghabi, Chotirat Ann Ratanamahatana, and Eamonn J. Keogh. The UCR time series archive. IEEE CAA J. Autom. Sinica, 6(6):1293–1305, 2019. doi:10.1109/JAS.2019.1911747.

[DYZ+ 20]

Xinyan Dai, Xiao Yan, Kaiwen Zhou, Yuxuan Wang, Han Yang, and James Cheng. Convolutional embedding for edit distance. In Jimmy X. Huang, Yi Chang, Xueqi Cheng, Jaap Kamps, Vanessa Murdock, Ji-Rong Wen, and Yiqun Liu, editors, Proceedings of the 43rd International ACM SIGIR conference on research and development in Information Retrieval, SIGIR 2020, Virtual Event, China, July 25-30, 2020, pages 599–608. ACM, 2020. doi:10.1145/3397271.3401045.

[FKLR05]

Ada Wai-Chee Fu, Eamonn J. Keogh, Leo Yung Hang Lau, and Chotirat Ann Ratanamahatana. Scaling and time warping in time series querying. In Klemens Böhm, Christian S. Jensen, Laura M. Haas, Martin L. Kersten, Per-Åke Larson, and Beng Chin Ooi, editors, Proceedings of the 31st International Conference on Very Large Data Bases, Trondheim, Norway, August 30 - September 2, 2005, pages 649–660. ACM, 2005. URL: http: //www.vldb.org/archives/website/2005/program/paper/thu/p649-fu.pdf.

[GBMP14] Simon Gog, Timo Beller, Alistair Moffat, and Matthias Petri. From theory to practice: Plug and play with succinct data structures. In Joachim Gudmundsson and Jyrki Katajainen, editors, Experimental Algorithms - 13th International Symposium, SEA 2014, Copenhagen, Denmark, June 29 - July 1, 2014. Proceedings, volume 8504 of Lecture Notes in Computer Science, pages 326–337. Springer, 2014. doi:10.1007/978-3-319-07959-5\_28. [GIM+ 16]

Roberto Grossi, Costas S. Iliopoulos, Robert Mercas, Nadia Pisanti, Solon P. Pissis, Ahmad Retha, and Fatima Vayani. Circular sequence comparison: algorithms and applications. Algorithms Mol. Biol., 11:12, 2016. doi:10.1186/S13015-016-0076-6.

[Gra16]

Szymon Grabowski. New tabulation and sparse dynamic programming based techniques for sequence similarity problems. Discret. Appl. Math., 212:96–103, 2016. doi:10.1016/ J.DAM.2015.10.040.

[GS18]

Omer Gold and Micha Sharir. Dynamic time warping and geometric edit distance: Breaking the quadratic barrier. ACM Trans. Algorithms, 14(4):50:1–50:17, 2018. doi: 10.1145/3230734.

[GT85]

Harold N. Gabow and Robert Endre Tarjan. A linear-time algorithm for a special case of disjoint set union. J. Comput. Syst. Sci., 30(2):209–221, 1985. doi: 10.1016/0022-0000(85)90014-5.

[Gus97]

Dan Gusfield. Algorithms on Strings, Trees, and Sequences - Computer Science and Computational Biology. Cambridge University Press, 1997. doi:10.1017/CBO9780511574931.

[HA85]

Lawrence Hubert and Phipps Arabie. Comparing partitions. J. Classif., 2(1):193–218, 1985. doi:10.1007/BF01908075.

[Hir75]

Daniel S. Hirschberg. A linear space algorithm for computing maximal common subsequences. Commun. ACM, 18(6):341–343, 1975. doi:10.1145/360825.360861.

[HMB24]

Christopher Holder, Matthew Middlehurst, and Anthony J. Bagnall. A review and evaluation of elastic distance functions for time series clustering. Knowl. Inf. Syst., 66(2):765–809, 2024. doi:10.1007/S10115-023-01952-0. 21

[JD88]

Anil K. Jain and Richard C. Dubes. Algorithms for Clustering Data. Prentice Hall, 1988.

[JNR05]

Anil K. Jain, Karthik Nandakumar, and Arun Ross. Score normalization in multimodal biometric systems. Pattern Recognition, 38(12):2270–2285, 2005. doi:10.1016/j. patcog.2005.01.012.

[KCPM01]

Eamonn J. Keogh, Kaushik Chakrabarti, Michael J. Pazzani, and Sharad Mehrotra. Dimensionality reduction for fast similarity search in large time series databases. Knowl. Inf. Syst., 3(3):263–286, 2001. doi:10.1007/PL00011669.

[Ken38]

Maurice G. Kendall. A new measure of rank correlation. Biometrika, 30(1-2):81–93, 1938. doi:10.1093/biomet/30.1-2.81.

[Ken02]

W. James Kent. Blat—the blast-like alignment tool. Genome Research, 12(4):656–664, Apr 2002. doi:10.1101/gr.229202.

[Keo02]

Eamonn J. Keogh. Exact indexing of dynamic time warping. In Proceedings of 28th International Conference on Very Large Data Bases, VLDB 2002, Hong Kong, August 20-23, 2002, pages 406–417. Morgan Kaufmann, 2002. URL: http://www.vldb.org/ conf/2002/S12P01.pdf, doi:10.1016/B978-155860869-6/50043-3.

[KLA+ 01]

Toru Kasai, Gunho Lee, Hiroki Arimura, Setsuo Arikawa, and Kunsoo Park. Linear-time longest-common-prefix computation in suffix arrays and its applications. In Amihood Amir and Gad M. Landau, editors, Combinatorial Pattern Matching, 12th Annual Symposium, CPM 2001 Jerusalem, Israel, July 1-4, 2001 Proceedings, volume 2089 of Lecture Notes in Computer Science, pages 181–192. Springer, 2001. doi:10.1007/3-540-48194-X\_17.

[KSB06]

Juha Kärkkäinen, Peter Sanders, and Stefan Burkhardt. Linear work suffix array construction. J. ACM, 53(6):918–936, 2006. doi:10.1145/1217856.1217858.

[Lev66]

Vladimir I. Levenshtein. Binary codes capable of correcting deletions, insertions, and reversals. Sov. Phys. Dokl., 10(8):707–710, 1966.

[LF22]

Jindrich Libovický and Alexander Fraser. Neural string edit distance. In Andreas Vlachos, Priyanka Agrawal, André F. T. Martins, Gerasimos Lampouras, and Chunchuan Lyu, editors, Proceedings of the Sixth Workshop on Structured Prediction for NLP, SPNLP@ACL 2022, Dublin, Ireland, May 27, 2022, pages 52–66. Association for Computational Linguistics, 2022. doi:10.18653/V1/2022.SPNLP-1.6.

[LKLC03]

Jessica Lin, Eamonn J. Keogh, Stefano Lonardi, and Bill Yuan-chi Chiu. A symbolic representation of time series, with implications for streaming algorithms. In Mohammed Javeed Zaki and Charu C. Aggarwal, editors, Proceedings of the 8th ACM SIGMOD workshop on Research issues in data mining and knowledge discovery, DMKD 2003, San Diego, California, USA, June 13, 2003, pages 2–11. ACM, 2003. doi:10.1145/882082.882086.

[LKWL07] Jessica Lin, Eamonn J. Keogh, Li Wei, and Stefano Lonardi. Experiencing SAX: a novel symbolic representation of time series. Data Min. Knowl. Discov., 15(2):107–144, 2007. doi:10.1007/S10618-007-0064-Z. [LMP26]

Zsuzsanna Lipták, Francesco Masillo, and Simon J. Puglisi. Matching statistics - a survey. Theor. Comput. Sci., 1071:115796, 2026. doi:10.1016/J.TCS.2026.115796.

[LPS23]

Grigorios Loukides, Solon P. Pissis, and Michelle Sweering. Bidirectional string anchors for improved text indexing and top-𝐾 similarity search. IEEE Trans. Knowl. Data Eng., 35(11):11093–11111, 2023. doi:10.1109/TKDE.2022.3231780.

22

[LWYH25] Xijuan Liu, Haobo Wei, Peilun Yang, and Haiyang Hu. CharFormer: Character-oriented attention network for string edit distance. Knowl. Based Syst., 318:113482, 2025. doi: 10.1016/J.KNOSYS.2025.113482. [LZL+ 26]

Ling Li, Wiktor Zuba, Grigorios Loukides, Solon P. Pissis, and Maria Matsangidou. Orderpreserving pattern mining and comparison via indexing. IEEE Trans. Knowl. Data Eng., pages 1–18, 2026. doi:10.1109/TKDE.2026.3710634.

[Mac97]

A. Craig MacKinlay. Event studies in economics and finance. J. Econ. Lit., 35(1):13–39, 1997. URL: https://www.jstor.org/stable/2729691.

[MEG+ 23]

Santiago Marco-Sola, Jordan M. Eizenga, Andrea Guarracino, Benedict Paten, Erik Garrison, and Miquel Moretó. Optimal gap-affine alignment in O(s) space. Bioinform., 39(2), 2023. doi:10.1093/BIOINFORMATICS/BTAD074.

[MM85]

Webb Miller and Eugene W. Myers. A file comparison program. Softw. Pract. Exp., 15(11):1025–1040, 1985. doi:10.1002/SPE.4380151102.

[MM93]

Udi Manber and Eugene W. Myers. Suffix arrays: A new method for on-line string searches. SIAM J. Comput., 22(5):935–948, 1993. doi:10.1137/0222058.

[MMME21] Santiago Marco-Sola, Juan Carlos Moure, Miquel Moretó, and Antonio Espinosa. Fast gap-affine pairwise alignment using the wavefront algorithm. Bioinform., 37(4):456–463, 2021. doi:10.1093/BIOINFORMATICS/BTAA777. [MN06]

Veli Mäkinen and Gonzalo Navarro. Position-restricted substring searching. In José R. Correa, Alejandro Hevia, and Marcos A. Kiwi, editors, LATIN 2006: Theoretical Informatics, 7th Latin American Symposium, Valdivia, Chile, March 20-24, 2006, Proceedings, volume 3887 of Lecture Notes in Computer Science, pages 703–714. Springer, 2006. doi: 10.1007/11682462\_64.

[MRS08]

Christopher D. Manning, Prabhakar Raghavan, and Hinrich Schütze. Introduction to information retrieval. Cambridge University Press, 2008. URL: https://nlp.stanford. edu/IR-book/pdf/irbookprint.pdf, doi:10.1017/CBO9780511809071.

[Nat13]

National Center for Biotechnology Information (NCBI). Homo sapiens chromosome 1, GRCh38.p12 Primary Assembly. RefSeq Nucleotide Accession NC 000001.11, National Library of Medicine (US), Bethesda, MD, 2013. Accessed: October 2026. URL: https: //www.ncbi.nlm.nih.gov/nuccore/NC_000001.11.

[Nat18]

National Center for Biotechnology Information (NCBI). Homo sapiens chromosome 2, GRCh38.p12 Primary Assembly. RefSeq Nucleotide Accession NC 000002.12, National Library of Medicine (US), Bethesda, MD, 2018. Accessed: October 2026. URL: https: //www.ncbi.nlm.nih.gov/nuccore/NC_000002.12.

[Nav01]

Gonzalo Navarro. A guided tour to approximate string matching. ACM Comput. Surv., 33(1):31–88, 2001. doi:10.1145/375360.375365.

[Pai24]

Pairwise Alignment Benchmark (pa-bench). pa-bench datasets, 2024. Accessed: October 2026. URL: https://github.com/pairwise-alignment/pa-bench/releases/ tag/datasets.

[Pea95]

Karl Pearson. Note on regression and inheritance in the case of two parents. Proc. R. Soc. Lond., 58(347-352):240–242, 1895. doi:10.1098/rspl.1895.0041.

23

[PGR+ 02]

Vasiliki Plerou, Parameswaran Gopikrishnan, Bernd Rosenow, Luı́s A. Nunes Amaral, Thomas Guhr, and H. Eugene Stanley. Random matrix approach to cross correlations in financial data. Phys. Rev. E, 65(6):066126, 2002. doi:10.1103/PhysRevE.65.066126.

[PKS25]

Lamprini Pappa, Petros S. Karvelis, and Chrysostomos D. Stylios. Exploring the diverse world of SAX-based methodologies. Data Min. Knowl. Discov., 39(1):1–78, 2025. doi: 10.1007/S10618-024-01075-2.

[PT14]

Mihai Patrascu and Mikkel Thorup. Dynamic integer sets with optimal rank, select, and predecessor search. In 55th IEEE Annual Symposium on Foundations of Computer Science, FOCS 2014, Philadelphia, PA, USA, October 18-21, 2014, pages 166–175. IEEE Computer Society, 2014. doi:10.1109/FOCS.2014.26.

[RK04]

Chotirat Ann Ratanamahatana and Eamonn J. Keogh. Making time-series classification more accurate using learned constraints. In Michael W. Berry, Umeshwar Dayal, Chandrika Kamath, and David B. Skillicorn, editors, Proceedings of the Fourth SIAM International Conference on Data Mining, Lake Buena Vista, Florida, USA, April 22-24, 2004, pages 11–22. SIAM, 2004. doi:10.1137/1.9781611972740.2.

[ROL+ 22]

Massimiliano Rossi, Marco Oliva, Ben Langmead, Travis Gagie, and Christina Boucher. MONI: A pangenomic index for finding maximal exact matches. J. Comput. Biol., 29(2):169– 187, 2022. doi:10.1089/CMB.2021.0290.

[RY98]

Eric Sven Ristad and Peter N. Yianilos. Learning string-edit distance. IEEE Trans. Pattern Anal. Mach. Intell., 20(5):522–532, 1998. doi:10.1109/34.682181.

[SC78]

Hiroaki Sakoe and Seibi Chiba. Dynamic programming algorithm optimization for spoken word recognition. IEEE Trans. Acoust. Speech Signal Process., 26(1):43–49, 1978. doi:10.1109/TASSP.1978.1163055.

[sci]

scikit-learn developers. sklearn.metrics.f1 score. scikit-learn documentation. Accessed: October 19, 2026. URL: https://scikit-learn.org/stable/modules/generated/ sklearn.metrics.f1_score.html.

[SG02]

Alexander Strehl and Joydeep Ghosh. Cluster ensembles - A knowledge reuse framework for combining multiple partitions. J. Mach. Learn. Res., 3:583–617, 2002. doi:10.1162/ 153244303321897735.

[SKS20]

Avi Silberschatz, Henry F. Korth, and S. Sudarshan. Database System Concepts, Seventh Edition. McGraw-Hill Book Company, 2020. URL: https://www.db-book.com/.

[Spe04]

Charles Spearman. The proof and measurement of association between two things. Am. J. Psychol., 15(1):72–101, 1904. doi:10.2307/1412159.

[ŠŠ17]

Martin Šošić and Mile Šikić. Edlib: a C/C++ library for fast, exact sequence alignment using edit distance. Bioinform., 33(9):1394–1395, 2017. doi:10.1093/BIOINFORMATICS/ BTW753.

[UBTC06]

Igor Ulitsky, David Burstein, Tamir Tuller, and Benny Chor. The average common substring approach to phylogenomic reconstruction. J. Comput. Biol., 13(2):336–350, 2006. doi:10.1089/CMB.2006.13.336.

[UCRa]

UCR/UEA Time Series Classification Repository. AconityMINIPrinterSmall dataset. Accessed: October 2026. URL: https://www.timeseriesclassification.com/ aeon-toolkit/AconityMINIPrinterSmall.zip.

24

[UCRb]

UCR/UEA Time Series Classification Repository. ACSF1 dataset. Accessed: October 2026. URL: https://www.timeseriesclassification.com/description.php? Dataset=ACSF1.

[UCRc]

UCR/UEA Time Series Classification Repository. ArticularyWordRecognition dataset. Accessed: October 2026. URL: https://www.timeseriesclassification.com/ description.php?Dataset=ArticularyWordRecognition.

[UCRd]

UCR/UEA Time Series Classification Repository. CharacterTrajectories dataset. Accessed: October 2026. URL: https://www.timeseriesclassification.com/description. php?Dataset=CharacterTrajectories.

[UCRe]

UCR/UEA Time Series Classification Repository. Chinatown dataset. Accessed: October 2026. URL: https://www.timeseriesclassification.com/description. php?Dataset=Chinatown.

[UCRf]

UCR/UEA Time Series Classification Repository. Crop dataset. Accessed: October 2026. URL: https://www.timeseriesclassification.com/description.php? Dataset=Crop.

[UCRg]

UCR/UEA Time Series Classification Repository. EOGHorizontalSignal dataset. Accessed: October 2026. URL: https://www.timeseriesclassification.com/description. php?Dataset=EOGHorizontalSignal.

[UCRh]

UCR/UEA Time Series Classification Repository. FacesUCR dataset. Accessed: October 2026. URL: https://www.timeseriesclassification.com/description. php?Dataset=FacesUCR.

[UCRi]

UCR/UEA Time Series Classification Repository. Fish dataset. Accessed: October 2026. URL: https://www.timeseriesclassification.com/description.php? Dataset=Fish.

[UCRj]

UCR/UEA Time Series Classification Repository. GesturePebbleZ1 dataset. Accessed: October 2026. URL: https://www.timeseriesclassification.com/description. php?Dataset=GesturePebbleZ1.

[UCRk]

UCR/UEA Time Series Classification Repository. Meat dataset. Accessed: October 2026. URL: https://www.timeseriesclassification.com/description.php? Dataset=Meat.

[UCRl]

UCR/UEA Time Series Classification Repository. MixedShapesSmallTrain dataset. Accessed: October 2026. URL: https://www.timeseriesclassification.com/ description.php?Dataset=MixedShapesSmallTrain.

[UCRm]

UCR/UEA Time Series Classification Repository. PenDigits dataset. Accessed: October 2026. URL: https://www.timeseriesclassification.com/description. php?Dataset=PenDigits.

[UCRn]

UCR/UEA Time Series Classification Repository. ShakeGestureWiimoteZ dataset. Accessed: October 2026. URL: https://www.timeseriesclassification.com/ description.php?Dataset=ShakeGestureWiimoteZ.

[UCRo]

UCR/UEA Time Series Classification Repository. StarLightCurves dataset. Accessed: October 2026. URL: https://www.timeseriesclassification.com/description. php?Dataset=StarLightCurves.

25

[UCRp]

UCR/UEA Time Series Classification Repository. UWaveGestureLibrary dataset. Accessed: October 2026. URL: https://www.timeseriesclassification.com/description. php?Dataset=UWaveGestureLibrary.

[UCRq]

UCR/UEA Time Series Classification Repository. WordSynonyms dataset. Accessed: October 2026. URL: https://www.timeseriesclassification.com/description. php?Dataset=WordSynonyms.

[Ukk85]

Esko Ukkonen. Algorithms for approximate string matching. Inf. Control., 64(1-3):100–118, 1985. doi:10.1016/S0019-9958(85)80046-2.

[Ukk92]

Esko Ukkonen. Approximate string matching with q-grams and maximal matches. Theor. Comput. Sci., 92(1):191–211, 1992. doi:10.1016/0304-3975(92)90143-4.

[vEB77]

Peter van Emde Boas. Preserving order in a forest in less than logarithmic time and linear space. Inf. Process. Lett., 6(3):80–82, 1977. doi:10.1016/0020-0190(77)90031-X.

[VGK02]

Michail Vlachos, Dimitrios Gunopulos, and George Kollios. Discovering similar multidimensional trajectories. In Rakesh Agrawal and Klaus R. Dittrich, editors, Proceedings of the 18th International Conference on Data Engineering, San Jose, CA, USA, February 26 - March 1, 2002, pages 673–684. IEEE Computer Society, 2002. doi:10.1109/ICDE.2002.994784.

[WF74]

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.

[Yah20]

Yahoo Finance. Historical adjusted closing prices for Apple, Microsoft, and Moderna, 2020. Daily observations from 3 February to 30 June 2020; accessed: October 22, 2026. URL: https://finance.yahoo.com/.

[Yan14]

Ziheng Yang. Molecular Evolution: A Statistical Approach. Oxford University Press, 2014. doi:10.1093/acprof:oso/9780199602605.001.0001.

[ZHD26]

Zhou Zhou, Gang Huang, and Laura Dawkins. Dynamic sub-sequence warping: A representation-based similarity measure for long time series. Data Sci. Eng., 11(1):260–274, 2026. doi:10.1007/S41019-025-00331-9.

[ZZ17]

Haoyu Zhang and Qin Zhang. EmbedJoin: Efficient edit similarity joins via embeddings. In Proceedings of the 23rd ACM SIGKDD International Conference on Knowledge Discovery and Data Mining, Halifax, NS, Canada, August 13 - 17, 2017, pages 585–594. ACM, 2017. doi:10.1145/3097983.3098003.

[ZZ20a]

Haoyu Zhang and Qin Zhang. MinSearch: An efficient algorithm for similarity search under edit distance. In Rajesh Gupta, Yan Liu, Jiliang Tang, and B. Aditya Prakash, editors, KDD ’20: The 26th ACM SIGKDD Conference on Knowledge Discovery and Data Mining, Virtual Event, CA, USA, August 23-27, 2020, pages 566–576. ACM, 2020. doi:10.1145/3394486.3403099.

[ZZ20b]

Haoyu Zhang and Qin Zhang. MinSearch: Source code, 2020. Accessed: November 4, 2026. URL: https://github.com/kedayuge/Search.

26

Related documents

Record · ID 1767920 · SHA-256 f8c255ad47127064
Retrieved via Conceptio: every document is proof-bundled with source, license, and retrieval metadata.
Bring this data into your agent: Connect via MCP or API · 20 free credits to start · no card required
Read the Docs → · View CLI source on GitHub · Conceptio Open Knowledge Archive