English

An Almost Optimal Edit Distance Oracle

Data Structures and Algorithms 2021-03-08 v1

Abstract

We consider the problem of preprocessing two strings SS and TT, of lengths mm and nn, respectively, in order to be able to efficiently answer the following queries: Given positions i,ji,j in SS and positions a,ba,b in TT, return the optimal alignment of S[i..j]S[i \mathinner{.\,.} j] and T[a..b]T[a \mathinner{.\,.} b]. Let N=mnN=mn. We present an oracle with preprocessing time N1+o(1)N^{1+o(1)} and space N1+o(1)N^{1+o(1)} that answers queries in log2+o(1)N\log^{2+o(1)}N time. In other words, we show that we can query the alignment of every two substrings in almost the same time it takes to compute just the alignment of SS and TT. Our oracle uses ideas from our distance oracle for planar graphs [STOC 2019] and exploits the special structure of the alignment graph. Conditioned on popular hardness conjectures, this result is optimal up to subpolynomial factors. Our results apply to both edit distance and longest common subsequence (LCS). The best previously known oracle with construction time and size O(N)\mathcal{O}(N) has slow Ω(N)\Omega(\sqrt{N}) query time [Sakai, TCS 2019], and the one with size N1+o(1)N^{1+o(1)} and query time log2+o(1)N\log^{2+o(1)}N (using a planar graph distance oracle) has slow Ω(N3/2)\Omega(N^{3/2}) construction time [Long & Pettie, SODA 2021]. We improve both approaches by roughly a N\sqrt N factor.

Keywords

Cite

@article{arxiv.2103.03294,
  title  = {An Almost Optimal Edit Distance Oracle},
  author = {Panagiotis Charalampopoulos and Paweł Gawrychowski and Shay Mozes and Oren Weimann},
  journal= {arXiv preprint arXiv:2103.03294},
  year   = {2021}
}
R2 v1 2026-06-23T23:46:23.250Z