Random Access in Grammar-Compressed Strings: Optimal Trade-Offs in Almost All Parameter Regimes
Abstract
A Random Access query to a string asks for the character at a given position . In bits of space, this fundamental task admits constant-time queries. While this is optimal in the worst case, much research has focused on compressible strings, hoping for smaller data structures that still admit efficient queries. We investigate the grammar-compressed setting, where is represented by a straight-line grammar. Our main result is a general trade-off that optimizes Random Access time as a function of string length , grammar size (the total length of productions) , alphabet size , data structure size , and word size of the word RAM model. For any with , we show an -size data structure with query time . Remarkably, we also prove a matching unconditional lower bound that holds for all parameter regimes except very small grammars and relatively small data structures. Previous work focused on query time as a function of only, achieving time using space [Bille et al.; SIAM J. Comput. 2015] and time using space for any constant [Belazzougui et al.; ESA'15], [Ganardi, Je\.z, Lohrey; J. ACM 2021]. The only tight lower bound [Verbin and Yu; CPM'13] was for , , and . In contrast, our result yields tight bounds in all relevant parameters and almost all regimes. Our data structure admits efficient deterministic construction. It relies on novel grammar transformations that generalize contracting grammars [Ganardi; ESA'21]. Beyond Random Access, its variants support substring extraction, rank, and select.
Cite
@article{arxiv.2602.10864,
title = {Random Access in Grammar-Compressed Strings: Optimal Trade-Offs in Almost All Parameter Regimes},
author = {Anouk Duyster and Tomasz Kociumaka},
journal= {arXiv preprint arXiv:2602.10864},
year = {2026}
}