---
title: 'Manacher Arrays: Palindrome Detection & Reconstruction'
url: https://www.emergentmind.com/topics/manacher-arrays
type: topic
---

# Manacher Arrays: Palindrome Detection & Reconstruction

Searching arXiv for recent papers on Manacher arrays, maximal palindromes, and related compression/reconstruction results.
Manacher arrays are integer arrays that encode the maximal palindromic radius at every admissible center of a string. For a string \(S\) of length \(n\), the classical formulation stores radii for the \(2n-1\) half-integer centers, thereby reconstructing the set of all maximal palindromic substrings of \(S\) in overall \(O(n)\) time via Manacher’s algorithm [2507.13671]. Closely related formulations separate odd and even centers into two arrays \(d_1[0..n-1]\) and \(d_2[0..n-1]\), where \(d_1[i]\) is the radius of the longest odd-length palindrome centered at \(i\) and \(d_2[i]\) is the radius of the longest even-length palindrome centered between \(i-1\) and \(i\) [2508.14384]. Recent work has shifted attention from computation alone to combinatorics, reconstruction, alphabet minimization, and succinct or compressed representations of these arrays [2507.13671], [2508.14384], [2410.09984].

## 1. Formal definitions and equivalent encodings

Let \(S=S[1\ldots n]\) be a string over an alphabet \(\Sigma\). One formulation defines a Manacher array \(A[1\ldots 2n-1]\) by assigning to each odd index \(i=2k-1\) the value
\[
A[i] = \max \{ r \ge 0 \mid S[k-r\ldots k+r] \text{ is a palindrome} \},
\]
and to each even index \(i=2k\) the value
\[
A[i] = \max \{ r \ge 0 \mid S[k-r+1\ldots k+r] \text{ is a palindrome} \}.
\]
Thus \(A\) records the maximal palindromic radius around each of the \(2n-1\) half-integer centers, and equivalently determines the set of all maximal palindromic substrings of \(S\) [2507.13671].

An alternative but standard representation uses two arrays. For \(S[0..n-1]\), \(d_1[0..n-1]\) stores odd-center radii and \(d_2[0..n-1]\) stores even-center radii:
\[
d_1[i] = \max\{r \ge 0 : S[i-r..i+r] \text{ is a palindrome}\},
\]
\[
d_2[i] = \max\{r \ge 0 : S[i-r..i+r-1] \text{ is a palindrome}\}.
\]
The maximal odd palindrome at \(i\) has length \(2\cdot d_1[i]+1\), while the maximal even palindrome with center at \(i\) has length \(2\cdot d_2[i]\) [2508.14384].

A third common formulation embeds the string into a virtual augmented string \(T\) of length \(2N+1\), where original symbols occupy odd positions and a sentinel occupies even positions. The radius array \(p[0..2N]\) then satisfies
\[
p[i] = \text{the largest radius } r \ge 0 \text{ such that } T[i-r..i+r] \text{ is a palindrome}.
\]
This representation unifies odd- and even-length palindromes into a single array over virtual centers [2003.08211].

These definitions are equivalent at the level of maximal palindromic structure. In many applications one folds odd and even palindromes into a single array of maximal palindrome lengths by doubling characters, although some treatments retain separate arrays for clarity [2508.14384].

## 2. Linear-time computation and implementation variants

Manacher’s classical algorithm computes palindrome radii for every center in overall \(O(n)\) time [2507.13671]. In the two-array formulation, a standard in-place scan computes \(d_1\) in \(O(n)\), and an almost identical loop computes \(d_2\) in \(O(n)\) as well; the overall time remains \(O(n)\) [2508.14384]. On an unordered alphabet, the time is \(O(n)\) comparisons, assuming each character fits in a machine word, while the two arrays \(d_1,d_2\) take \(O(n)\) words, that is \(O(n \log n)\) bits [2508.14384].

The augmented-string formulation exploits the mirror relation around the current center \(c\). If \(R=c+p[c]\) is the rightmost boundary reached so far, then for a new center \(i\),
\[
\mathrm{mirror}(i)=2c-i,
\]
and
\[
p[i]=
\begin{cases}
\min\bigl(p[\mathrm{mirror}(i)],\,R-i\bigr), & \text{if } i<R,\\
0, & \text{otherwise.}
\end{cases}
\]
The algorithm then expands around \(i\) while the matched characters agree, and if \(i+p[i]\) exceeds the previous right boundary, it updates \(c\) and \(R\) [2003.08211]. The resulting runtime is \(\Theta(N)\), where \(N\) is the original string length [2003.08211].

A notable implementation refinement avoids explicitly building the augmented string. Instead, the virtual character access
\[
T(i)=
\begin{cases}
S[(i-1)/2], & i \equiv 1 \pmod 2,\\
\#, & i \equiv 0 \pmod 2
\end{cases}
\]
is computed on the fly. This index-mapping implementation keeps only the radius array \(p\), thereby eliminating storage for the augmented string \(T\); the extra memory becomes solely \(\Theta(2N)\) for \(p\), rather than storing both \(T\) and \(p\) [2003.08211]. The reported significance is practical rather than asymptotic: the preprocessing is “neither economic nor necessary,” and index mapping avoids the need to choose a dummy character absent from the input alphabet [2003.08211].

## 3. Combinatorial structure and enumeration

Recent work has treated Manacher arrays as combinatorial objects in their own right. Let \(\rho_n\) denote the number of distinct Manacher arrays of length \(2n-1\) arising from strings of length \(n\), and let \(r_{n+1}\) denote the number of non-isomorphic rooted tandem-duplication trees with \(n+1\) leaves. A principal result establishes
\[
\rho_n \le r_{n+1},
\]
showing that there are strictly more rooted tandem-duplication trees than Manacher arrays [2507.13671].

The proof proceeds through a family of “counter arrays” \(a_1,\ldots,a_n\) satisfying
\[
1 \le a_i \le i,\qquad a_{i+1} \ge a_i-1.
\]
The paper states a chain of bijections
\[
\{\text{Manacher arrays of length }2n-1\}\hookrightarrow \{\text{counter arrays of length }n\}=\{\text{rooted duplication trees on }n+1\text{ leaves}\},
\]
together with an encoding of each duplication event \(B_i=(b_i,\dots,b_i+\ell_i-1)\) as a strictly decreasing block \((b_i+\ell_i-1,\dots,b_i)\) [2507.13671].

This combinatorial viewpoint reframes the Manacher array as more than a byproduct of palindrome detection. It becomes an object subject to enumeration, structural constraints, and nontrivial comparison with independently studied tree families. A plausible implication is that the radius sequence captures a highly structured subset of all locally consistent integer arrays, which helps explain why it supports strong reconstruction theorems and succinct encodings.

A related combinatorial observation appears in compression work: for a Manacher array \(r[1..N]\) of a string of length \(n\), one has \(r[i]\ge 0\) for all \(i\), at most one nonzero “center” appears per index, and the total sum of all radii satisfies
\[
\sum_i r[i]\le n.
\]
This bound underlies a linear-bit differential encoding of the nontrivial centers [2410.09984].

## 4. Reconstruction, graph-theoretic characterization, and alphabet minimization

A major development is the reconstruction of strings from Manacher arrays through a graph-theoretic framework. Rather than work directly with radii, one may pass to the set \(F\) of maximal palindromic intervals, called the palindromic fingerprint. From \(F\), one constructs an equality graph \(G_=\) on vertices \(\{1,\ldots,n\}\), where \((i,j)\in E\) if positions \(i\) and \(j\) must carry the same symbol in any reconstruction, and a restriction graph \(G\) whose vertices are the connected components of \(G_=\), with an edge between two components whenever positions in one must differ from positions in the other [2507.13671].

The central theorem states that for a valid Manacher array \(A\), proper vertex-colorings of \(G\) are in bijection with strings \(S\) of length \(n\) whose Manacher array is \(A\). Each color class corresponds to a symbol used in the reconstruction. Consequently, the minimal alphabet size required to realize \(A\) is exactly the chromatic number \(\chi(G)\) [2507.13671].

This characterization yields an exact decision and construction procedure for prescribed alphabet size. For a target \(k\), one builds \(G\) from the fingerprint \(F\) in polynomial time, checks whether
\[
\chi(G)\le k\le |V(G)|,
\]
and if the condition holds, starts from a minimal coloring of \(G\) and greedily splits color classes until \(k\) colors are obtained, then translates the \(k\)-coloring back to a string. The procedure resolves an open problem in the affirmative with an \(O(n^2)\)-time algorithm [2507.13671].

The same work analyzes a left-to-right reconstruction algorithm due to I et al. (SPIRE 2010). The algorithm builds a lexicographically minimal string achieving the given Manacher array and is shown to have three properties: global minimality of the alphabet, use of at most \(\log_2(n-1)+2\) distinct symbols, and adaptability to produce reconstructions over arbitrary alphabets when possible [2507.13671]. More precisely, the bound is stated as
\[
1+\lfloor \log_2(n-1)\rfloor +1 = \log_2(n-1)+2,
\]
and it is tight for infinitely many \(n\) [2507.13671].

The extremal analysis is tied to Palindromic Zimin words. The derivation shows that each newly introduced symbol must be preceded by a palindrome structure matching a Palindromic Zimin word of degree \(d\), which has length at least \(2^d-1\); hence if \(k\) symbols have appeared by position \(m\), then \(m\ge 2^{k-2}-1\), giving \(k\le \log_2(m-1)+2 \le \log_2(n-1)+2\) [2507.13671]. The paper also defines palindromic dependency: index \(j\) is palindromically dependent on \(m\) if there is a maximal palindrome \(p\) with center \(<m\le \mathrm{end}(p)\), forcing \(S[j]\) to equal a symmetric position within \(p\) [2507.13671].

An important contrast is that general “dependency” reconstruction is NP-hard, whereas the palindromic special case is easy because of the very structured restriction graph [2507.13671]. This suggests that the tractability of Manacher-array reconstruction is due not merely to local equalities but to the highly constrained geometry imposed by maximal palindromes.

## 5. Succinct and compressed representations

Classically, storing all maximal palindrome radii requires \(O(n)\) machine words, or \(O(n\log n)\) bits, because the arrays \(d_1\) and \(d_2\) each have length \(n\) [2508.14384]. Subsequent work has sought linear-bit encodings with efficient query support.

One line of results gives an \(O(n)\)-bit representation for all maximal palindromes with \(O(1)\)-time retrieval of the maximal even-palindrome length \(MEPal[c]=2\cdot d_2[c]\) [2508.14384]. The representation first encodes the sequence of centers of longest even-palindromic suffixes in unary differences, obtaining a bit string of total length \(2n-1\). Since this encoding alone does not support \(O(1)\) retrieval, the structure partitions centers into “long” and “short” cases using a parameter \(\tau=\Theta(\log n)\) and a bit-vector \(LS\), where \(LS[c]=1\) iff \(MEPal[c]>2\tau\) [2508.14384].

For long palindromes, centers are grouped into blocks of length \(\tau\). If a block contains at most two long palindromes, the pairs are stored explicitly in \(O(\log n)\) bits each. Otherwise, by a periodicity lemma, the centers form an arithmetic progression and the lengths decompose into at most two arithmetic progressions plus one exception; the representation stores the progression parameters and linear formulas in \(O(\log n)\) bits total per block [2508.14384]. For short palindromes, each lies within a window of length \(4\tau\); distinct window strings are locally encoded by the unary-difference method, and a global lookup table answers queries in \(O(1)\) time [2508.14384]. Combined, storing \(LS\), the long-palindrome structure, and the short-palindrome structure yields total space \(O(n)\) bits and query time \(O(1)\) [2508.14384].

A different compression approach encodes the Manacher array \(r[1..2n-1]\) through differential offsets between centers of nontrivial maximal palindromes and gamma-encodes these differences. If \(B[j]=c_j-c_{j-1}\), where \(c_j\) is the center of the \(j\)th nontrivial maximal palindrome in a left-to-right sweep, then \(\sum_j B[j]\le n\), and the total gamma-encoded size is \(O(n)\) bits [2410.09984]. From \(B\), the entire radius array can be reconstructed in \(O(n)\) time by replaying the mirroring steps of Manacher’s algorithm [2410.09984].

The same work states a lower bound: even if \(|\Sigma|\le 3\), the Manacher array of \(S\) already suffices to recover \(S\) up to a 6-element permutation, so one cannot beat \(\Omega(n)\) bits in the worst case [2410.09984]. It further gives a zero-order entropy bound
\[
H_0(r)\le \log(\sigma+1),
\]
and therefore
\[
|C(r)| \le nH_0(r)+O(n)=O(n\log \sigma)
\]
bits when the alphabet size is \(\sigma\) [2410.09984]. Together these imply
\[
\Omega(n)\le |C(r)|\le O(n\log \sigma).
\]
When \(\sigma=O(1)\), this becomes \(\Theta(n)\) bits, while for \(\sigma=O(n)\) the upper bound is \(O(n\log n)\) bits [2410.09984].

Beyond sequential decoding, the same paper gives a random-access index using
\[
O\!\Bigl(\frac{n}{\log n}\Bigr)\ \text{words}
\]
of space, that is \(O(n)\) bits, and supporting \(\mathsf{Access}(i)=r[i]\) in
\[
O(\log^* n)
\]
time after \(O(n)\)-time preprocessing [2410.09984]. The design partitions centers into non-periodic and periodic cases; non-periodic radii are stored in a CF-Array, while periodic regions are represented by period descriptors and auxiliary rank/select bitvectors [2410.09984].

## 6. Applications, related structures, and open directions

Because Manacher arrays encode all maximal palindromic structure, they serve as a substrate for other indexing problems. Using the \(O(n)\)-bit maximal-palindrome representation, one can preprocess a string into an \(O(n)\)-bit data structure that computes the longest palindrome appearing in any given factor \(S[i..j]\) in \(O(\log n)\) time [2508.14384]. The method decomposes the answer into longest palindromic prefix, longest palindromic suffix, and best interior maximal palindrome; prefix and suffix lengths are found by binary search over centers using RMQ on an auxiliary array, and the interior answer uses an RMQ over \(MEPal\) [2508.14384].

Compressed-representation work also connects Manacher arrays with Lempel–Ziv complexity and alphabet size. One result states a one-to-one link between the minimal alphabet size \(\sigma\) needed for any preimage of a given Manacher array and the Lempel–Ziv complexity \(LZ(r)\) of the radius sequence. Specifically, if the lexicographically minimal string realizing \(r\) has alphabet size \(\sigma\), then palindromic Zimin-word structure forces
\[
LZ(r)=\Theta(\sigma)\qquad\text{and}\qquad \sigma=O(\log n)
\]
[2410.09984]. This indicates that small alphabet size, Zimin-type extremal structure, and compressibility of the radius sequence are tightly coupled phenomena.

Several open directions are explicitly identified. One is to obtain a data structure using \(o(n)\) bits while still supporting \(O(1)\)-time access to \(r[i]\); the stated obstacle is a trade-off between long-run periodic cases and the CF-array’s local constraints [2410.09984]. Another is extension to two-dimensional palindromic pictures or higher-order palindromic factorizations [2410.09984].

A recurring misconception is that the Manacher array is only an auxiliary artifact for longest-palindromic-substring computation. The cited work shows a broader picture: it supports exact reconstruction up to graph coloring [2507.13671], admits nontrivial counting bounds via duplication trees [2507.13671], and can be stored in linear bits with constant or near-constant access guarantees [2508.14384], [2410.09984]. This suggests that Manacher arrays occupy a central role in the algorithmics and combinatorics of palindromic structure, rather than merely serving as an implementation detail of a classical linear-time scan.

Source: https://www.emergentmind.com/topics/manacher-arrays