Papers
Topics
Authors
Recent
2000 character limit reached

Grammar-Compressed Index Structures

Updated 30 December 2025
  • Grammar-compressed index structures are succinct representations that compress repetitive strings, trees, or sequences using context-free grammars like SLP and RLSLP.
  • They integrate auxiliary data structures such as tries and succinct trees to support efficient search, pattern matching, and random access directly on the compressed data.
  • These structures achieve significant space savings and provide effective query support for applications in text, XML, and spatio-temporal databases.

A grammar-compressed index structure is a class of succinct and algorithmically rich data structures built by compressing a string, sequence, or tree using a context-free grammar (CFG)—typically in the form of a straight-line program (SLP), run-length grammar, or an augmented variant—and integrating auxiliary structures that enable fast search, extraction, navigation, and often higher-level analytics directly on the compressed form. These indexes are geared toward highly repetitive data and enable both dramatic space reduction and efficient query support. Grammar-compressed index structures have significantly influenced progress in text, sequence, and tree indexing, with numerous theoretical and engineering breakthroughs over the last two decades.

1. Formal Models and Core Definitions

Grammar-compressed index structures start with a compressed representation of input data—a string, trajectory, or tree—using a context-free grammar or generalization. For a string S[1..n]S[1..n], the grammar GG produces SS through a sequence of production rules, where the total grammar size G|G| is the sum over the right-hand sides of all rules. Prominent variants include:

  • Straight-Line Program (SLP): Each nonterminal expands to exactly one string, with production rules of the form XiXjXkX_i \to X_j X_k or XiaX_i \to a (aa symbol).
  • Run-Length SLP (RLSLP): Extends SLPs with run-length productions XiXjkX_i \to X_j^k.
  • Tree/SLT grammar: For labeled trees, with nonterminals representing repeated substructures of the tree (used in XML and similar hierarchies).
  • 2D grammar (2D SLP): Binary productions that concatenate matrices horizontally/vertically for 2D data (De et al., 22 Oct 2025).

Auxiliary data structures, such as tries, 2D orthogonal range reporting data structures, permutation arrays, and succinct trees (e.g., DFUDS), are layered on top of the grammar, providing random access, substring extraction, pattern search, and—in generalized contexts—variable time-space tradeoffs.

2. Main Algorithmic Techniques and Index Constructions

a. Grammar Construction and Compression

  • Randomized and deterministic SLP construction: Algorithms such as Re-Pair, Edit-Sensitive Parsing (ESP)/FOLCA, Lyndon SLPs, and signature grammars efficiently compute compact SLPs or their variants for highly repetitive inputs (Christiansen et al., 2017, Takabatake et al., 2015, Tsuruta et al., 2020).
  • Run-length and recompression methods: Block compression, pair compression, and their symbolic application on SLPs support efficient RLSLP construction in compressed time and space (Adudodla et al., 13 Jun 2025).
  • 2D SLG construction: For two-dimensional data (images/maps), productions forming matrices through horizontal and vertical concatenation encode spatial repetition (De et al., 22 Oct 2025).

b. Index Layer: Search, Extraction, and Query Support

  • Index over SLPs: Navigation structures such as z-fast tries for substring search, labeled 2D relations for range-based occurrence reporting, compressed tries for leftmost/rightmost expansions, heavy-path decompositions for quick navigation and bottleneck queries, and succinct tree representations for grammar and parse tree traversal (Claude et al., 2020, Claude et al., 2011).
  • Pattern matching: Most grammar-compressed indexes split PP at all possible (or a logarithmic number of) points, using auxiliary data structures to match left and right pattern substrings to grammar-derived phrases or nonterminal expansions, mapping these range queries to 2D range reporting tasks (Christiansen et al., 2017, Claude et al., 2020, Tsuruta et al., 2020).
  • Rank/select/access: Augmenting the grammar with symbol counters and length arrays allows direct computation of ranka(i)\text{rank}_a(i) and selecta(j)\text{select}_a(j) for symbol aa, supported in O(logn)O(\log n) time using O(gσlogn)O(g \sigma \log n) space, nearly optimal for large and repetitive input (Ordóñez et al., 2019).
  • Tree and spatiotemporal queries: For compressing labeled trees (e.g., XML), self-indexes allow efficient execution of XPath, serialization, and node enumeration using automaton-based rule-wise traversal (Maneth et al., 2010). For spatio-temporal trajectories, logs are grammar-compressed with additional MBR metadata to accelerate spatial and range queries (Brisaboa et al., 2019).
  • Consecutive/gapped pattern queries: More complex search models (e.g., finding consecutive pairs with a bounded gap) are supported by layering further compressed tries, orthogonal range emptiness structures, and persistent predecessor data structures, at the cost of higher polynomial space in grammar size (Gawrychowski et al., 2023).

3. Space and Time Complexity Trade-offs

A hallmark of grammar-compressed index structures is near-optimal or optimal trade-offs between index space and supported query complexity:

Index variant Space (words) Locate time (pattern PP) Extraction time Extra structure
Signature grammar (Christiansen et al., 2017) O(zlog(n/z))O(z\log(n/z)) O(m+occ(loglogn+logϵz))O(m + occ(\log\log n+\log^\epsilon z)) O(+logn)O(\ell+\log n) Randomized grammar, z-fast tries, 2D range ds
SLP-based (Gagie et al., 2011, Claude et al., 2020) O(g+)O(g+\dots) O(m2+occloglogn)O(m^2+occ\log\log n) / O((m2+occ)logG)O((m^2+occ)\log G) O(+logn)O(\ell+\log n) Patricia trees, range reporting
Lyndon SLP (Tsuruta et al., 2020) O(g)O(g) O(m+logmlogn+occlogg)O(m+\log m\log n+occ\log g) O(+logn)O(\ell+\log n) Lyndon factorization, z-fast tries
OESP-index (online) (Takabatake et al., 2015) O(nlogn)O(n\log n) bits O(log(n+σ)(m/α+occq(logN+logm)))O(\log(n+\sigma)(m/\alpha + occ_q(\log N+\log m))) O(log(n+σ)(m+logN))O(\log(n+\sigma)(m+\log N)) Hybrid parse+wavelet/dynamic structures
Rank/select (Ordóñez et al., 2019) O(gσlogn)O(g \sigma \log n) bits O(logn)O(\log n) O(logn)O(\log n) Top-level sampling, per-rule counters
XPath/tree (Maneth et al., 2010) O(g)O(g) bits O(mgr)O(mg r) (automaton states mm, max rank rr) O(gr+k)O(gr + k) Tree automaton, skipping, pre/post order counters
Spatio-temporal (Brisaboa et al., 2019) O(G+o())O(\Vert G\Vert + o()) O((tetb)+logks+d+logT)O((t_e-t_b) + \log_k s + d + \log T) O(logks+logn+d+)O(\log_k s + \log n + d + \ldots) k2k^2-trees, per-rule MBRs

(zz: LZ77 parse size, gg: grammar size, occocc: number of occurrences, mm: pattern length, GG: grammar size by total rule length, ϵ>0\epsilon>0: small constant.)

All indexes cited maintain O(g)O(g) or near-linear space in grammar size and attain O(m+occ)O(m+occ) or O(mlogn+occlogϵn)O(m \log n + occ \log^\epsilon n) query for exact match at least in small alphabet or moderate gg, with trade-offs for richer queries, large alphabets, or more complex query semantics (Christiansen et al., 2017, Claude et al., 2020, Ordóñez et al., 2019, Gawrychowski et al., 2023).

4. Applications and Generalizations

Grammar-compressed index structures have been extended to domains and problems beyond basic substring search:

  • Highly repetitive document collections: Universal indexes for grammars, LZ77, or run-based compressors achieve space up to 2–3% of the raw text or less, supporting pattern match and inverted list queries in near-optimal time—orders of magnitude smaller than classical inverted indexes (Claude et al., 2016, Navarro et al., 2018).
  • Spatio-temporal databases: Compressing logs of relative or absolute positions with grammars (GraCT) enables trajectory and range queries, spatial joins, and nearest-neighbor search, all on multi-gigabyte datasets in core memory (Brisaboa et al., 2019).
  • XML and tree data: Repeated XML subtrees are compressed as shared nonterminals, providing rapid XPath, serialization, and materialization via rule-wise automata, with theoretical and empirical performance gains (Maneth et al., 2010).
  • 2D data (images, maps): 2D SLPs can compress images, matrices, and more, offering optimal random access and supporting conditional lower bounds for more complex pattern and LCE queries (De et al., 22 Oct 2025).

5. Algorithmic Paradigms: Range Reporting, Automata, Pattern Splitting

A common strategy in grammar-compressed indexing is to map the pattern matching or higher-order query to geometric primitives:

  • 2D Range reporting: Many indexes reduce the search for occurrences of a pattern PP to range queries over 2D grids, where one axis corresponds to the left substring of PP and another to the right, represented as lex/rank indices in tries or grammar-derived arrays (Christiansen et al., 2017, Claude et al., 2020, Tsuruta et al., 2020).
  • Automaton simulation: For tree-structured data (e.g., XML), a deterministic automaton operates on rules in the grammar, allowing bulk computation or selection over vast subtrees without full tree expansion (Maneth et al., 2010).
  • Core/anchor-based search: Many schemes select a "core" substring or nonterminal associated with occurrences of PP, searching for the core within grammar rules and extending matches to full pattern occurrences, reducing verification cost (Takabatake et al., 2015, Akagi et al., 2021, Tsuruta et al., 2020).

6. Theoretical Limits, Extensions, and Open Problems

While extraction, random access, and exact match are supported with efficient cursors, several fundamental limitations and research challenges remain:

  • Optimal pattern matching complexity: Achieving true O(m+occ)O(m+occ) query with O(g)O(g) space for arbitrary grammars and alphabets is open; best constructions are still O(mlogn+occlogϵn)O(m\log n+occ\log^\epsilon n) in general (Christiansen et al., 2017, Claude et al., 2020).
  • Rank/select on compressed sequences: For grammar-compressed sequences and large alphabets, rank/select in O(logn)O(\log n) time is essentially optimal, as no O(g polylog n)O(g\ \text{polylog}\ n) space, O(polylog n)O(\text{polylog}\ n) time solution is known, and lower bounds are tight up to log factors (Ordóñez et al., 2019, De et al., 22 Oct 2025).
  • 2D queries and pattern matching: Unlike 1D SLPs, 2D SLPs admit O(logn/loglogn)O(\log n/\log\log n) random access, but conditional lower bounds (Orthogonal Vectors Conjecture) preclude O(g2ϵPO(1))O(g^{2-\epsilon}\cdot |P|^{O(1)}) pattern search, and efficient support for basic 2D queries (sum, LCE, all-zero) would also imply breakthroughs for long-standing 1D problems (De et al., 22 Oct 2025).
  • Online indexing: Fully online index construction with working space proportional to final grammar size is addressed by OESP-index, although with size and latency overhead (Takabatake et al., 2015).

7. Practical Impacts and Empirical Results

Experiments confirm that grammar-compressed indexes often reduce storage by one to two orders of magnitude for highly repetitive data (e.g., multi-version document collections, pangenomics, ship or aircraft trajectories), at the cost of moderate slowdowns compared to non-compressed indexes. Nonetheless, they achieve space-time trade-offs unachievable by statistical or classical dictionary-compression approaches—supporting new query types and making large, otherwise intractable datasets feasible for in-core analytics (Gagie et al., 2011, Brisaboa et al., 2019, Maneth et al., 2010, Takabatake et al., 2015).

In summary, grammar-compressed index structures constitute a foundational tool in text, sequence, XML, and multi-dimensional data indexing. They represent a convergence of algorithmic compression, succinct indexing, and data structure design, with ongoing advancements in efficiency, generality, and applicability (Christiansen et al., 2017, Ordóñez et al., 2019, Claude et al., 2020, De et al., 22 Oct 2025).

Whiteboard

Topic to Video (Beta)

Follow Topic

Get notified by email when new papers are published related to Grammar-compressed Index Structures.