Small Space Encoding and Recognition of $k$-Palindromic Prefixes
Gabriel Bathie, Jonas Ellert, Tatiana Starikovskaya
TL;DR
This work addresses the space efficiency of recognizing $k$-palindromic prefixes (strings that are concatenations of exactly $k$ palindromes) and of computing the palindromic length of a string. It introduces affine prefix sets to compactly encode all $k$-palindromic prefixes, proving a near-optimal space bound $O(6^{k^2}\cdot\log^k n)$ for small $k$, and provides a matching lower bound up to polylog factors. The paper then presents read-only algorithms that, in time $O(n\cdot 6^{k^2}\cdot\log^k n)$ and space $O(6^{k^2}\cdot\log^k n)$, compute the $i$-palindromic prefixes for all $i\le k$ and, separately, the palindromic length in time $O(n\cdot 6^{\ell^2}\cdot\log^{\lceil \ell/2\rceil} n)$ and space $O(6^{\ell^2}\cdot\log^{\lceil \ell/2\rceil} n)$. The approach hinges on decomposing the prefix structure into a small union of affine prefix sets and carefully managing how palindromes extend these sets, including long and short palindromes, via a suite of structural and algorithmic refinements. Overall, the results advance the understanding of small-space processing for complex CFL-like languages and offer practical, space-efficient tools for palindromic-prefix analysis and palindromic-length computation, with nuanced trade-offs between length, alphabet structure, and space usage.
Abstract
Palindromes are non-empty strings that read the same forward and backward. The problem of recognizing strings that can be represented as the concatenation of even-length palindromes, the concatenation of palindromes of length at least two, and the concatenation of exactly $k$ palindromes was introduced in the seminal paper of Knuth, Morris, and Pratt [SIAM J. Comput., 1977]. In this work, we study the problem of recognizing so-called $k$-palindromic strings, which can be represented as the concatenation of exactly $k$ palindromes. We show the following results: 1. First, we show a structural characterization of the set of all $k$-palindromic prefixes of a string by representing it as a union of a small number of highly structured string sets, called affine prefix sets. Representing the lengths of the $k$-palindromic prefixes in this way requires $O(6^{k^2} \cdot \log^k n)$ space. By constructing a lower bound, we show that the space complexity is optimal up to polylogarithmic factors for reasonably small values of $k$. 2. Secondly, we derive a read-only algorithm that, given a string $T$ of length $n$ and an integer $k$, computes a compact representation of $i$-palindromic prefixes of $T$, for all $1 \le i \le k$. The algorithm uses $O(n \cdot 6^{k^2} \cdot \log^k n)$ time and $O(6^{k^2} \cdot \log^k n)$ space. 3. Finally, we also give a read-only algorithm for computing the palindromic length of $T$, which is the smallest $\ell$ such that $T$ is $\ell$-palindromic. Here, we achieve $O(n \cdot 6^{\ell^2} \cdot \log^{\lceil{\ell/2 \rceil}} n)$ time and $O(6^{\ell^2} \cdot \log^{\lceil{\ell/2\rceil}} n)$ space. For some values of $\ell$, this is the first algorithm for palindromic length that uses $o(n)$ additional working space on top of the input.
