Pattern Matching on Compressed Text Indexes

24 concepts10 papers1 proposal

Large datasets—such as genomic sequences, source code repositories, and execution traces—are frequently stored in compressed formats to save space. Traditionally, searching these datasets required a costly decompression step, creating a massive bottleneck in both time and memory overhead.

Compressed text indexing changes this paradigm. Instead of decompressing data before searching, modern compressed indexes allow algorithms to perform complex pattern matching queries directly on the compressed representation. Crucially, this is not just a way to save memory; it fundamentally alters the computational complexity landscape. By exploiting the structural regularities of compression, these techniques frequently bypass theoretical lower bounds that limit search speeds on uncompressed text.

Searching the Grammar, Not the Characters

To understand how it is possible to search a text without looking at its raw characters, consider grammar-based compression. A popular framework is the Straight-Line Program (SLP), which represents a long string as a context-free grammar that generates exactly one sequence. If a specific phrase repeats thousands of times across a dataset, the SLP collapses those repetitions into a single production rule.

When we query a grammar-compressed index, we are not scanning a linear sequence of characters. Instead, we are traversing the hierarchical structure of the grammar rules. As Duyster demonstrates in Logarithmic-Time Internal Pattern Matching Queries in Compressed and Dynamic Texts, internal pattern matching queries can achieve an optimal logarithmic time complexity directly on run-length straight-line programs without requiring any auxiliary data structures or extra preprocessing.

By operating directly on the rules rather than the expanded text, the search algorithm evaluates entire blocks of repetitive text simultaneously. If a pattern matches a high-level grammar variable, the algorithm instantly identifies matches across all instances generated by that variable, avoiding redundant character comparisons.

Bypassing the Square-Root Barrier

The true power of this approach becomes evident when tackling problems that are computationally "hard" on standard text. A prime example is finding gapped consecutive occurrences—locating pairs of patterns that appear close to each other in a text without any other matches in between.

On uncompressed text of length $N$, this problem faces a strict conditional lower bound: queries are bottlenecked by an $\Omega(\sqrt{N})$ time barrier. However, in Compressed Indexing for Consecutive Occurrences, Gawrychowski et al. showed that indexing based on grammar size rather than uncompressed text length completely bypasses this square-root limitation.

Because highly repetitive datasets have a grammar size significantly smaller than their total text length, operating on the compressed representation yields polylogarithmic query times relative to the original text length. In Compressed Consecutive Pattern Matching and its extended analysis in Compressed consecutive pattern matching, Gawrychowski et al. designed polynomial-space indexes that achieve near-optimal query speeds proportional to the compressed representation size and the pattern length. This allows proximity-based ranking and distance-constrained queries to scale with the information content of the data, rather than its raw footprint.

Adapting Diverse Compression Architectures

The principle of direct compressed querying extends well beyond context-free grammars. Researchers have adapted several classical compression paradigms to support high-speed pattern matching:

  • Run-Length Burrows-Wheeler Transform (RL-BWT): In genomic datasets, strings are highly repetitive but massive. Sanaullah et al. in An Efficient Data Structure and Algorithm for Long-Match Query in Run-Length Compressed BWT augmented the RL-BWT to support constant-time queries for the Permuted Longest Common Prefix (PLCP) and the phi array. This optimization allows match lengths to be calculated rapidly without decompression, enabling high-speed string comparisons within a compressed memory space.
  • LZ77 and Phrase Tries: Sometimes the text is uncompressed, but the incoming queries are compressed. Bille et al. addressed this in String Indexing with Compressed Patterns by constructing a compact phrase trie from the LZ77 parses of all suffixes of a text. This structure facilitates efficient matching of prefixes from a compressed pattern directly against the text's encoded representation, yielding near-optimal query times that scale with the compressed pattern's phrase count rather than its uncompressed length.
  • Repetition-Aware Suffix Graphs: Many compressed indexes suffer from a trade-off where reducing memory footprint inflates search time to a factor proportional to the square of the pattern length. To resolve this, Takagi et al. in Linear-size CDAWG: new repetition-aware indexing and grammar compression bridged Compact Directed Acyclic Word Graphs (CDAWGs) with grammar compression, creating a linear-size structure that eliminates these suboptimal search penalties.
  • Dictionary-Based Execution Traces: For specialized data like control flow traces, Lin et al. in The design and evaluation of path matching schemes on compressed control flow traces extended dictionary-based compression with specialized flags encoding nesting levels and function contexts, allowing execution path matching directly on the compressed trace.

The Limits of the Space-Time Trade-Off

Despite these breakthroughs, compressed indexing is bounded by fundamental algorithmic trade-offs. The performance gains depend heavily on the alignment between the query type and the underlying compression scheme.

For example, enforcing strict distance constraints between multiple patterns introduces severe space penalties. As Gawrychowski et al. observed, while unconstrained consecutive matching scales quadratically with grammar size, adding specific gap constraints introduces a high-degree polynomial space exponent to maintain optimal query speeds.

Furthermore, certain query types are fundamentally resistant to acceleration via preprocessing. In A Conditional Lower Bound for Episode Matching, Bille et al. proved that for general subsequence queries (episode matching), achieving sub-quadratic query times requires an impractical amount of storage space that scales exponentially with the length of the pattern.

Similarly, in applications like heuristic search, Schreiber et al. demonstrated in Using Partitions and Superstrings for Lossless Compression of Pattern Databases that order-of-magnitude size reductions are possible, but they require careful partitioning and superstring optimization to preserve the near-constant time random access required by real-time search heuristics.

Ultimately, the field demonstrates that compression does not merely minimize disk space; when designed correctly, the grammar rules and dictionary phrases of a compressed index serve as a pre-computed map of the text's internal symmetries, unlocking search speeds that are theoretically impossible on raw data.

Key Foundational Work

Approximate String Matching with Compressed Indexes (2009) — contributed 3 concept elements to this direction.
The design and evaluation of path matching schemes on compressed control flow traces (2007) — contributed 1 concept elements to this direction.
History & citationVersion 1 · 2026-10-04

Current · Permanent link

View frozen version 1

Cite this direction

Latest version (a living page):

@misc{lacuna_space_time_indexing_trade_off_a4eaf95f,
  title = {space-time indexing trade-off},
  author = {{Lacuna}},
  howpublished = {Lacuna research direction},
  year = {2026},
  url = {https://lacuna.tiptreesystems.com/direction/space-time-indexing-trade-off/rdr_a4eaf95fc22146ed8639176570e2d5aa},
  note = {Latest version of a living research direction; cite a version for a fixed text. Accessed 2026-11-27},
}

This exact version (version 1, frozen text):

@misc{lacuna_space_time_indexing_trade_off_a4eaf95f_v1,
  title = {space-time indexing trade-off},
  author = {{Lacuna}},
  howpublished = {Lacuna research direction},
  year = {2026},
  url = {https://lacuna.tiptreesystems.com/direction/space-time-indexing-trade-off/rdr_a4eaf95fc22146ed8639176570e2d5aa/v/1},
  note = {Version 1, frozen 2026-10-04. Accessed 2026-11-27},
}
About

These directions overlap with this one through shared papers.

See something wrong? Report a mistake