English

Counting Distinct Patterns in Internal Dictionary Matching

Data Structures and Algorithms 2020-05-13 v1

Abstract

We consider the problem of preprocessing a text TT of length nn and a dictionary D\mathcal{D} in order to be able to efficiently answer queries CountDistinct(i,j)CountDistinct(i,j), that is, given ii and jj return the number of patterns from D\mathcal{D} that occur in the fragment T[i..j]T[i \mathinner{.\,.} j]. The dictionary is internal in the sense that each pattern in D\mathcal{D} is given as a fragment of TT. This way, the dictionary takes space proportional to the number of patterns d=Dd=|\mathcal{D}| rather than their total length, which could be Θ(nd)\Theta(n\cdot d). An O~(n+d)\tilde{\mathcal{O}}(n+d)-size data structure that answers CountDistinct(i,j)CountDistinct(i,j) queries O(logn)\mathcal{O}(\log n)-approximately in O~(1)\tilde{\mathcal{O}}(1) time was recently proposed in a work that introduced internal dictionary matching [ISAAC 2019]. Here we present an O~(n+d)\tilde{\mathcal{O}}(n+d)-size data structure that answers CountDistinct(i,j)CountDistinct(i,j) queries 22-approximately in O~(1)\tilde{\mathcal{O}}(1) time. Using range queries, for any mm, we give an O~(min(nd/m,n2/m2)+d)\tilde{\mathcal{O}}(\min(nd/m,n^2/m^2)+d)-size data structure that answers CountDistinct(i,j)CountDistinct(i,j) queries exactly in O~(m)\tilde{\mathcal{O}}(m) time. We also consider the special case when the dictionary consists of all square factors of the string. We design an O(nlog2n)\mathcal{O}(n \log^2 n)-size data structure that allows us to count distinct squares in a text fragment T[i..j]T[i \mathinner{.\,.} j] in O(logn)\mathcal{O}(\log n) time.

Keywords

Cite

@article{arxiv.2005.05681,
  title  = {Counting Distinct Patterns in Internal Dictionary Matching},
  author = {Panagiotis Charalampopoulos and Tomasz Kociumaka and Manal Mohamed and Jakub Radoszewski and Wojciech Rytter and Juliusz Straszyński and Tomasz Waleń and Wiktor Zuba},
  journal= {arXiv preprint arXiv:2005.05681},
  year   = {2020}
}

Comments

Accepted to CPM 2020

R2 v1 2026-06-23T15:29:03.776Z