Abstract 1 Introduction 2 Preliminaries 3 𝑶(𝒏)-bit representation of maximal palindromes 4 Application to internal longest palindrome queries 5 Conclusions References Appendix A Proof of Lemma 6

Compact Representation of Maximal Palindromes

Takuya Mieno ORCID Department of Computer and Network Engineering, University of Electro-Communications, Chofu, Japan
Abstract

Palindromes are strings that read the same forward and backward. The computation of palindromic structures within strings is a fundamental problem in string algorithms, being motivated by potential applications in formal language theory and bioinformatics. Although the number of palindromic factors in a string of length n can be quadratic, they can be implicitly represented in O(nlogn) bits of space by storing the lengths of all maximal palindromes in an integer array, which can be computed in O(n) time [Manacher, 1975]. In this paper, we propose a novel O(n)-bit representation of all maximal palindromes in a string, which enables O(1)-time retrieval of the length of the maximal palindrome centered at any given position. The data structure can be constructed in O(n) time from the input string of length n. Since Manacher’s algorithm and the notion of maximal palindromes are widely utilized for solving numerous problems involving palindromic structures, our compact representation will accelerate the development of more space-efficient solutions to such problems. Indeed, as the first application of our compact representation of maximal palindromes, we present a data structure of size O(n) bits that can compute the longest palindrome appearing in any given factor of a string of length n in O(logn) time.

Keywords and phrases:
palindromes, succinct data structures, internal queries
Copyright and License:
[Uncaptioned image] © Takuya Mieno; licensed under Creative Commons License CC-BY 4.0
2012 ACM Subject Classification:
Mathematics of computing Combinatorial algorithms
Funding:
JSPS KAKENHI Grant Number JP24K20734
Editors:
Philip Bille and Nicola Prezza

1 Introduction

A palindrome is a string that reads the same forward and backward. For centuries, palindromes have been enjoyed as elements of wordplay and puzzles. In recent years, they have also gained attention in Theoretical Computer Science due to their combinatorial properties and relevance in fields such as formal language theory, computability theory, and bioinformatics (see also [9, 13, 27, 15, 10, 14, 16, 17] and references therein). From an algorithmic perspective, one of the most well-known algorithms for detecting palindromic factors is Manacher’s algorithm [18]. Manacher’s algorithm can efficiently enumerate all maximal palindromes in a given string in linear time, where a maximal palindrome is defined as a palindromic factor that cannot be further extended while preserving its center position. Alternative approaches to enumerate maximal palindromes based on suffix trees [28] are also known and have been applied depending on the context [10, 21]. Manacher’s algorithm is particularly notable for its algorithmic elegance as well as for its applicability to general unordered alphabets. Thanks to these advantages, it plays a central role in many algorithms involving palindromic structures, even today [23, 26, 3, 5]. Furthermore, over the past decade, several developments have been made in designing data structures that compactly represent palindromic information and efficiently support various queries [25, 24, 8, 1, 22, 20, 12].

Although various algorithms and data structures related to palindromes have been developed, it is somewhat surprising that sublinear o(n)-word representations of all maximal palindromes remain largely unexplored so far. To the best of our knowledge, the only prior work on this problem is by Itzhaki in 2025 [12], who proposed an O(n)-bit representation of maximal palindromes in a string of length n, which allows retrieving the length of each maximal palindrome in O(logn) time upon a query111logn denotes the iterated logarithm of n..

In this paper, we propose an O(n)-bit representation of all maximal palindromes in a string that supports constant-time retrieval of the length of each maximal palindrome centered at any given position (Theorem 4). The data structure can be constructed in O(n) time given a string of length n. In addition, as an application of Theorem 4, we present a data structure of size O(n) bits that can answer any internal longest palindrome query [22], which finds the longest palindrome within a query factor, in O(logn) time (Theorem 12).

Related work

Manacher’s algorithm [18] can output an integer array of linear length, occupying O(nlogn) bits of space, that stores the lengths of all maximal palindromes in a string w of length n. If we are interested in the variety of distinct palindromic factors in w, rather than their occurrences, we can store them using the palindromic tree (a.k.a. EERTREE) data structure, which requires O(dlogn) bits of space [25], where d is the number of distinct palindromic factors in w and is known to be at most n+1 [4]. The palindromic tree of w can be extremely small when w has very few distinct palindromic factors; however, it does not support locating occurrences of palindromic factors in w. Charalampopoulos et al. [3] presented an O(n/logσn)-time (namely, sublinear-time) algorithm for computing a longest palindromic factor in w, assuming that the alphabet size σ is small and that w is given in a packed representation occupying O(nlogσ) bits of space. Recently, Mieno and Funakoshi [20] proposed an O(n)-bit data structure that represents all unique palindromic factors in w, where a factor is said to be unique if it occurs exactly once in w.

2 Preliminaries

2.1 Intervals, strings, and palindromes

For non-negative integers i,j with ij, let [i..j]={i,i+1,,j} be the set of consecutive integers from i to j. Further, let [i..j)=[i..j]{j}. Note that [i..i)=. We sometimes refer to a set [i..j] of consecutive integers as an interval.

Let Σ be an alphabet of size σ. An element in Σ is called a character. An element in Σ is called a string. The length of string w is denoted by |w|. The string of length zero is called the empty string. If w=xyz holds for strings w,x,y,zΣ, then x, y, and z are called a prefix, a factor, and a suffix of w, respectively. For a string w and integers i,j[0..|w|), we denote by w[i] the i-th character of w, and by w[i..j] the factor of w that starts at position i and ends at position j. For convenience, let w[i..j] be the empty string if i>j. We denote by wR the reversal of string w, i.e., wR=w[|w|1]w[|w|2]w[0]. A positive integer p is called a period of a string w if w[i]=w[i+p] holds for all i[0..|w|p). We also say that w has a period p if p is a period of w. If string w has a period p with p|w|/2, then w is said to be periodic.

A string w is called a palindrome if w=wR holds. Note that the empty string is a palindrome. A factor of a string is called palindromic if it is a palindrome. An occurrence of a palindromic factor w[i..j] of w is called a maximal palindrome if (1) i=0, (2) j=|w|1, or (3) w[i1]w[j+1]. A palindrome is called an even-palindrome (resp. odd-palindrome) if its length is even (resp. odd). Throughout this paper, we focus only on even-palindromes. As discussed in Section 3 of [2], if we are interested in odd-palindromes, we can convert the input string w into w^=w[0]w[0]w[1]w[1]w[n1]w[n1], which is obtained by doubling each character of w. Then, Observation 1 holds:

Observation 1.

For any i,j with 0ijn1, w[i..j] is a (possibly odd-) palindrome if and only if w^[2i..2j+1] is an even-palindrome.

Namely, detecting palindromes in a string of length n can be reduced to detecting even-palindromes in a string of length 2n. In the rest of this paper, we simply refer to “even-palindromes” as “palindromes” unless otherwise specified.

If w[cr..c+r1] is a palindromic factor of w for some non-negative integers c and r, we say that c is the center of w[cr..c+r1], or w[cr..c+r1] is centered at c. Note that c is not exactly the median of interval [cr..c+r1], but it is the first position of the right half of the interval. For notational simplicity, we sometimes say that a factor is the MPal at c if the factor is the maximal palindrome centered at c.

2.2 Model of computation

In what follows, we arbitrarily fix the input string w of length n. In this paper, when we omit the base of log, it is two. Our computation model is a standard word RAM model of word size Ω(logn). We assume that every character from Σ fits within a single machine word, i.e., given two characters, the equality of them can be determined in constant time.

2.3 Arrays 𝗠𝗘𝗣𝗮𝗹 and 𝗟𝗘𝗣𝗮𝗹

Manacher [18] proposed a linear-time algorithm to compute the longest palindromic factors in a given string, which inherently computes all the maximal palindromes in the string. By running Manacher’s algorithm, we can obtain a representation of the maximal palindromes in w in linear time. In this paper, we define the maximal even-palindrome array 𝖬𝖤𝖯𝖺𝗅w of length n as follows: 𝖬𝖤𝖯𝖺𝗅w[c] stores the length of the MPal at c in w for every c[0..n). Next, we define the longest even-palindrome array 𝖫𝖤𝖯𝖺𝗅w of length n such that 𝖫𝖤𝖯𝖺𝗅w[j] stores the length of the longest even-palindrome that is a suffix of w[0..j] for every j[0..n). We may omit subscripts if they are clear from the context. The following lemma can be shown in a similar way to Lemma 2 of [11].

Lemma 2.

For any strings x and y, 𝖬𝖤𝖯𝖺𝗅x=𝖬𝖤𝖯𝖺𝗅y iff 𝖫𝖤𝖯𝖺𝗅x=𝖫𝖤𝖯𝖺𝗅y.

Using Lemma 2, we can compactly encode array 𝖬𝖤𝖯𝖺𝗅.

Lemma 3.

Array 𝖬𝖤𝖯𝖺𝗅x for a string x can be encoded using 2|x|2 bits.

Proof.

By Lemma 2, it is enough to encode 𝖫𝖤𝖯𝖺𝗅x in 2|x|2 bits instead of encoding 𝖬𝖤𝖯𝖺𝗅x. Consider two positions j1,j2[0..|x|) with j1<j2. Let c1 and c2 be the center positions of the longest even-palindromic suffixes of x[0..j1] and x[0..j2], respectively. If the longest even-palindromic suffix of x[0..j] is the empty string, we define its center as j. For the sake of contradiction, assume c1>c2. On the one hand, x[2c1j11..j1] is the longest even-palindromic suffix of x[0..j1] by definition. On the other hand, x[2c2j11..j1] is also a palindromic suffix of x[0..j1] centered at c2 since there is a longer palindromic factor x[2c2j21..j2] centered at c2. Then, it holds that |x[2c1j11..j1]|=2(j1c1)+2<2(j1c2)+2=|x[2c2j11..j1]|, a contradiction. Thus, the center positions of the longest even-palindromic suffixes of prefixes of x form a non-decreasing sequence in [0..|x|). Such a sequence can be encoded using 2|x|2 bits by representing the differences between adjacent values in unary. Therefore, 𝖫𝖤𝖯𝖺𝗅x can be encoded using 2|x|2 bits, and the same holds for 𝖬𝖤𝖯𝖺𝗅x. We provide examples of the encoding in Fig. 1. Note that the compact encoding in Lemma 3 does not support constant-time access to each element of 𝖬𝖤𝖯𝖺𝗅x.

Figure 1: Encodings of two strings, 𝚊𝚋𝚌𝚌𝚋𝚊𝚋𝚋𝚊𝚊 and 𝚋𝚌𝚊𝚊𝚌𝚋𝚊𝚊𝚋𝚋. Non-empty maximal even-palindromes are indicated as double-headed arrows. For each string, 𝖫𝖤𝖯𝖺𝗅 array, its corresponding centers, the differences between adjacent centers, and the binary encoding are shown. The binary encoding represents the differences in unary.

3 𝑶(𝒏)-bit representation of maximal palindromes

In this section, we show our main theorem:

Theorem 4.

Given a string of length n, we can construct in O(n) time an O(n)-bit data structure that can return the length of the maximal even-palindrome centered at c in O(1) time for a given c[0..n).

The next corollary immediately follows from Theorem 4 and Observation 1:

Corollary 5.

Given a string of length n, we can construct in O(n) time an O(n)-bit data structure that can return the length of the maximal palindrome w[i..j] such that i+j=c in O(1) time for a given c[0..2n1).

Let τ be an integer parameter with 1τn/4. A palindrome is said to be long if its length is greater than 2τ and short otherwise. For the simplicity of the discussions below, we assume that n is a multiple of 2τ. If this is not the case, we modify w to satisfy the condition by appending a special character $Σ at most 2τ1 times. This modification does not affect the asymptotic complexities in Theorem 4. Note that τ is later set to logn/16.

3.1 Sketch of our method

Our compact data structure consists of two main components: one is for long maximal palindromes (Section 3.2), which we denote by 𝒟long, and the other one is for short maximal palindromes (Section 3.3), which we denote by 𝒟short. We also construct a bit vector 𝖫𝖲 of length n that indicates whether the corresponding maximal palindrome is long or short, i.e., 𝖫𝖲[c]=1 iff 𝖬𝖤𝖯𝖺𝗅[c]>2τ. Given an integer c as a query input, we first check the c-th bit of 𝖫𝖲. If 𝖫𝖲[c]=1 then we use 𝒟long, and otherwise we use 𝒟short.

The idea behind the first data structure 𝒟long is the sparsification of array 𝖬𝖤𝖯𝖺𝗅 by using the periodicity of palindromes. Array 𝖬𝖤𝖯𝖺𝗅 is decomposed into O(n/τ) blocks of size τ. Roughly speaking, long palindromes whose centers lie within the same block must be periodic, except for at most one possible exception, and can be represented in O(logn) bits using a constant number of arithmetic progressions. Then, every long maximal palindrome can be restored in constant time, from the arithmetic progressions, upon a query. Since each block has O(logn) bits of information, the total size of 𝒟long is O(nτlogn) bits. Later, we will choose τ so that τΘ(logn).

The second data structure 𝒟short is based on a lookup table. By definition, every short maximal palindrome is a factor of w[(k1)2τ..(k+1)2τ1] of length 4τ for some integer k. We refer to such factors as 4τ-windows. Given a center position c, we detect a 4τ-window that contains the (short) maximal palindrome centered at c. We then obtain 𝖬𝖤𝖯𝖺𝗅[c] by a single access to a precomputed lookup table T. Since the total number of length-4τ strings over Σ is σ4τ, a naïve implementation of table T leads to an Ω(σ4τ)-bit data structure, which may be superlinear unless τ or σ is sufficiently small. However, using a compact representation of 𝖬𝖤𝖯𝖺𝗅 (Lemma 3), the dependency on σ can be eliminated. Finally, the size of table T can be reduced to O(αττ2) bits where α is a constant that is independent of σ and τ. Furthermore, by Lemma 3, each 4τ-window can be encoded using O(τ) bits. By choosing τ=(logαn)/2Θ(logn), the space usage can be O(n) bits in total.

3.2 Data structure for long palindromes

We separate interval [0..n) into O(n/τ) sub-intervals where each sub-interval is of length τ. We refer to such a sub-interval as a block. Let us focus on k-th block, denoted by Bk. Let Lk be the set of long maximal palindromes whose centers lie within the k-th block Bk. If |Lk|2, then we simply store their lengths using O(logn) bits. Otherwise, we use periodicity of palindromes whose centers are close to each other, which is summarized as the following lemma:

Lemma 6.

If |Lk|3, then the sequence of lengths of maximal palindromes in Lk sorted by their center positions can be represented by at most two arithmetic progressions and at most one integer. Also, the center positions from Lk can be represented by a single arithmetic progression.

The essence of this lemma is the same as that of Lemma 12 in [19], which follows from classical results shown by Apostolico, Breslauer, and Galil [2]. A concrete example of Lemma 6 is provided in Fig. 2. For completeness, we give a proof of Lemma 6 in Appendix A.

Figure 2: Illustration of a part of an input string and maximal even-palindromes within it. Consider the block B=[22..32] of size τ=11. Maximal palindromes whose centers lie within B are shown with bold arrows, and their lengths are labeled to the right. The sequence of these lengths is (28,32,42,32,28,24), which can be described using two arithmetic progressions, (28,32) and (32,28,24), along with the single integer 42. Also, the centers of the long palindromes within B are evenly spaced.

By Lemma 6, even if Lk is large, it can be represented in O(logn) bits and each element of Lk can be retrieved by a constant number of arithmetic operations. Finally, let us consider the construction of the data structure. Given a string w of length n, we first compute the array 𝖬𝖤𝖯𝖺𝗅w. For each block, we scan the corresponding sub-array of 𝖬𝖤𝖯𝖺𝗅w and extract the lengths of long maximal palindromes within that sub-array. By Lemma 6, they can be represented by at most three arithmetic progressions. Clearly, such arithmetic progressions can be computed in O(τ) time for each block. Thus, in total, the data structure of Lemma 7 can be constructed in O(n) time.

From the above discussion, we obtain the following:

Lemma 7.

There is a data structure of size O(nτlogn) bits that can return 𝖬𝖤𝖯𝖺𝗅[c] in constant time if 𝖬𝖤𝖯𝖺𝗅[c]>2τ. The data structure can be constructed in O(n) time.

If we choose τΘ(logn) and naïvely store the length of every short maximal palindrome, which can be represented in O(logτ)=O(loglogn) bits, we obtain a sub-linear O(nloglogn/logn)-space representation of 𝖬𝖤𝖯𝖺𝗅:

Corollary 8.

There is a data structure of O(nloglogn) bits that can return 𝖬𝖤𝖯𝖺𝗅[c] in O(1) time for a given c[0..n). The data structure can be constructed in O(n) time.

3.3 Data structure for short palindromes

In this subsection, we show the following lemma to reduce the size of the data structure of Corollary 8 to O(n) bits.

Lemma 9.

Assume that τ=logn/16. There is a data structure of size o(n) bits that can return 𝖬𝖤𝖯𝖺𝗅[c] in constant time if 𝖬𝖤𝖯𝖺𝗅[c]2τ. The data structure can be constructed in O(n) time.

Proof.

For each k[1..n/2τ), let Xk=w[(k1)2τ..(k+1)2τ) be the length-4τ factor of w that starts at position (k1)2τ. We refer to Xk as the k-th 4τ-window. By definition, every short maximal palindrome is a factor of Xk for some k. To avoid case distinction for boundary cases, we define X0:=X1 and Xn/2τ:=Xn/2τ1.

By Lemma 3, array 𝖬𝖤𝖯𝖺𝗅x of a string x can be encoded using 2|x|2 bits. We denote by 𝖾𝗇𝖼(X) the (2|X|2)-bit encoding of 4τ-window X. Let T be a lookup table (empty initially). For every 4τ-window X in w, we add records (𝖾𝗇𝖼(X),p), to the lookup table T if they do not already exist, where p[0..4τ) is a center position of X and is the length of the MPal at p in X. The lookup table requires O(28τ2(4τ)log(4τ))=O(28ττlogτ) bits since there are at most 22|X|2=28τ2 possible encodings 𝖾𝗇𝖼(X) for strings X of length 4τ, and each value requires O(log(4τ))=O(logτ) bits. If we set τ=logn/16, then the size of the table becomes O(2logn2lognloglogn)=O(nlognloglogn)o(n) bits. Also, each 4τ-block can be represented in O(logn) bits, fitting in a constant number of machine words. Given the center position c of a short maximal palindrome as a query, a 4τ-window that contains the MPal at c, say Xk, can be detected in constant time: k=k/2, where k[1..n/τ] is the index of the block Bk to which c belongs. Then, we look up the record from T that corresponds to (𝖾𝗇𝖼(Xk),c𝖻𝖾𝗀(Xk)) where 𝖻𝖾𝗀(Xk) is the beginning position of Xk. Namely, c𝖻𝖾𝗀(Xk) denotes the offset of the center position from the beginning position of Xk. Then, we can obtain 𝖬𝖤𝖯𝖺𝗅[c] in constant time if 𝖬𝖤𝖯𝖺𝗅[c]2τ.

Finally, let us consider the construction of the lookup table. For each 4τ-window X of the input string w, we perform Manacher’s algorithm on it. Then we can obtain 𝖬𝖤𝖯𝖺𝗅X and 𝖫𝖤𝖯𝖺𝗅X, as well as the encoding 𝖾𝗇𝖼(X) of the window in O(|X|)=O(4τ) time (see also the proof of Lemma 3). We then insert the lengths of (short) maximal palindromes from 𝖬𝖤𝖯𝖺𝗅X into the lookup table. Recall that every record of the form (𝖾𝗇𝖼(X),p), fits within O(1) machine words. The total construction time is O(4τ×n/2τ)=O(n).

Theorem 4 immediately follows from Lemmas 7 and 9. Finally, we give a pseudocode of the proposed query algorithm as Algorithm 1.

Algorithm 1 Query algorithm for given center c.

4 Application to internal longest palindrome queries

In this section, we propose an O(n)-bit data structure for solving the following problem.

Definition 10 (Internal longest palindrome query).

For a string w of length n, the internal longest palindrome query is, given an interval [i..j][0..n) as a query, to return the length of a longest palindromic factor appearing in w[i..j].

This problem can be solved in O(1) time per query, using O(nlogn) bits of space [22]. Below, we show that we can build an O(n)-bit data structure that can answer each query in O(logn) time. It is known [22] that the length of a longest palindromic factor of w[i..j] is the maximum among the following:

  1. 1.

    The length p of the longest palindromic prefix of w[i..j],

  2. 2.

    the length s of the longest palindromic suffix of w[i..j], and

  3. 3.

    the length m of a longest maximal palindrome of w that is contained within w[i+1..j1].

Let cp (resp. cs) be the center position of the longest palindromic prefix (resp. suffix) of w[i..j]. Namely, cp=i+p/2 and cs=js/2+1 hold. Once we obtain cp and cs, the length m can be computed by using range maximum queries (RMQ) on array 𝖬𝖤𝖯𝖺𝗅. Precisely, m=𝖬𝖤𝖯𝖺𝗅[𝖱𝖬𝖰𝖬𝖤𝖯𝖺𝗅(cp+1,cs1)] holds, where 𝖱𝖬𝖰A(s,t) is an element of argmax{A[k]k[s..t]} for array A and its indices s,t (the correctness is shown in [22]). It is known that there is an O(n)-bit data structure that can answer an RMQ in constant time [7]. Thus, the remaining task is to show how to compute s efficiently using an O(n)-bit data structure, since the computation of p can be treated symmetrically. The following lemma addresses this:

Lemma 11.

There is a data structure of size O(n) bits that can compute the length s of the longest palindromic suffix of w[i..j] in O(logn) time for any given range [i..j].

Proof.

We first present an O(nlogn)-bit data structure, and then we make it compact. Let 𝖤 be the array of length n such that 𝖤[c]=c if the MPal at c is empty; and otherwise, it stores the ending position of the MPal at c. We search for the center cs of the longest palindromic suffix of w[i..j] by using binary search on 𝖤. Let m=(i+j)/2 be the middle position of range [i..j]. Note that mcsj holds by the definition of cs. The search range [m..j] exhibits the following monotonicity:

  • 𝖤[𝖱𝖬𝖰𝖤(m,p)]<j holds for every p[m..cs1], and

  • 𝖤[𝖱𝖬𝖰𝖤(m,q)]j holds for every q[cs..j].

Thus, we can determine cs in O(logn) time by conducting a binary search within range [m..j], making use of RMQ at each step. The desired length s can be immediately obtained from cs and j.

Finally, we make the data structure compact. As mentioned before, an O(n)-bit data structure for RMQs on 𝖤 can be constructed, allowing O(1)-time queries. Moreover, each element of 𝖤 can be derived from 𝖬𝖤𝖯𝖺𝗅 as 𝖤[c]=c+𝖬𝖤𝖯𝖺𝗅[c]/21. Therefore, by Theorem 4, array 𝖤 can be represented in O(n) bits. In summary, we obtain the following:

Theorem 12.

There is a data structure of size O(n) bits that can answer each internal longest palindrome query in O(logn) time.

5 Conclusions

In this paper, we proposed an O(n)-bit data structure that can return the length of the maximal palindrome centered at a given position in constant time for a string of length n. As an application of this compact representation, we presented a data structure of size O(n) bits that can answer any internal longest palindrome query in O(logn) time.

Our future work includes the following:

  • Can we construct our data structure using only O(n) bits of working space? Especially, can we construct it without explicitly computing array 𝖬𝖤𝖯𝖺𝗅 of O(nlogn) bits?

  • Can we construct our data structures in O(n/logσn) time when the alphabet size σ is small? An O(n/logσn) time algorithm to compute the longest maximal palindrome is known [3].

  • Can we implement our data structure so that it outperforms the simple array representation of 𝖬𝖤𝖯𝖺𝗅 in practice?

References

  • [1] Amihood Amir, Panagiotis Charalampopoulos, Solon P. Pissis, and Jakub Radoszewski. Dynamic and internal longest common substring. Algorithmica, 82(12):3707–3743, 2020. doi:10.1007/S00453-020-00744-0.
  • [2] Alberto Apostolico, Dany Breslauer, and Zvi Galil. Parallel detection of all palindromes in a string. Theor. Comput. Sci., 141(1&2):163–173, 1995. doi:10.1016/0304-3975(94)00083-U.
  • [3] Panagiotis Charalampopoulos, Solon P. Pissis, and Jakub Radoszewski. Longest palindromic substring in sublinear time. In 33rd Annual Symposium on Combinatorial Pattern Matching, CPM 2022, June 27-29, 2022, Prague, Czech Republic, volume 223 of LIPIcs, pages 20:1–20:9. Schloss Dagstuhl – Leibniz-Zentrum für Informatik, 2022. doi:10.4230/LIPIcs.CPM.2022.20.
  • [4] Xavier Droubay, Jacques Justin, and Giuseppe Pirillo. Episturmian words and some constructions of de Luca and Rauzy. Theor. Comput. Sci., 255(1-2):539–553, 2001. doi:10.1016/S0304-3975(99)00320-5.
  • [5] Jonas Ellert, Pawel Gawrychowski, and Tatiana Starikovskaya. Minimal generators in optimal time. In 36th Annual Symposium on Combinatorial Pattern Matching, CPM 2025, June 17-19, 2025, Milan, Italy, volume 331 of LIPIcs, pages 14:1–14:19. Schloss Dagstuhl – Leibniz-Zentrum für Informatik, 2025. doi:10.4230/LIPIcs.CPM.2025.14.
  • [6] Nathan J Fine and Herbert S Wilf. Uniqueness theorems for periodic functions. Proceedings of the American Mathematical Society, 16(1):109–114, 1965. doi:10.1090/S0002-9939-1965-0174934-9.
  • [7] Johannes Fischer and Volker Heun. Space-efficient preprocessing schemes for range minimum queries on static arrays. SIAM J. Comput., 40(2):465–492, 2011. doi:10.1137/090779759.
  • [8] Mitsuru Funakoshi, Yuto Nakashima, Shunsuke Inenaga, Hideo Bannai, and Masayuki Takeda. Computing longest palindromic substring after single-character or block-wise edits. Theor. Comput. Sci., 859:116–133, 2021. doi:10.1016/J.TCS.2021.01.014.
  • [9] Zvi Galil and Joel I. Seiferas. Recognizing certain repetitions and reversals within strings. In 17th Annual Symposium on Foundations of Computer Science, Houston, Texas, USA, 25-27 October 1976, pages 236–252. IEEE Computer Society, 1976. doi:10.1109/SFCS.1976.25.
  • [10] Dan Gusfield. Algorithms on Strings, Trees, and Sequences - Computer Science and Computational Biology. Cambridge University Press, 1997. doi:10.1017/CBO9780511574931.
  • [11] Tomohiro I, Shunsuke Inenaga, and Masayuki Takeda. Palindrome pattern matching. Theor. Comput. Sci., 483:162–170, 2013. doi:10.1016/J.TCS.2012.01.047.
  • [12] Michael Itzhaki. Palindromes compression and retrieval. In Data Compression Conference, DCC 2025, Snowbird, UT, USA, March 18-21, 2025, page 375. IEEE, 2025. doi:10.1109/DCC62719.2025.00062.
  • [13] Donald E. Knuth, James H. Morris Jr., and Vaughan R. Pratt. Fast pattern matching in strings. SIAM J. Comput., 6(2):323–350, 1977. doi:10.1137/0206024.
  • [14] Roman Kolpakov and Gregory Kucherov. Searching for gapped palindromes. Theor. Comput. Sci., 410(51):5365–5373, 2009. doi:10.1016/J.TCS.2009.09.013.
  • [15] Dmitry Kosolobov, Mikhail Rubinchik, and Arseny M. Shur. Palk is linear recognizable online. In SOFSEM 2015: Theory and Practice of Computer Science - 41st International Conference on Current Trends in Theory and Practice of Computer Science, Pec pod Sněžkou, Czech Republic, January 24-29, 2015. Proceedings, volume 8939 of Lecture Notes in Computer Science, pages 289–301. Springer, 2015. doi:10.1007/978-3-662-46078-8_24.
  • [16] Stefan Langerman and Andrew Winslow. A quasilinear-time algorithm for tiling the plane isohedrally with a polyomino. In 32nd International Symposium on Computational Geometry, SoCG 2016, June 14-18, 2016, Boston, MA, USA, volume 51 of LIPIcs, pages 50:1–50:15. Schloss Dagstuhl – Leibniz-Zentrum für Informatik, 2016. doi:10.4230/LIPIcs.SOCG.2016.50.
  • [17] Veli Mäkinen, Djamal Belazzougui, Fabio Cunial, and Alexandru I. Tomescu. Genome-Scale Algorithm Design: Bioinformatics in the Era of High-Throughput Sequencing (2nd edition). Cambridge University Press, 2023. URL: http://www.genome-scale.info/.
  • [18] Glenn K. Manacher. A new linear-time "on-line" algorithm for finding the smallest initial palindrome of a string. J. ACM, 22(3):346–351, 1975. doi:10.1145/321892.321896.
  • [19] Wataru Matsubara, Shunsuke Inenaga, Akira Ishino, Ayumi Shinohara, Tomoyuki Nakamura, and Kazuo Hashimoto. Efficient algorithms to compute compressed longest common substrings and compressed palindromes. Theor. Comput. Sci., 410(8-10):900–913, 2009. doi:10.1016/J.TCS.2008.12.016.
  • [20] Takuya Mieno and Mitsuru Funakoshi. Data structures for computing unique palindromes in static and non-static strings. Algorithmica, 86(3):852–873, 2024. doi:10.1007/S00453-023-01170-8.
  • [21] Takuya Mieno, Mitsuru Funakoshi, and Shunsuke Inenaga. Computing palindromes on a trie in linear time. In 33rd International Symposium on Algorithms and Computation, ISAAC 2022, December 19-21, 2022, Seoul, Korea, volume 248 of LIPIcs, pages 15:1–15:15. Schloss Dagstuhl – Leibniz-Zentrum für Informatik, 2022. doi:10.4230/LIPIcs.ISAAC.2022.15.
  • [22] Kazuki Mitani, Takuya Mieno, Kazuhisa Seto, and Takashi Horiyama. Finding top-k longest palindromes in substrings. Theor. Comput. Sci., 979:114183, 2023. doi:10.1016/J.TCS.2023.114183.
  • [23] Shintaro Narisada, Diptarama Hendrian, Ryo Yoshinaka, and Ayumi Shinohara. Linear-time online algorithm for inferring the shortest path graph from a walk label. Theor. Comput. Sci., 812:187–202, 2020. doi:10.1016/J.TCS.2019.10.029.
  • [24] Mikhail Rubinchik and Arseny M. Shur. Counting palindromes in substrings. In String Processing and Information Retrieval - 24th International Symposium, SPIRE 2017, Palermo, Italy, September 26-29, 2017, Proceedings, volume 10508 of Lecture Notes in Computer Science, pages 290–303. Springer, 2017. doi:10.1007/978-3-319-67428-5_25.
  • [25] Mikhail Rubinchik and Arseny M. Shur. EERTREE: an efficient data structure for processing palindromes in strings. Eur. J. Comb., 68:249–265, 2018. doi:10.1016/J.EJC.2017.07.021.
  • [26] Mikhail Rubinchik and Arseny M. Shur. Palindromic k-factorization in pure linear time. In 45th International Symposium on Mathematical Foundations of Computer Science, MFCS 2020, August 24-28, 2020, Prague, Czech Republic, volume 170 of LIPIcs, pages 81:1–81:14. Schloss Dagstuhl – Leibniz-Zentrum für Informatik, 2020. doi:10.4230/LIPIcs.MFCS.2020.81.
  • [27] Michael Sipser. Introduction to the theory of computation. PWS Publishing Company, 1997.
  • [28] Peter Weiner. Linear pattern matching algorithms. In 14th Annual Symposium on Switching and Automata Theory, Iowa City, Iowa, USA, October 15-17, 1973, pages 1–11. IEEE Computer Society, 1973. doi:10.1109/SWAT.1973.13.

Appendix A Proof of Lemma 6

This section provides a proof of Lemma 6. We state some known results, which will be used in the proof of Lemma 6. We say that the radius of a palindrome is r if the length of the palindrome is 2r. We denote by gcd(p,q) the greatest common divisor of integers p and q.

Lemma 13 (Periodicity lemma [6]).

If a string w has two periods p and q with p+qgcd(p,q)|w|, then w also has period gcd(p,q).

Lemma 14 (Lemma 3.3 in [2]).

Assume that there are two even-palindromic factors in string w, each with radius at least r, centered at c1 and c2, where c1<c2 and c2c1r. Then the factor w[c1r..c2+r1] has period 2(c2c1).

Lemma 15 (Lemma 3.4 in [2]).

Assume that the radius of the MPal at c~ in w is at least r. Let w[eL..eR] be the maximal factor of w that contains w[c~r..c~+r1] and has period 2r. Namely,

  • w[i]=w[i+2r] for i[eL..eR2r],

  • eL=0 or w[eL1]w[eL+2r1], and

  • eR=|w|1 or w[eR+1]w[eR2r+1].

Then the radii of the maximal palindromes centered at c=c~+mr for m such that c[eL..eR] are given as follows:

  • If ceL<eRc+1, then the radius is ceL.

  • If ceL=eRc+1, then the radius is larger than or equal to ceL.

  • If ceL>eRc+1, then the radius is eRc+1.

Lemma 16.

If w[a..b]=w[c..d] are identical palindromic factors of w with acbd, then w[a..d] is a (possibly odd-) palindrome.

Proof.

For any i[0..(a+d)/2], it must hold that w[a+i]=w[di] as follows: since w[a..b] is a palindrome, w[a+i]=w[bi] holds; Since w[a..d] has period ca=db, w[bi]=w[bi+(ca)]=w[bi+(db)] holds; Finally, w[bi+(db)]=w[di].

Now we are ready to prove Lemma 6. See 6

Proof.

We denote N=|Lk| in this proof. For each i[1..N], let Pi be the length-2τ palindrome that is obtained by truncating the palindrome in Lk whose center is the i-th smallest in Lk. Further, let ci be the center of Pi. Let r=c2c1. Since c1,c2Bk with |Bk|=τ, it holds that r<τ. By Lemma 14, string X=w[c1τ..c2+τ1] has period 2r. Similarly, let r=c3c2<τ. Then string Y=w[c2τ..c3+τ1] has period 2r. Thus, P2=w[c2τ..c2+τ1] has periods 2r and 2r since it is a factor of both X and Y. For the sake of contradiction, assume that rr. We only consider the case r<r since the other case can be treated symmetrically. Since r+r=c3c1<|Bk|=τ, 2r+2r<2τ=|P2| holds, and thus, P2 has period r=gcd(2r,2r) by Lemma 13. Note that rr holds since r is a divisor of 2r and r2r<2r. Since r is a divisor of 2r, string Y also has period r. The periodicity of Y leads to an occurrence of a length-2τ palindrome that is identical to P2 and starts at c2τ+r=c3τ+r(c3c2)=c3τ+(rr). If r<r, then c2τ+r<c3τ, which contradicts the definition of P3 (see Fig. 3). Otherwise, if r=r, then P2=P3 holds. Note that r is an even integer since r is the gcd of two even integers 2r and 2r. By Lemma 16, the MPal at (c2+c3)/2=c2+r/2<c3 is a long palindrome, which contradicts the definition of P3. Therefore, r=r holds.

Figure 3: Illustration for a contradiction in the case where r<r. String Y has period r=gcd(2r,2r). If r is strictly smaller than r, another P2, indicated as a dotted-arrow, occurs between the original P2 and P3, a contradiction.

In general, the above discussion can be applied to any three consecutive length-2τ palindromes Pi, Pi+1, and Pi+2 obtained from Lk. Thus, by induction, it can be shown that ci+1ci=r holds for all i[1..N1]. Namely, ci=c1+(i1)r holds for all i[1,N]. Furthermore, since the factor w[ciτ..ci+1+τ1] has period 2r for each i[1,N1], the factor w[c1τ..cN+τ1] also has period 2r. Now, let w[eL..eR] be the maximal factor of w that contains w[c1r..c1+r1] and has period 2r. Then, the inclusion [c1τ..cN+τ1][eL..eR] holds, and thus, ci=c1+(i1)r[eL..eR] for all i[1..N]. Therefore, by Lemma 15, the radii of maximal palindromes centered at ci can be represented by at most two arithmetic progressions and a single integer. More precisely, (1) for ci with cieL<eRci+1, the radii can be represented by c1+(i1)reL; (2) for ci with cieL>eRci+1, the radii can be represented by eR(c1+(i1)r)+1; and (3) there is at most one maximal palindrome centered at c that satisfies ceL=eRc+1.