Space-Efficient Text Indexing for Advanced Counting Queries
Abstract
In the classical problem of text indexing, the objective is to preprocess a text $T=T[1..n]$ over an integer alphabet $[0..σ)$ into a data structure that supports efficient pattern matching queries. Given a pattern $P=P[1..m]$, a reporting query lists the set $\mathsf{Occ}_T(P)$ of occurrences of $P$ in $T$, whereas a counting query returns $|\mathsf{Occ}_T(P)|$. Space-efficient suffix-tree variants use only $\mathcal{O}(n\logσ)$ bits and support reporting queries in $\mathcal{O}(m+|\mathsf{Occ}_T(P)|\cdot\log_σ^ε n)$ time, where $ε>0$ is an arbitrarily small constant, and counting queries in $\mathcal{O}(m)$ time. Notably, space-efficient indexes for more advanced counting queries have largely resisted achieving the same optimal (or near-optimal) query times when using less than $Θ(n\log n)$ bits. We change this situation by proposing a general framework that supports advanced counting queries, denoted by $φ_T(P)$, provided that $φ_T$ satisfies two mild conditions: (1) $φ_T(P)$ is an integer in $[0..|\mathsf{Occ}_T(P)|]$ that can be computed from $\mathsf{Occ}_T(P)$ via sorting; and (2) $φ_T(Q)\geqφ_T(P)$ for every prefix $Q$ of $P$. We show that our framework supports optimal $\mathcal{O}(m)$-time queries using $\mathcal{O}(n\logσ+n(\log\log n)^2)$ bits or near-optimal $\mathcal{O}(m\log_σ^ε n)$-time queries using $\mathcal{O}(n\logσ)$ bits. As an example, our trade-offs improve upon the classical MAST index for counting non-overlapping occurrences [Apostolico and Preparata, Algorithmica, 1996; Brodal et al., ICALP 2002], which uses $\mathcal{O}(n\log n)$ bits and supports $\mathcal{O}(m)$-time queries, and the recent compact index for the same problem [Bals et al., ESA 2026], which uses $\mathcal{O}(n\logσ)$ bits and supports $\mathcal{O}(m\log n\log_σ^ε n)$-time queries.
- Comment
- SOSA 2027 (abstract abridged to satisfy arXiv requirements)