English

Pattern Matching on Grammar-Compressed Strings in Linear Time

Data Structures and Algorithms 2021-11-10 v1

Abstract

The most fundamental problem considered in algorithms for text processing is pattern matching: given a pattern pp of length mm and a text tt of length nn, does pp occur in tt? Multiple versions of this basic question have been considered, and by now we know algorithms that are fast both in practice and in theory. However, the rapid increase in the amount of generated and stored data brings the need of designing algorithms that operate directly on compressed representations of data. In the compressed pattern matching problem we are given a compressed representation of the text, with nn being the length of the compressed representation and NN being the length of the text, and an uncompressed pattern of length mm. The most challenging (and yet relevant when working with highly repetitive data, say biological information) scenario is when the chosen compression method is capable of describing a string of exponential length (in the size of its representation). An elegant formalism for such a compression method is that of straight-line programs, which are simply context-free grammars describing exactly one string. While it has been known that compressed pattern matching problem can be solved in O(m+nlogN)O(m+n\log N) time for this compression method, designing a linear-time algorithm remained open. We resolve this open question by presenting an O(n+m)O(n+m) time algorithm that, given a context-free grammar of size nn that produces a single string tt and a pattern pp of length mm, decides whether pp occurs in tt as a substring. To this end, we devise improved solutions for the weighted ancestor problem and the substring concatenation problem.

Keywords

Cite

@article{arxiv.2111.05016,
  title  = {Pattern Matching on Grammar-Compressed Strings in Linear Time},
  author = {Moses Ganardi and Paweł Gawrychowski},
  journal= {arXiv preprint arXiv:2111.05016},
  year   = {2021}
}
R2 v1 2026-06-24T07:31:57.182Z