# Sorting Permutations with Fixed Pinnacle Set

We give a positive answer to a question raised by Davis et al. ( Discrete Mathematics 341, 2018), concerning permutations with the same pinnacle set. Given π∈ S_n, a pinnacle of π is an element π_i (i≠ 1,n) such that π_i-1<π_i>π_i+1. The question is: given π,π'∈ S_n with the same pinnacle set S, is there a sequence of operations that transforms π into π' such that all the intermediate permutations have pinnacle set S? We introduce balanced reversals, defined as reversals that do not modify the pinnacle set of the permutation to which they are applied. Then we show that π may be sorted by balanced reversals (i.e. transformed into a standard permutation _S), implying that π may be transformed into π' using at most 4n-2min{p,3} balanced reversals, where p=|S|≥ 1. In case p=0, at most 2n-1 balanced reversals are needed.

## Authors

• 5 publications
08/31/2020

### Sorting by Prefix Block-Interchanges

We initiate the study of sorting permutations using prefix block-interch...
12/10/2018

### Learning Representations of Sets through Optimized Permutations

Representations of sets are challenging to learn because operations on s...
07/08/2021

### On the 4-Adic Complexity of Quaternary Sequences with Ideal Autocorrelation

In this paper, we determine the 4-adic complexity of the balanced quater...
01/08/2018

### Generalized Reed-Solomon Codes with Sparsest and Balanced Generator Matrices

We prove that for any positive integers n and k such that n≥ k≥ 1, there...
01/04/2022

### A note on the paper arXiv:2112.14547

We give historical remarks related to arXiv:2112.14547 ("A New Method of...
06/22/2018

### Improved bounds for multipass pairing heaps and path-balanced binary search trees

We revisit multipass pairing heaps and path-balanced binary search trees...
01/02/2021

### Visual High Dimensional Hypothesis Testing

In exploratory data analysis of known classes of high dimensional data, ...
##### 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

In a permutation from the symmetric group , a peak is an index such that , whereas a valley is an index such that . Descents and ascents respectively identify indices such that and .

Many studies have been devoted to the combinatorics of peaks, especially to enumeration and counting problems [1, 2, 3, 6, 9, 11] (and many others). They identify strong and elegant relationships between peaks or descents in permutations, on the one hand, and Fibonacci numbers, Eulerian numbers, chains in Eulerian posets, etc. on the other hand.

In [5], Davis et al. revive the point of view considered in [4], and propose to identify peaks by their values rather than by their positions. They call a pinnacle any element with such that , and show that considering pinnacles instead of peaks changes the combinatorial considerations behind counting and enumerating permutations with a given peak/pinnacle set. They characterize the sets of integers that may be the pinnacle set of a permutation (so-called admissible pinnacle sets), count them, and propose bounds, involving the Stirling number, on the numbers of permutations with given pinnacle set.

They further ask several questions, one of which is considered in this paper:

Question 4.2 in [5]. For a given admissible pinnacle set , is there a class of operations that one may apply to any whose pinnacle set is to obtain any other permutation with the same pinnacle set, and no other permutation?

This question is motivated by the search for similarities between pinnacles and peaks [5]. In this paper we give a positive answer to this question. More particularly, we identify a reduced set of reversals (the operation that reverses a block of a permutation) - called balanced reversals - which do not modify the set of pinnacles. Then we show that it is possible to transform any permutation with pinnacle set into a canonical permutation of the same size with pinnacle set by applying a sequence of at most balanced reversals. As the inverse transformation is always possible, this answers Question 4.2. above.

The paper is organized as follows. Section 2 contains the main definitions and notations. In Section 3 we identify balanced reversals and state the main results. Section 4 is devoted to the proof of our main theorem. This proof describes the algorithm allowing us to find the sequence of reversals transforming a given permutation into the canonical permutation. For the sake of completeness, we give in Section 5 the implementation details for an optimal running time of our algorithm. Section 6 is the conclusion.

## 2 Definitions and notations

Permutations we use in the paper belong to the symmetric group , for a given integer . Elements and are artificially added at the beginning and respectively the end of each permutation, so that a permutation is written as with and . For each , we define and for each we define . The block of with endpoints and (where ) is defined as .

A pinnacle is any element with such that . Similarly to pinnacles (whose indices are the peaks), we define the dells (whose indices are the valleys). A dell of is any element with such that . The shape of the permutation is the permutation where are the dells of , are its pinnacles, whereas and . The presence of the elements and at the beginning and the end of the permutation adds no pinnacle to the initial permutation, and ensures that dells exist.

Moreover, let with be the set of elements in the block of with endpoints and , which are neither a dell nor a pinnacle. Similarly let with be the set of elements in the block of with endpoints and , which are neither a dell nor a pinnacle. Sets and are respectively called ascending and descending sets of . Note that and belong respectively to the leftmost descending and the rightmost ascending set. The dells and pinnacles belong to no such set.

###### Example 1.

Consider from (thus ) with elements 11 and 12 artificially added. Dells are underlined, pinnacles are overlined, . The shape is . The ascending sets are , and , whereas the descending sets are , and .

We define a canonical permutation according to [5]. Given a set and an integer , the canonical permutation with pinnacle set is the permutation built as follows: place the elements of in increasing order on positions respectively; then place the elements in in increasing order on positions . With our convention, elements and are added at the beginning and respectively the end of .

###### Definition 1.

Let be two elements of , such that and . The reversal is the operation that transforms into . Notation: .

###### Example 2.

With , the canonical permutation is , with shape . Then has the same pinnacle set as in Example 1, but not the same dells and thus not the same shape. Applying to yields the permutation . It may be noticed that the resulting permutation has pinnacle set , showing that reversals may modify the pinnacle set.

###### Definition 2.

Let . A reversal is a balanced reversal for if and have the same pinnacle set.

Balanced reversals are characterized in the next section. In order to identify appropriate balanced reversals when needed, we make use of cutpoints. Let be an integer with and be an element of not belonging to , such that . The largest element of such that is called the cutpoint of on and is denoted . The similar definition holds for . Let be an integer with and be an element of not belonging to , such that . The largest element of such that is called the cutpoint of on and is denoted .

Finally, define the following problem:

Balanced Sorting Problem

Input: A permutation with pinnacle set .

Question: Is it possible to transform into using only balanced reversals?

The difficulty in solving this problem has mainly two origins: first, one cannot perform any wished reversal since a reversal is not necessarily balanced (see Example 2); and second, given a set of pinnacles and a permutation of the elements in , it is possible that no permutation of given size and with pinnacle exists that has the pinnacles in the order (from left to right) given by .

###### Example 3.

Let set . Then with and we may find the permutation , but with and there is no permutation from with pinnacles in this order.

Therefore, the Balanced Sorting Problem is a question of feasibility in the first place. The optimal sorting is proposed as an open problem in the conclusion.

## 3 Main results

Let be a permutation with pinnacle set such that . The main result of the paper is the following one.

###### Theorem 1.

There is a sequence that solves the Balanced Sorting Problem on using at most balanced reversals when , and at most reversals when .

An answer to Question 4.2 is an immediate consequence of this theorem.

###### Corollary 1.

Let be two permutations with pinnacle set such that . Then, when there is a sequence of at most balanced reversals that transforms into , using only intermediate permutations with pinnacle set . When , contains at most balanced reversals.

###### Proof.

Let be the sequence of balanced reversals needed to sort according to Theorem 1. Similarly, let be the sequence of balanced reversals needed to sort . Let be the sequence made of followed by the sequence . Then transforms into and subsequently into using only balanced reversals. The definition of a balanced reversal guarantees that all the intermediate permutations have pinnacle set . ∎

Recall that, by Definition 1, in a reversal the endpoints and are in this order from left to right on and are distinct from . Depending on the position of and in , balanced reversals are of different types and imply different constraints, that need to be satisfied in order to guarantee that the reversal is balanced. Table 1 presents the different possible positions for and , each defining a type. On the rightmost column are given the constraints that and their adjacent elements must fulfill in order to obtain a balanced reversal. For instance, reversal of type A.1 is obtained when belongs to an ascending set of and belongs to a descending set of . One further requires that the following constraints be verified: when we must have ; when we must have .

The standard cases A.1 and B.1 are shown in Figure 1. The other cases are obtained from A.1 or B.1 when or or both of them are a pinnacle or a dell. Cases denoted A.x are obtained from case A.1 only, cases B.x are obtained from B.1 only and cases C.x are obtained from both A.1 and B.1. Symmetrical cases are identified by an “s”. We show below that these types form altogether the entire collection of balanced reversals.

###### Proposition 1.

Reversal is balanced iff it belongs to the collection of types in Table 1.

###### Proof.

: Several cases may appear.

If both and belong to ascending sets of the permutation, that is and with , then when the reversal is performed or becomes a new pinnacle, a contradiction. A similar reasoning holds when both and belong to descending sets of the permutation. So these cases cannot appear.

If one element among and belongs to an ascending set of the permutation, and the other one to a descending set of it, then it is easy to check that only the conditions in type A.1. or in type B.1. guarantee that no new pinnacle is added.

If exactly one element among and is a dell, then we necessarily have one of the types A.3, B.3, C.1 (or the symmetric ones) since any other condition creates a new pinnacle or removes an existing one.

If exactly one element among and is a pinnacle, then the other one is either a dell or belongs to an ascending or descending set of . The former possibility necessarily leads to type C.1 (or the symmetric one). The latter possibility results into types A.2, A.2s, B.2 or B.2s.

If both and are pinnacles, or both are dells, then we must have the conditions in types C.2 or C.3 to preserve the pinnacle set.

: This part only requires to check, for each type, that the pinnacle set is not modified under the indicated conditions. ∎

## 4 Proof of Theorem 1

We assume below that and postpone the case to Remark 2, at the end of the section.

In order to build the sequence required in Theorem 1, we follow three steps:

1. Sort the pinnacles of in increasing order.

2. Place the wished dells (i.e. the dells of ) as dells of , in increasing order.

3. Move each element belonging to an ascending or descending set of on the rightside of the last dell of , in increasing order.

The result of these three steps is . Then is the sequence of all the balanced reversals performed during these three steps in order to transform into .

###### Remark 1.

Note that in the subsequent, when permutation is successively transformed using balanced reversals into some other permutation , the elements of are identified both by their names in , i.e. etc. and by their names in , according to the needs. Once a given task is fulfilled by applying one or several balanced reversals, the resulting permutation is renamed as , so that the following task begins with an initial permutation still denoted .

### 4.1 Step 1: Sort the pinnacles

This is done by successively replacing the pinnacle , for , by the -th lowest pinnacle without modifying the set of pinnacles. Then in the resulting permutation the highest pinnacle is necessarily . The other elements are not constrained at this step. Algorithm 1 presents the balanced rotations to be performed, as identified in this subsection.

###### Lemma 1.

There is a sequence of at most balanced reversals that transforms with pinnacle into with pinnacle such that is the lowest pinnacle in . Moreover, when , exactly one of the two following configurations occurs:

• the sequence contains exactly balanced reversals and is the highest pinnacle in .

• the sequence contains at most balanced reversals.

###### Proof.

If is already the lowest pinnacle, then nothing is done. Assume now the lowest pinnacle is with . Several cases are possible, that we present below, before giving the algorithm.

Case 1). and for all , we have .

Then and the balanced reversal (type C.2) allows to obtain a permutation with . In :

1. if , then we are done.

2. if and , then we have that and we deduce that at least one pinnacle placed on the rightside of is larger than . Then satisfies Case 2 below.

3. if and , then satisfies Case 3 below.

Case 2) and there is such that .

Then we assume w.l.o.g. that is the minimum index with this property. Then , otherwise we also have which contradicts the choice of . Now, is a balanced reversal (type C.2) since is not a pinnacle and even if it may happen that we have . Once is performed, the new first dell is and is smaller than as proved above. Let us call this new permutation, whose elements satisfy for some , . In :

1. if , then we are done.

2. if and , then satisfies Case 2 since , so there is at least one index as required in Case 2. The smaller such index, say , satisfies .

3. if and , then is in Case 3 below.

Condition in item means that the recursivity we find here will end, as we show later (once Case 3 is presented).

Case 3) .

Let . Then is a balanced reversal (type A.2s if and type C.3 otherwise) since and , both by the definition of the cutpoint . This reversal places as the leftmost pinnacle.

The algorithm consists in applying Case 1 if necessary, then Case 2 as long as the current permutation requires it (in item of Case 2) and finally Case 3 if needed. It is presented in Algorithm 1. In order to compute the number of balanced reversals performed in the worst case, we denote:

• the initial permutation

• the permutation obtained at the end of Case 1, whether it is applied or not (so that if not).

• the successive permutations obtained using Case 2 ( if Case 2 is not applied).

• the permutation obtained once Case 3 is applied, if it is applied.

As a consequence, if then for , permutation is transformed into permutation using the balanced reversal of type C.2, as mentioned in Case 2 before. Here, denotes the minimum index computed in Case 2 for each , i.e. (see Case 2), (see item in Case 2), and so on. Indices computed respectively in satisfy (see again Case 2 item where we show that ):

1. are pinnacles in the permutation for each with , in this order from left to right. Moreover, each permutation inherits the pinnacles of the previous permutation , that is, for all (meaning that the pinnacles as well as their indices in the permutation are the same).

2. and satisfy the conditions of Case 2 item in for each with .

3. permutation obtained when Case 2 does not apply any longer contains all the pinnacles built by the previous iterations, in this order from left to right.

The number of balanced reversals performed in this step strongly depends on the number of reversals performed at worst in Case 2. By item (iv) above, are pinnacles in the permutation obtained when Case 2 does not apply any longer, in this order from left to right. The number of such pinnacles (i.e. ) is upper bounded by , since (1) , and (2) when the -th reversal is applied (to ), at least two pinnacles exist in the block to be reversed, the current leftmost pinnacle and . They are distinct, otherwise no reversal is applied. Thus . Now:

• If , then the pinnacles of are necessarily, in this order from left to right, , (= ), (= ), (= ). The last reversal due to Case 2, i.e. , places as the leftmost pinnacle, and thus we are done. Item in Case 2 applies, and no other reversal is needed. Then the total number of reversals applied in Step 1 is when Case 1 applies and otherwise. In the latter case, configuration (Y) in the lemma occurs. The former case is fixed using property (P) below.

• If , then we distinguish again several situations:

• When , the total number of reversals applied in Step 1 is when exactly one of Case 1 and Case 3 applies, and when both Case 1 and Case 3 apply. Configuration (Y) then occurs.

• When and , then as above the pinnacles of must be , (= ), (= ), (= ) and , where is the rightmost pinnacle, that is never involved in the reversals. The last reversal due to Case 2, i.e. , places as the leftmost pinnacle, and thus we are done. Item in Case 2 applies, and no other reversal is needed. Then the total number of reversals in step 1 is when Case 1 applies and otherwise, yielding configuration (Y) again.

• When and , the total number of reversals applied in Step 1 is when at most one of Case 1 and Case 3 applies (configuration (Y) again), and when both Case 1 and Case 3 apply. The latter case is fixed using property (P) below.

We now finish the two unresolved cases, both of which occur when Case 1 applies and (recall that the pinnacles with indices are inherited from one execution of Case 2 to the next one, by affirmation (ii) above).

(P) If Case 1 applies and in Case 2 we have , then is the highest pinnacle in .

Indeed, since Case 1 applies, in we have , for all . Thus in (see Case 1) we have for all , where . When is renamed as , we have:

for all , where . (1)

Moreover, since Case 2 applies with , we have that:

(2)

, for all with . (3)

By (1), and by definition , thus for all , where . By (2) and (3), for all with . Thus is the highest pinnacle in . Due to affirmation (ii) above, is the highest pinnacle in and property (P) is proved.

Now, property (P) applies in each of the two unresolved cases and yield configuration (X). Lemma 1 is proved. ∎

Once the lowest pinnacle is placed first, i.e. it is , each of the other pinnacles is easily placed. The reasoning is by induction.

###### Lemma 2.

Assume that are the lowest pinnacles, with , and assume with is the next lowest pinnacle. Then there is a balanced reversal allowing to replace with , which does not modify the pinnacles , with .

###### Proof.

We notice that . With , the reversal is balanced (type A.2s if and type C.3 otherwise) and moves at the sought place. ∎