English

Nearly Optimal Internal Dictionary Matching

Data Structures and Algorithms 2025-05-16 v3

Abstract

We study the internal dictionary matching (IDM) problem where a dictionary D\mathcal{D} containing dd substrings of a text TT is given, and each query concerns the occurrences of patterns in D\mathcal{D} in another substring of TT. We propose a novel O(n)O(n)-sized data structure named Basic Substring Structure (BASS) where nn is the length of the text T.T. With BASS, we are able to handle all types of queries in the IDM problem in nearly optimal query and preprocessing time. Specifically, our results include: \bullet The first algorithm that answers the CountDistinct query in O~(1)\tilde{O}(1) time with O~(n+d)\tilde{O}(n+d) preprocessing, where we need to compute the number of distinct patterns that exist in T[l,r]T[l,r]. Previously, the best result was O~(m)\tilde{O}(m) time per query after O~(n2/m+d)\tilde{O}(n^2/m+d) or O~(nd/m+d)\tilde{O}(nd/m+d) preprocessing, where mm is a chosen parameter. \bullet Faster algorithms for two other types of internal queries. We improve the runtime for (1) Occurrence counting (Count) queries to O(logn/loglogn)O(\log n/\log\log n) time per query with O(n+dlogn)O(n+d\sqrt{\log n}) preprocessing from O(log2n/loglogn)O(\log^2 n/\log\log n) time per query with O(nlogn/loglogn+dlog3/2n)O(n\log n/\log \log n+d\log^{3/2} n) preprocessing. (2) Distinct pattern reporting (ReportDistinct) queries to O(1+output)O(1+|\text{output}|) time per query from O(logn+output)O(\log n+|\text{output}|) per query. In addition, we match the optimal runtime in the remaining two types of queries, pattern existence (Exists), and occurrence reporting (Report). We also show that BASS is more generally applicable to other internal query problems.

Keywords

Cite

@article{arxiv.2312.11873,
  title  = {Nearly Optimal Internal Dictionary Matching},
  author = {Jingbang Chen and Jiangqi Dai and Qiuyang Mang and Qingyu Shi and Tingqiang Xu},
  journal= {arXiv preprint arXiv:2312.11873},
  year   = {2025}
}

Comments

25 pages

R2 v1 2026-06-28T13:55:39.102Z