English

Small Space Encoding and Recognition of $k$-Palindromic Prefixes

Data Structures and Algorithms 2025-04-18 v4

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 kk 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 kk-palindromic strings, which can be represented as the concatenation of exactly kk palindromes. We show the following results: 1. First, we show a structural characterization of the set of all kk-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 kk-palindromic prefixes in this way requires O(6k2logkn)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 kk. 2. Secondly, we derive a read-only algorithm that, given a string TT of length nn and an integer kk, computes a compact representation of ii-palindromic prefixes of TT, for all 1ik1 \le i \le k. The algorithm uses O(n6k2logkn)O(n \cdot 6^{k^2} \cdot \log^k n) time and O(6k2logkn)O(6^{k^2} \cdot \log^k n) space. 3. Finally, we also give a read-only algorithm for computing the palindromic length of TT, which is the smallest \ell such that TT is \ell-palindromic. Here, we achieve O(n62log/2n)O(n \cdot 6^{\ell^2} \cdot \log^{\lceil{\ell/2 \rceil}} n) time and O(62log/2n)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)o(n) additional working space on top of the input.

Keywords

Cite

@article{arxiv.2410.03309,
  title  = {Small Space Encoding and Recognition of $k$-Palindromic Prefixes},
  author = {Gabriel Bathie and Jonas Ellert and Tatiana Starikovskaya},
  journal= {arXiv preprint arXiv:2410.03309},
  year   = {2025}
}
R2 v1 2026-06-28T19:08:23.120Z