of length nis an ordered binary tree recursively defined below: the root is the leftmost occurrence
iof the smallest value in S, the left child of the root is the Cartesian-tree of S[1..i −1], and
the right child of the root is the Cartesian-tree of S[i+ 1..n]. We say that two strings of equal
length Cartesian-tree match if their Cartesian-trees are isomorphic. Cartesian-tree matching can
capture shapes of stock chart patterns such as head-and-shoulder [30]. Also, some significant stock
chart patterns exhibit palindrome-like structures (e.g., head-and-shoulder and double-top). Hence,
enumerating such palindrome-like structures in a stock chart is expected to improve the efficiency
of chart pattern searches. The first motivation of our research is to explore efficient methods to
compute such palindrome-like structures by applying Cartesian-tree matching.
First, let us revisit the definition of palindromes in the context of the standard matching model,
that is, the “equality” (≈) between two strings is the exact matching on a character-by-character
basis (=). There are two common definitions for palindromes: Let S=XaY be a string, where X
and Yare the same length, and ais either a single character or the empty string. Then, Sis said
to be a palindrome if:
Reverse-based definition: Sis equal to its reversal SR;
Symmetry-based definition: Yis equal to the reversal of X.
It is clear that if we assume the standard matching model, then the two definitions are the same,
meaning that a string Sis a reverse palindrome iff Sis a symmetric palindrome. Observe this
with examples such as racecar and noon. However, the two definitions above differ if we apply the
Cartesian-tree model. For instance, the Cartesian-tree of S1=223 is the tree with no branches that
slopes down to the right while the Cartesian-tree of SR
1=322 is shaped like a logical AND symbol (∧)
because the leftmost smallest element in S1is the second one. Thus, S1is not a reverse palindrome.
On the other hand, S1=223 is a symmetric palindrome since the Cartesian-trees of its right-half
3and the reversal of its left-half (2)R=2are both singletons. In addition, the two definitions are
also different if we apply the complementary-matching model where Amatches T, and Gmatches C,
which is a standard matching model for DNA sequences. For instance, a string S2=AGTCT is not a
reverse palindrome since S2[3] = Tand SR
2[3] = Tdo not complementary-match, but is a symmetric
palindrome since (AG)R=GA and CT complementary-match. Now we raise the following question: If
we apply other string-equality criteria ≈, including the parameterized model [4], the order-preserving
model [22], and the palindromic-structure model [18], then are the reverse palindromes and the
symmetric palindromes the same? This question is interesting because, while the symmetry-based
palindrome definition requires only XR≈Y, the reversal-based palindrome definition requires more
strict matching under ≈so that S≈SR⇔XaY ≈(XaY )R⇔XaY ≈YRaXR. Thus, these two
types of palindromes can be quite different for some matching criterion ≈(see also Figure 1). To
our knowledge, no previous work has considered or answered this natural question. In this paper,
we first provide quick answers to this question and present efficient algorithms for computing such
palindromes in a given string under the non-standard matching models.
One of the well-studied topics regarding palindromes is maximal palindromes, which are substring
palindromes whose left-right extensions are not palindromes. It is interesting and important to find
all maximal palindromes in a given string Tbecause any substring palindrome of Tcan be obtained
by removing an equal number of characters from the left and the right of some maximal palindrome.
Hence, by computing all maximal palindromes of a string, we obtain a compact representation of
all palindromes in the string. Manacher [25] showed an elegant algorithm for finding all maximal
palindromes in a given string T. Manacher’s algorithm works in an online manner (processes
the characters of Tfrom left to right) and runs in O(n)time and space for general (unordered)
alphabets, where nis the length of the input string T. Later, Gusfield [15] showed another famous
2