Internal Pattern Matching Queries in a Text and Applications
Tomasz Kociumaka,Jakub Radoszewski,Wojciech Rytter,Tomasz Waleń
DOI: https://doi.org/10.1137/23m1567618
2024-10-16
SIAM Journal on Computing
Abstract:SIAM Journal on Computing, Volume 53, Issue 5, Page 1524-1577, October 2024. We consider several types of internal queries, that is, questions about fragments of a given text [math] specified in constant space by their locations in [math]. Our main result is an optimal data structure for internal pattern matching (IPM) queries, which, given two fragments [math] and [math], ask for a representation of all fragments contained in [math] and matching [math] exactly. This problem can be viewed as an internal version of the fundamental exact pattern matching problem: We are looking for exact occurrences of one substring of [math] within another substring of [math]. Our data structure answers IPM queries in time proportional to the quotient [math] of the fragments' lengths, which is required due to the worst-case information content of the output. If [math] is a text of length [math] over an integer alphabet of size [math], then our data structure occupies [math] machine words (that is, [math] bits) and admits an [math]-time construction algorithm. We also show how to use IPM queries for answering internal queries corresponding to other classic string processing problems. Among others, we derive optimal data structures reporting the periods of a fragment and testing the cyclic equivalence of two fragments. Since the publication of the conference version of this paper [Kociumaka et al., Internal pattern matching queries in a text and applications, SODA 2015], IPM queries have found numerous further applications, following the path paved by the classic longest common extension (LCE) queries of Landau and Vishkin [J. Comput. System Sci., 37 (1988), pp. 63–78]. In particular, IPM queries have been implemented in grammar-compressed and dynamic settings and, along with LCE queries, constitute elementary operations of the [math] model, developed by Charalampopoulos, Kociumaka, and Wellnitz [Faster approximate pattern matching: A unified approach, FOCS 2020] to design approximate pattern matching algorithms that work in multiple settings. All our algorithms are deterministic, whereas the data structure in the conference version of the paper only admits a randomized construction in [math] expected time. To achieve this, we provide a novel construction of string synchronizing sets of Kempa and Kociumaka [String synchronizing sets: Sublinear-time BWT construction and optimal LCE data structure, STOC 2019]. Our method, based on a new restricted version of the recompression technique of Jeż [J. ACM, 63 (2016), pp. 4:1–4:51], yields a hierarchy of [math] string synchronizing sets covering the whole spectrum of the fragments' lengths.
computer science, theory & methods,mathematics, applied