,
Estéban Gabory
,
Paweł Gawrychowski
,
Adam Górkiewicz
Creative Commons Attribution 4.0 International license
We consider building, given a straight-line program (SLP) consisting of g productions deriving a two-dimensional string T of size N× N, a structure capable of providing random access to any character of T. For one-dimensional strings, it is now known how to build a structure of size 𝒪(g) that provides random access in 𝒪(log N) time. In fact, it is known that this can be obtained by building an equivalent SLP of size 𝒪(g) and depth 𝒪(log N) [Ganardi, Jeż, 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× N described by a 2D SLP of size g such that any 2D SLP of depth 𝒪(log N) describing the same string must be of size Ω(g⋅ N/log³N). We complement this with an upper bound showing how to construct such a 2D SLP of size 𝒪(g⋅ 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ż, Lohrey, JACM 2021] immediately implies that, given a 2D SLP of size g deriving a string of size N× N, we can construct a 2D SLP with holes of depth 𝒪(log N) and size 𝒪(g). This allows us to conclude that there is a structure of size 𝒪(g) providing random access in 𝒪(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 𝒪(g log^ε N) providing random access in 𝒪(log N/log log N) time, for any ε > 0. The same (optimal) random access time was very recently achieved by [De and Kempa, SODA 2026], but with a significantly larger structure of size 𝒪(g log^{2+ε} N).
@InProceedings{boneh_et_al:LIPIcs.CPM.2026.32,
author = {Boneh, Itai and Gabory, Est\'{e}ban and Gawrychowski, Pawe{\l} and G\'{o}rkiewicz, Adam},
title = {{Balancing Two-Dimensional Straight-Line Programs}},
booktitle = {37th Annual Symposium on Combinatorial Pattern Matching (CPM 2026)},
pages = {32:1--32:20},
series = {Leibniz International Proceedings in Informatics (LIPIcs)},
ISBN = {978-3-95977-420-8},
ISSN = {1868-8969},
year = {2026},
volume = {369},
editor = {Bille, Philip and Prezza, Nicola},
publisher = {Schloss Dagstuhl -- Leibniz-Zentrum f{\"u}r Informatik},
address = {Dagstuhl, Germany},
URL = {https://drops.dagstuhl.de/entities/document/10.4230/LIPIcs.CPM.2026.32},
URN = {urn:nbn:de:0030-drops-259582},
doi = {10.4230/LIPIcs.CPM.2026.32},
annote = {Keywords: Two-dimensional string, straight-line program, random access}
}