English

Rank, select and access in grammar-compressed strings

Data Structures and Algorithms 2014-08-15 v2

Abstract

Given a string SS of length NN on a fixed alphabet of σ\sigma symbols, a grammar compressor produces a context-free grammar GG of size nn that generates SS and only SS. In this paper we describe data structures to support the following operations on a grammar-compressed string: \mboxrankc(S,i)\mbox{rank}_c(S,i) (return the number of occurrences of symbol cc before position ii in SS); \mboxselectc(S,i)\mbox{select}_c(S,i) (return the position of the iith occurrence of cc in SS); and \mboxaccess(S,i,j)\mbox{access}(S,i,j) (return substring S[i,j]S[i,j]). For rank and select we describe data structures of size O(nσlogN)O(n\sigma\log N) bits that support the two operations in O(logN)O(\log N) time. We propose another structure that uses O(nσlog(N/n)(logN)1+ϵ)O(n\sigma\log (N/n)(\log N)^{1+\epsilon}) bits and that supports the two queries in O(logN/loglogN)O(\log N/\log\log N), where ϵ>0\epsilon>0 is an arbitrary constant. To our knowledge, we are the first to study the asymptotic complexity of rank and select in the grammar-compressed setting, and we provide a hardness result showing that significantly improving the bounds we achieve would imply a major breakthrough on a hard graph-theoretical problem. Our main result for access is a method that requires O(nlogN)O(n\log N) bits of space and O(logN+m/logσN)O(\log N+m/\log_\sigma N) time to extract m=ji+1m=j-i+1 consecutive symbols from SS. Alternatively, we can achieve O(logN/loglogN+m/logσN)O(\log N/\log\log N+m/\log_\sigma N) query time using O(nlog(N/n)(logN)1+ϵ)O(n\log (N/n)(\log N)^{1+\epsilon}) bits of space. This matches a lower bound stated by Verbin and Yu for strings where NN is polynomially related to nn.

Keywords

Cite

@article{arxiv.1408.3093,
  title  = {Rank, select and access in grammar-compressed strings},
  author = {Djamal Belazzougui and Simon J. Puglisi and Yasuo Tabei},
  journal= {arXiv preprint arXiv:1408.3093},
  year   = {2014}
}

Comments

16 pages

R2 v1 2026-06-22T05:28:09.186Z