English

Balancing Two-Dimensional Straight-Line Programs

Data Structures and Algorithms 2025-12-01 v1

Abstract

We consider building, given a straight-line program (SLP) consisting of gg productions deriving a two-dimensional string TT of size N×NN\times N, a structure capable of providing random access to any character of TT. For one-dimensional strings, it is now known how to build a structure of size O(g)\mathcal{O}(g) that provides random access in O(logN)\mathcal{O}(\log N) time. In fact, it is known that this can be obtained by building an equivalent SLP of size O(g)\mathcal{O}(g) and depth O(logN)\mathcal{O}(\log N) [Ganardi, Je\.z, Lohrey, JACM 2021]. We consider the analogous question for two-dimensional strings: can we build an equivalent SLP of roughly the same size and small depth? We show that the answer is negative: there exists an infinite family of two-dimensional strings of size N×NN\times N described by a 2D SLP of size gg such that any 2D SLP describing the same string of depth O(logN)\mathcal{O}(\log N) must be of size Ω(gN/log3N)\Omega(g\cdot N/\log^{3}N). We complement this with an upper bound showing how to construct such a 2D SLP of size O(gN)\mathcal{O}(g\cdot N). Next, we observe that one can naturally define a generalization of 2D SLP, which we call 2D SLP with holes. We show that a known general balancing theorem by [Ganardi, Je\.z, Lohrey, JACM 2021] immediately implies that, given a 2D SLP of size gg deriving a string of size N×NN\times N, we can construct a 2D SLP with holes of depth O(logN)\mathcal{O}(\log N) and size O(g)\mathcal{O}(g). This allows us to conclude that there is a structure of size O(g)\mathcal{O}(g) providing random access in O(logN)\mathcal{O}(\log N) time for such a 2D SLP. Further, this can be extended (analogously as for a 1D SLP) to obtain a structure of size O(glogϵN)\mathcal{O}(g \log^{\epsilon}N) providing random access in O(logN/loglogN)\mathcal{O}(\log N/\log \log N) time, for any ϵ>0\epsilon >0.

Cite

@article{arxiv.2511.22212,
  title  = {Balancing Two-Dimensional Straight-Line Programs},
  author = {Itai Boneh and Estéban Gabory and Paweł Gawrychowski and Adam Górkiewicz},
  journal= {arXiv preprint arXiv:2511.22212},
  year   = {2025}
}