Abstract
This paper introduces the Basic Substring Structure (BASS), a novel $O(n)$-sized data structure designed to solve the Internal Dictionary Matching (IDM) problem with near-optimal efficiency. BASS provides the first algorithm capable of answering "distinct pattern counting" queries in $O(\log n)$ time, resolving a significant open question in string algorithms while maintaining competitive performance for existence and reporting queries.
Introduction
In classical dictionary matching, a set of patterns (a dictionary $D$) is sought within a text $T$. The Internal Dictionary Matching (IDM) problem specializes this by requiring that the patterns in $D$ are themselves substrings of $T$. This scenario is prevalent in bioinformatics and data compression, where researchers often need to query occurrences of specific internal structures like palindromes or squares within a given range $T[l, r]$.
Historically, researchers have struggled to develop a single data structure that handles diverse query types—such as Exists, Count, and CountDistinct—without incurring prohibitive costs in preprocessing time or memory. The BASS structure addresses these challenges by reducing string problems to geometric ones.
The BASS Framework: Geometric Reduction
The core innovation of BASS is the transformation of substrings into points on a 2D grid. Every substring $T[i, j]$ is mapped to a point $(i, j)$. To avoid the $O(nd)$ space complexity that would arise from marking every occurrence of every pattern, the authors group substrings into equivalence classes based on their occurrences.
These equivalence classes form connected, staircase-shaped "blocks" on the grid. By proving that the total number of boundary elements for all blocks is only $O(n)$, the authors ensure the structure remains space-efficient even for massive texts.
Algorithmic Components
To navigate the relationships between these geometric blocks, BASS utilizes two specialized suffix trees: PreTree (based on $T$) and SufTree (based on the reverse of $T$). These trees allow the algorithm to efficiently locate the relevant blocks for a given query range.
For the complex CountDistinct query, the authors decompose the problem into standard Count queries and a correction term. This is achieved using Link-Cut Trees to track dynamic changes in substring occurrences and Persistent Segment Trees to perform range queries over the history of those changes.
Key Results
The BASS structure matches or improves upon the previous state-of-the-art for every major IDM query type, as shown in the table below:
| Query Type | BASS Result (Query Time) | Previous Best (Query Time) |
|---|---|---|
| CountDistinct | $O(\log n)$ | $O(m)$ (where $m$ is a large parameter) |
| Count | $O(\frac{\log n}{\log \log n})$ | $O(\frac{\log^2 n}{\log \log n})$ |
| ReportDistinct | $O(1 + |output|)$ | $O(\log n + |output|)$ |
| Exists | $O(1)$ | $O(1)$ |
| Report | $O(1 + |output|)$ | $O(1 + |output|)$ |
These bounds are achieved with a data structure requiring approximately $O(n + d)$ space and near-linear preprocessing time.
Conclusion and Future Work
BASS represents a significant theoretical advancement in string algorithms, particularly in its handling of distinctness queries. However, the reliance on complex structures like Link-Cut Trees and Persistent Segment Trees may present challenges for practical implementation. Future research may focus on simplifying these components for real-world software libraries or extending the framework to handle dynamic dictionaries where patterns are frequently added or removed.
Summary updated