 # Palindromes in two-dimensional Words

A two-dimensional (2D) word is a 2D palindrome if it is equal to its reverse and it is an HV-palindrome if all its columns and rows are 1D palindromes. We study some combinatorial and structural properties of HV-palindromes and its comparison with 2D palindromes. We investigate the maximum number number of distinct non-empty HV-palindromic sub-arrays in any finite 2D word, thus, proving the conjecture given by Anisiua et al. We also find the least number of HV-palindromes in an infinite 2D word over a finite alphabet size q.

## Authors

##### This week in AI

Get the week's most popular data science and artificial intelligence research sent straight to your inbox every Saturday.

## 1. Introduction

Palindromes are extensively studied in -dimensional words by several authors [1, 4, 11, 12]

. There is an increasing interest in the combinatorial properties of palindromes in mathematics, theoretical computer science, and biology. Due to its symmetrical properties, this concept was generalized to two-dimension. Such a construction has significance in detecting bilateral symmetry of an image and face recognition technologies

[6, 13].

Identifying palindromes in arrays dates back to , when authors in , described an array to be a palindrome if all rows and columns are D palindromes. These structures are referred to as HV-palindromes in , where H and V stand for horizontal and vertical respectively. It was much later in when Berthé et al.,  formally defined a D palindrome to be an array which is equal to its reverse. It can be easily observed that an array whose all rows and columns are D palindromes is equal to its reverse. Hence, HV-palindromes is a sub-class of D palindromes. Recently, there has been a rise in research that deals with the concept of D palindromes. A relation between D palindromes and D primitive words was studied in . An algorithm for finding the maximal D palindromes was given in . The maximum and the least number of D palindromes in an array was studied in [3, 19] and  respectively.

The main idea of this paper is to study the structure of a special type of D word called an HV-palindrome. The motivation of studying this structure came from the conjecture mentioned in  which speculates about the maximum number of HV-palindromes in a D word of size for a given . We settle this conjecture in affirmative and generalize the result to words of larger sizes.

The paper is organized as follows. Section deals with the characterization of a word to be an HV-palindrome. Further, the D words whose all D palindromes are HV-palindromes are also characterized. In Section , we count the number of possible D palindromes and HV-palindromes for a given array size and investigate the number of D palindromic and HV-palindromic conjugates of a D word. Lastly, in Section , we find the maximum number of HV-palindromes in a finite D word and the least number of HV-palindromes in an infinite D word for a given alphabet size . We end the paper with some concluding remarks.

## 2. Basic definitions and notations

An alphabet is a finite non-empty set of symbols. A D word is defined to be a sequence of letters. denotes the set of all words over including the empty word . . The length of a word is the number of symbols in a word and is denoted by . The reversal of is defined to be a string where . is the set of all factors of of length . A word is said to be a palindrome if . The concepts of prefix, suffix, primitivity, and conjugates are as usual. For all other concepts in formal language theory and combinatorics on words, the reader is referred to [14, 18].

### 2.1. Two-dimensional arrays

A two-dimensional word over of size is defined to be a two-dimensional rectangular array of letters. If both and are infinite, then is an infinite D word. A factor of is a sub-array of . In the case of D words, an empty word is a word of size , and we use the notation to denote such a word. The set of all D words including the empty word over is denoted by whereas, is the set of all non-empty D words over . Note that, the words of size and for are not defined.

###### Definition 2.1.

Let and be two words over of size and , respectively.

1. The column concatenation of and denoted by is a partial operation, defined if , and it is given by

 u⌽v=u1,1⋯u1,n1v1,1⋯v1,n2⋮⋱⋮⋮⋱⋮um,1⋯um,n1vm,1⋯vm,n2

The column closure of denoted by is defined as where .

2. The row concatenation of and denoted by is a partial operation defined if , and it is given by

 u⊖v=u1,1⋯u1,n⋮⋱⋮um1,1⋯um1,nv1,1⋯v1,n⋮⋱⋮vm2,1⋯vm2,n

The row closure of denoted by is defined as where .

In , a prefix of a D word is defined to be a rectangular sub-block that contains one corner of , whereas suffix of is defined to be a rectangular sub-array that contains the diagonally opposite corner of . However, throughout this paper, we consider prefix/suffix of a D word to be a rectangular sub-array that contains the top-left/bottom-right corner of . This was formally defined in  as follows.

###### Definition 2.2.

Given , is said to be a prefix of respectively, suffix of , denoted by respectively if or respectively, or for .

If a sub-array occurs as both the prefix and suffix of a D word , then it is called a border of .

###### Definition 2.3.

Let be a D word. The reverse and transpose of denoted by and respectively are defined as

If , then is said to be a two-dimensional D palindrome ([5, 9]).

###### Example 2.4.

Let and let

 w=abcabccaaccbacba

Note that and hence is a D palindrome.

Note that the rows and columns of a D palindrome are not always D palindromes. We observe that if all columns and rows of a finite D word are palindromes, then the word itself is a palindrome. Such palindromes are referred to as HV-palindromes in .

###### Example 2.5.

Let and let

 u=ababcbaba

Note that every row and every column of is a 1D palindrome. Thus, is an HV-palindrome.

We recall the notion of horizontal and vertical palindromes from .

###### Definition 2.6.

Let be a D word. The horizontal palindromes of are the palindromic factors of of size where and of are the palindromic factors of of size where .

The palindromes of size are trivial. Note that, all horizontal and vertical palindromes are HV-palindromes. We now recall the notion of the center of a word defined in .

###### Definition 2.7.

Center is the position that results in an equal number of columns to the left and right, as well as an equal number of rows above and below i.e. in a word of size , if and

are odd, then the center is at location

. If or/and is even, the center is in between rows or/and columns respectively.

###### Example 2.8.

The center of in Example 2.4 is in between the rows and columns of the sub-array . However, for the word from Example 2.5, the center of is the sub-word c.

For more information pertaining to two-dimensional word concepts, we refer the reader to [8, 10, 5, 9].

## 3. Structure of an HV-palindrome

By definition, if a D word of size is a palindrome, then and accepts the following structures.

• If , then admits four symmetries namely identity, two diagonal reflections and rotation.

• If , then admits two symmetries namely identity and rotation.

Hence, given a D palindrome of size , let be the prefix of size and . Then, is of the form

1. , if is even.

2. , if is odd.

In addition to the symmetries in a D palindrome, an HV-palindrome is preserved under reflections about horizontal and vertical axis containing the center of the word. Due to such symmetrical properties, we give the exact structure of an HV-palindrome.

###### Theorem 3.1.

Structure theorem of HV-palindromes
Given an HV-palindrome of size , let be the prefix of of size ,  ,   and . Then, is of the form

Structure of Structure of
even  even  even  odd
odd  even  odd  odd

where

###### Proof.

We give the proof of case when and are both even and the rest of the cases follow similarly. Let be an HV-palindrome of size and be the prefix of of size . Now, as every row of is a palindrome, is the prefix of of size . Also, as every column of is a palindrome, then . ∎

We observe that similar to the construction in case of a D palindrome in , an HV-palindrome of size can be constructed from an HV-palindrome of size by removing the row and column of . We also observe the following result.

###### Lemma 3.2.

If is an HV-palindrome of size , then the word obtained by removal of first and last rows of , for and first and last columns of , for is an HV-palindrome of size . This result is also true in the case of D palindromes.

### 3.1. Characterization of an HV-palindrome

In this section, we first give two necessary and sufficient conditions for a D word to be an HV-palindrome and then give a characterization of D words such that all of its palindromic sub-words are HV-palindromes i.e., words with no non-HV-palindromes. We begin the section by stating a necessary and sufficient condition for a 2D word to be an HV-palindrome.

###### Proposition 3.3.

Let be a D word of size , where and be the row and column of respectively. Then, is an HV-palindrome if and only if for and for .

###### Proof.

Let be an HV-palindrome. This implies each and is a palindrome. Every row of is a palindrome if and only if for . Every column is a palindrome if and only if for . ∎

One can easily observe that the above result does not hold true in the case of D palindromes that are not HV-palindromes. For example, the word given in Example 2.4 does not satisfy the conditions given in Proposition 3.3.

It is well known that a 1D word is a 1D-palindrome if and only if for some 1D palindromes and .

It was proved in , that for 2D palindromic words the condition is only sufficient. We now show that the condition is both necessary and sufficient for an HV-palindrome.

###### Proposition 3.4.

Let be HV- palindromes. Then, or , if and only if is an HV- palindrome.

###### Proof.

Let , then

 uR =[(x⌽y)i⌽⌽x]R =xR⌽(yR⌽xR)i⌽ =(xR⌽yR)i⌽⌽xR =(x⌽y)i⌽⌽x =u

Hence, . A similar proof follows for . Now as and are HV-palindromes, then is an HV-palindrome. Hence, is an HV-palindrome for .
Conversely, let be an HV-palindrome of size , then and by Proposition 3.3, for and every row of is a palindrome. Let and . By Lemma 3.2, is an HV-palindrome. Thus, .

All letters from the alphabet are trivially palindromes and hence every D word has palindromic sub-words. Also, all trivial palindromes are HV-palindromes and all HV-palindromes are D palindromes. However, a D palindrome may or may not be an HV-palindrome. A word may or may not contain non-HV palindromes. In the following, we give a characterization of D words such that all of its palindromic sub-words are HV-palindromes. The word in Example 2.5 is one such word.

###### Theorem 3.5.

All D palindromic sub-words of a D word are HV-palindromes if and only if has no sub-word of the form

 xuyvpvRyuRx

where such that , and are D words and is a D palindrome (may be empty).

###### Proof.

Let be a D word with no sub-word of the form

 xuyvpvRyuRx

where such that , and are D words and is a D palindrome. We show that all of its D palindromic sub-words are HV-palindromes. Let be a D palindromic sub-word of of size , with , then it must be of the form

 x1u1x1v1p1vR1x1uR1x1

where , and are D words and is a D palindrome. We show that is an HV-palindrome. Consider the first and last row of . We show that they are the same. If not, consider the first position where they are different, say it is the position. Let the position of the first and last row of be and respectively, where . As is a D palindrome, then the position of the first and last row of are and respectively. Then has a sub-word of the form where , and are D words and is a D palindrome which is a contradiction. Hence, the first row and the last row of are same. Similarly, we can show that the and row of are same for . Now, consider the word which is a palindrome of size . Apply the same procedure on to show that the and row of are same for . This implies and column of is same for . Thus, by Proposition 3.3, is an HV-palindrome.
Conversely, if all palindromes of are HV-palindromes, then any sub-word of the form

 xuyvpvRyuRx

where are distinct, and are D words and is a D palindrome is itself a non-HV-palindrome which is a contradiction. ∎

### 3.2. Borders in an HV-palindrome

We now count the number of borders in an HV-palindrome. We first observe a general result for D palindromes.

###### Proposition 3.6.

Every border of a D palindrome is a D palindrome.

###### Proof.

Let be a D palindrome of size . Let be a border of size , then

 (1) v=w1,1w1,2⋯w1,jw2,1w2,2⋯w2,j⋮⋮⋱⋮wi,1wi,2⋯wi,j=wm−i+1,n−j+1wm−i+1,n−j+2⋯wm−i+1,nwm−i+2,n−j+1wm−i+2,n−j+2⋯wm−i+2,n⋮⋮⋱⋮wm,n−j+1wm,n−j+2⋯wm,n

Now, as is a palindrome, then for

 (2) w1+k,1w1+k,2⋯w1+k,j=(wm−k,n−j+1wm−k,n−j+2⋯wm−k,n)R

Hence, by Equations 1 and 2, is a D palindrome. ∎

###### Corollary 3.7.

Every border of an HV-palindrome is a D palindrome.

###### Remark 3.8.

Border of an HV-palindrome need not be an HV palindrome. In Example 2.5, is a border but is not an HV-palindrome.

We now count the number of borders in a D palindrome and an HV-palindrome. It is clear that the maximum number of borders in a word of size is and is achieved when . Let be the set of all borders of , then we have the following result.

###### Lemma 3.9.

Let be a word of size .

1. If is a D palindrome, then .

2. If is an HV-palindrome, then .

###### Proof.

Let be a word of size , .

1. If is a D palindrome, then the prefix of size is a border of . It can be observed in Example 2.4 that the lower bound is tight.

2. If is an HV-palindrome, then the prefixes of size , and are borders of . We show the existence of words that achieve the lower bound. Let

 w=abababbabbababa

Here, is an -palindrome with only borders.

## 4. Counting Palindromes

It can be easily observed that the maximum number of distinct D palindromes of length over an alphabet size is . In this section, we first count the maximum number of D palindromes (HV-palindromes) that can be obtained over a given alphabet . We then determine the maximum and the minimum number of D palindromes (HV-palindromes) that can appear in the conjugacy class of a given D word .

###### Theorem 4.1.

Let be a finite alphabet such that . Then,

1. the maximum number of distinct D palindromes of size is where .

2. the maximum number of distinct HV-palindromes of size is where .

###### Proof.

Let be a palindrome of size such that , where is the th row of . Since , the D word is a D palindrome. Let be the prefix of of length . Then, is a suffix of . Thus, we have distinct choices of letters from and therefore, there are distinct D palindromes of size over . If is an HV-palindrome of size , then by Proposition 3.3, we have distinct choices of letters in the prefix of of size . Hence, there are distinct HV-palindromes of size over .

We illustrate with the following example.

###### Example 4.2.

Consider the binary alphabet . The set of all 2D-palindromes of size is given by:

 {aaaa,  abba,  baab, bbbb }

which has exactly D palindromes and HV-palindromes of size .

### 4.1. Palindromes in a conjugacy class

It was proved in  that a conjugacy class of a D word contains at most two D palindromes. We now count the number of D palindromes and HV-palindromes in a conjugacy class of a D word. We recall the definition of conjugates in an array from .

###### Definition 4.3.

Let and be respectively the rows and the columns of a word of size . The cyclic rotation of columns, for denoted by is defined as the word

 ↺Colk=vn−k+1⌽⋯vn⌽v1⌽v2⋯vn−k−1⌽vn−k

Similarly, the cyclic rotation of rows, for denoted by is defined as the word

 ↺Rowk=um−k+1⌽⋯um⌽u1⌽u2⋯um−k−1⌽um−k

Then, the conjugacy class of denoted by Conj(u) is defined as

 Conj(u)={↺Coli↺Rowju,1≤i≤n,1≤j≤m}

Note that, given any 2D word of size , the number of elements in its conjugacy class can be at most . We illustrate with the following example.

###### Example 4.4.

Consider the 2D word of size . Then, the conjugacy class of is given by:

 Conj(w)=⎧⎪ ⎪ ⎪⎨⎪ ⎪ ⎪⎩ abccbbbbccba,cbbbbccbaabc,bbccbaabccbb,cbbbbccbaabc,bcabbcbcbbac,bbcbcbbacbca,bcbbacbcabbc,bbcbcbbacbca,cabbcbcbbacb,bcbcbbacbcab,cbbacbcabbcb,bcbcbbacbcab ⎫⎪ ⎪ ⎪⎬⎪ ⎪ ⎪⎭
###### Remark 4.5.

For a 2D word of size , if , and if , . However, the converse need not be true as illustrated in Example 4.4. If the D word is a D palindrome and if , then . If is an HV-palindrome and if , then .

We now count the maximum number of D palindromes (HV-palindromes) in the conjugacy class of a D word. We call such conjugates as palindromic (HV-palindromic) conjugates and denote them by . Note that, for the given in Example 4.4 we have,

 PALConj(w)=⎧⎪ ⎪ ⎪⎨⎪ ⎪ ⎪⎩ abccbbbbccba,bbccbaabccbb ⎫⎪ ⎪ ⎪⎬⎪ ⎪ ⎪⎭, HVPALConj(w)=∅

We give another example of a D word of size where .

 PALConj(v)=HVPALConj(v)=⎧⎪ ⎪ ⎪⎨⎪ ⎪ ⎪⎩ abbaaaaaaaaaabba,baabaaaaaaaabaab,aaaaabbaabbaaaaa,aaaabaabbaabaaaa ⎫⎪ ⎪ ⎪⎬⎪ ⎪ ⎪⎭

We first recall the following result for D words from .

###### Theorem 4.6.

A conjugacy class of a D word contains at most two palindromes and it has exactly two if and only if it contains a word of the form , where is a primitive word and .

We have the following result.

###### Theorem 4.7.

Let be a D word of size , then

 0≤|PALConj(w)|≤⎧⎨⎩4,if m,\;n are even,1,if m,\;n are odd,2,otherwise.
###### Proof.

It is clear that there exist words for example, with no palindromic conjugates. Also, note that for a D word of size such that , and for , such that , .

We now find the maximum number of palindromic conjugates that can have. If has no palindromic conjugates, then we are done. Otherwise, assume that . Note that, . Now, , where is the column of and is the row of . As is a palindrome, then it is a D palindrome over the alphabet of columns i.e., the set . It is a also a D palindrome over the alphabet of rows i.e., the set . Also, note that is a D palindrome iff it is a D palindrome over its alphabet of columns and its rows. We have the following cases.

• If and are both even, then by Theorem 4.6, as is even, there can be at most D palindromic conjugates of say and over its alphabet of columns. Each of them can be expressed as alphabet of rows say the set . Again, as is even, by Theorem 4.6, there are at most palindromic conjugates of and each as a D word over . In total, there are at most palindromic conjugates in the conjugacy class of . Hence, for some and ,

 PALConj(w)={↺Coli1↺Rowj1w,↺Coli1↺Rowj2w,↺Coli2↺Rowj1w,↺Coli2↺Rowj2w,}
• If is even and is odd, then can be expressed as a D word over its alphabet of rows. As is odd, by Theorem 4.6, there is no palindromic conjugate of , other than . Again can be expressed as a D word over the alphabet of columns say the set to obtain at most palindromic conjugates over . In total, there are at most palindromic conjugates in the conjugacy class of . Hence, for some and ,

 PALConj(w)={↺Coli1↺Rowj1w,↺Coli1↺Rowj2w}

Similar is the case when is odd and is even. Here, for some and ,

 PALConj(w)={↺Coli1↺Rowj1w,↺Coli2↺Rowj1w}
• If are both odd, by Theorem 4.6, there is no palindromic conjugate of , other than . Hence, for some and ,

 PALConj(w)={↺Coli1↺Rowj1w}

Theorem 4.7 also holds in case of HV-palindromes. We have the following result.

###### Corollary 4.8.

Let be a D word of size , then

 0≤|HVPALConj(w)|≤⎧⎨⎩4,if m,\;n are even,1,if m,\;n are odd,2,otherwise.
###### Remark 4.9.

We now find the structure of the words that achieve the above upper bound in case of HV-palindromes. Let , then by the structure of , and .

1. If and are even, then to have distinct palindromic conjugates, we have the following:

1. and . This implies that the prefix of size is not an HV-palindrome.

2. and . This implies that the prefix of size is not an HV-palindrome.

3. . This implies that the prefix of size is not a D palindrome.

4. . This implies that the prefix of size is not a D palindrome.

Hence, in this case iff the prefix of size of is not a D palindrome.

2. For even and odd, i.e. iff the prefix of size is not an HV-palindrome.

3. For odd and even, i.e. iff the prefix of size is not an HV-palindrome.

## 5. Bounds on the number of palindromes

In this section, we find the maximum and the least number of HV-palindromes in any D finite and infinite word respectively. We also compare these results with the existing results on D palindromes.

### 5.1. On the maximum number of HV-palindromes

In this section, we find the maximum number of non-empty distinct HV-palindromes in a D word of size . It was proved in  and  that there are at most palindromes in a D word of length and at most palindromes in a two-row array of size respectively. Further, it was conjectured in  that the number of HV-palindromes in any D word of size is less than or equal to . We give a proof of this conjecture. We also extend the result to a word of size and find an upper bound.

###### Theorem 5.1.

The maximum number of HV-palindromes in any D word of size is .

###### Proof.

Let be a D word of size . The number of HV-palindromes in is the sum of horizontal palindromes in and the HV-palindrome of size in . It can be observed that the HV-palindromes of size