Counting Distinct Patterns in Internal Dictionary Matching
Preprint
Abstract
We consider the problem of preprocessing a text $T$ of length $n$ and a dictionary $\mathcal{D}$ in order to be able to efficiently answer queries $CountDistinct(i,j)$, that is, given $i$ and $j$ return the number of patterns from $\mathcal{D}$ that occur in the fragment $T[i \mathinner{.\,.} j]$. The dictionary is internal in the sense that each pattern in $\mathcal{D}$ is given as a fragment of $T$. This way, the dictionary takes space proportional to the number of patterns $d=|\mathcal{D}|$ rather than their total length, which could be $\Theta(n\cdot d)$. An $\tilde{\mathcal{O}}(n+d)$-size data structure that answers $CountDistinct(i,j)$ queries $\mathcal{O}(\log n)$-approximately in $\tilde{\mathcal{O}}(1)$ time was recently proposed in a work that introduced internal dictionary matching [ISAAC 2019]. Here we present an $\tilde{\mathcal{O}}(n+d)$-size data structure that answers $CountDistinct(i,j)$ queries $2$-approximately in $\tilde{\mathcal{O}}(1)$ time. Using range queries, for any $m$, we give an $\tilde{\mathcal{O}}(\min(nd/m,n^2/m^2)+d)$-size data structure that answers $CountDistinct(i,j)$ queries exactly in $\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 $\mathcal{O}(n \log^2 n)$-size data structure that allows us to count distinct squares in a text fragment $T[i \mathinner{.\,.} j]$ in $\mathcal{O}(\log n)$ time.
Keywords
All Related Versions
This publication has 22 references indexed in Scilit:
- Counting Palindromes in Substrings2017
- How many double squares can a string contain?Discrete Applied Mathematics, 2015
- Extracting powers and periods in a word from its runs structureTheoretical Computer Science, 2014
- The total run length of a wordTheoretical Computer Science, 2013
- Constructing Efficient Dictionaries in Close to Sorting Time2008
- Linear time algorithms for finding and representing all the tandem repeats in a stringJournal of Computer and System Sciences, 2004
- Simple and flexible detection of contiguous repeats using a suffix treeTheoretical Computer Science, 2001
- How Many Squares Can a String Contain?Journal of Combinatorial Theory, Series A, 1998
- Log-logarithmic worst-case range queries are possible in space Θ(N)Information Processing Letters, 1983
- An optimal algorithm for computing the repetitions in a wordInformation Processing Letters, 1981