Skip to content

Pattern Matching with Edits in O~(n+k3⋅n/m)\tilde{O}(n+k^3\cdot n/m) Time

Tomasz Kociumaka

cs.DS

Abstract

Given a pattern PP of length mm, a text TT of length nn, and a threshold kk, the Pattern Matching with Edits problem asks whether TT contains a substring that can be transformed into PP using at most kk character insertions, deletions, and substitutions. The classic O(nm)O(nm)- and O(nk)O(nk)-time algorithms of Sellers [J. Algorithms'80] and Landau and Vishkin [STOC'86, J. Algorithms'89] are near-optimal for k=Θ(m)k=Θ(m) under the Orthogonal Vectors Hypothesis. For small kk, Cole and Hariharan [SODA'98, SICOMP'02] achieved O(n+k4⋅n/m)O(n+k^4\cdot n/m) time, and Charalampopoulos, Kociumaka, and Wellnitz (CKW) [FOCS'22] improved this to O(n+k3.5log⁡k⋅n/m)O(n+k^{3.5}\log k\cdot n/m), essentially halfway to the O(n+k3⋅n/m)O(n+k^3\cdot n/m) bound conjectured by Cole and Hariharan. This work confirms the conjecture up to a polylogarithmic factor with an O(n+k3log⁡2k⋅n/m)O(n+k^3\log^2 k\cdot n/m)-time algorithm. Working in the PILLAR model [CKW; FOCS'20], which accesses strings only through a few basic operations, it extends to grammar-compressed, dynamic, quantum, and small-space read-only settings. It also closes, up to the log⁡2k\log^2 k factor, the longstanding gap to certain aperiodic patterns, for which Cole and Hariharan achieved O(n+k3⋅n/m)O(n+k^3\cdot n/m) time. The alternative approach of CKW [FOCS'20] leaves one bottleneck, which the general case reduces to: PP and TT are close to periodic strings with a common period. This case amounts to many min-plus products of distance matrices, each consisting of long runs of one fixed matrix separated by O(k)O(k) other matrices. We collapse every long run into a single matrix and show that this preserves the distances that determine the occurrences unless the periodicity-breaking parts of PP and TT interact strongly. Our main structural result, a planar variation theorem, confines the exact computations needed in the remaining cases to narrow regions of the alignment graph.

Create a lesson