Open Access
This article is

- freely available
- re-usable

*Algorithms*
**2019**,
*12*(11),
237;
https://doi.org/10.3390/a12110237

Article

What Do a Longest Increasing Subsequence and a Longest Decreasing Subsequence Know about Each Other?

Department of Computer Science, Ariel University, Ariel 40700, Israel

^{*}

Authors to whom correspondence should be addressed.

Received: 21 August 2019 / Accepted: 29 October 2019 / Published: 7 November 2019

## Abstract

**:**

As a kind of converse of the celebrated Erdős–Szekeres theorem, we present a necessary and sufficient condition for a sequence of length n to contain a longest increasing subsequence and a longest decreasing subsequence of given lengths x and y, respectively.

Keywords:

Erdős–Szekeres theorem; longest increasing sequence; longest decreasing sequence## 1. Introduction

In 1935, Hungarian mathematicians Paul Erdős and George Szekeres proved a celebrated theorem, which is now a classic, on relations between lengths of a sequence and its increasing (decreasing) subsequence [1].

**Theorem**

**1.**

(Erdős–Szekeres) Suppose
and ${x}_{1},{x}_{2},\dots ,{x}_{n}$ is a sequence of real numbers. Then this sequence contains a monotonic increasing (decreasing) subsequence of $a+1$ terms or a monotonic decreasing (increasing) subsequence of $b+1$ terms.

$$a,b\in N,n\ge a\xb7b+1$$

More than 85 years have passed since then, and a whole subarea of combinatorics has grown up from the Erdős–Szekeres theorem. Even today we cannot fully appreciate the significance of this theorem, see, for instance, [2,3,4,5,6,7,8].

The main goal of this paper is to describe the complete family of constraints on the lengths of a sequence, its longest increasing subsequence, and its longest decreasing subsequence.

## 2. Results

**Theorem**

**2.**

There exists a sequence T of length $n\ge 1$ containing a longest increasing subsequence of length $x=lis\left(T\right)\ge 1$ and a longest decreasing subsequence of length $y=lds\left(T\right)\ge 1$ if and only if the numbers x, y and n satisfy the following conditions:

$$x\xb7y\ge n$$

$$x+y\le n+1.$$

**Proof.**

If either $x=1$ or $y=1$ the claim is evident.

In what follows, $x>1,y>1$, and $n>1$.

**Necessity**of the condition (1) immediately follows from the theorem of Erdős–Szekeres. Assume that the condition (1) is not satisfied, i.e., $x\xb7y\le n-1$, then, according to the Erdős–Szekeres theorem, the sequence T of length n contains a monotone increasing subsequence of the length $x+1$ or a monotone decreasing subsequence of the length $y+1$, which contradicts the hypothesis of the theorem. The violation of the condition (2) makes impossible the existence of two subsequences with specified lengths, one of which increases, while the other decreases. In fact, these two subsequences can have no more than one element in common; that is, the sum of their lengths should not exceed $n+1$.

**Sufficiency**. Assume that $x\xb7y\ge n$ and $x+y\le n+1$, and build a sequence T of length n, such that $x=lis\left(T\right),y=lds\left(T\right)$. This sequence is built according to the following scheme. We take a sequence of n natural numbers $1,2,\dots ,n$ and divide it into x groups, in such a way that $T=Concatenation({T}_{1},{T}_{2},\dots ,{T}_{x})$ and satisfies the following conditions:

- The numbers in each group are arranged in decreasing order.
- All the numbers of a subsequent group are greater than all the numbers of a preceding group.
- The first group consists of y elements: $y,y-1,y-2,\dots ,1$, which is possible by the condition $y<n$.
- We divide the remaining $n-y$ elements into $x-1$ groups as follows. Let $p=\u230a{\displaystyle \frac{n-y}{x-1}}\u230b$ and $r=(n-y)mod(x-1)$. Note that $p=\u230a{\displaystyle \frac{n-y}{x-1}}\u230b\ge \u230a{\displaystyle \frac{x-1}{x-1}}\u230b=1$ and $0\le r<x-1$. The first r groups represent decreasing subsequences ${T}_{2},\dots ,{T}_{r+1}$ of the length $p+1$:${T}_{2}=\{y+p+1,y+p,y+p-1,\dots ,y+1\}$…${T}_{r+1}=\{y+r(p+1),y+r(p+1)-1,\dots ,y+r(p+1)-p\}$.The last $x-r-1$ groups represent decreasing subsequences ${T}_{r+2},\dots ,{T}_{x}$ of length p. (If $r=0$, then all $x-1$ decreasing subsequences have the length p):${T}_{r+2}=\{y+r(p+1)+p,y+r(p+1)+p-1,\dots ,y+r(p+1)+1\}$,…${T}_{x}=\{n,n-1,n-2,\dots ,n-p+1\}.$

Before passing to the proof of the sufficiency, we prove the following.

**Claim**

**1.**

At the partition of $n-y$ elements into $x-1$ groups satisfying Conditions 1–4, the number of elements in each group does not exceed y.

**Proof.**

It is given that $y+p\xb7(x-1)+r=n$. Then,
in accordance with the condition $x\xb7y\ge n$. Thus

$$y+p\xb7(x-1)+r\le y+(x-1)\xb7y$$

$$p+{\displaystyle \frac{r}{x-1}}\le y.$$

If $r=0$, then all $x-1$ groups are of the same length p and $p\le y$.

If $r>0$, then taking into account that $r<x-1$, and the fact that p and y are positive integers, we conclude with $p+1\le y$, while all the groups are of length p or $p+1$. □

By the above construction and Claim 1, the longest decreasing subsequence in T is the first group and thus has length y, while each longest increasing subsequence is obtained by choosing exactly one element from each of x groups, giving length x. □

**Example**

**1.**

Consider $n=7,x=4,\phantom{\rule{4pt}{0ex}}\phantom{\rule{4pt}{0ex}}\phantom{\rule{4pt}{0ex}}y=3$, and note that the conditions (1) and (2) are satisfied and $p=\u230a{\displaystyle \frac{n-y}{x-1}}\u230b=3$ and $r=1$. By the construction given in the proof,
Clearly, the longest decreasing sequence of T is $(3,2,1)$ and has length $y=3$, and the longest increasing subsequences each have length $x=4$.

$$T=(3,2,1,\phantom{\rule{4pt}{0ex}}\phantom{\rule{4pt}{0ex}}5,4,\phantom{\rule{4pt}{0ex}}\phantom{\rule{4pt}{0ex}}6,\phantom{\rule{4pt}{0ex}}\phantom{\rule{4pt}{0ex}}7).$$

**Remark**

**1.**

There are other methods of building sequences satisfying the conditions (1) and (2). For instance, by choosing the last group to be the longest decreasing subsequence rather than the first, or, say, by first creating the group consisting of x increasing integers $n-x+1,n-x+2,\dots ,n$, and then adding $y-1$ increasing groups of nearly equal size so that all the numbers in each group is smaller than the numbers in any previous group.

## Author Contributions

Conceptualization, E.J.I.; Investigation, V.E.L.; Writing–original draft preparation, V.E.L.; Writing–review and editing, E.J.I.

## Funding

This research received no external funding.

## Acknowledgments

We would like to thank the reviewers for their comments, which helped us to improve the presentation of the paper.

## Conflicts of Interest

The authors declare no conflict of interest.

## References

- Erdős, P.; Szekeres, G. A combinatorial problem in geometry. Compositio Mathematica
**1935**, 2, 463–470. [Google Scholar] - Bukh, B.; Sevekari, A. Linear orderings of combinatorial cubes. arXiv
**2019**, arXiv:1906.118669. [Google Scholar] - Deorowich, S. On Some Variants of the Longest Increasing Subsequence Problem. Theor. Appl. Inform.
**2009**, 21, 135–148. [Google Scholar] - Gottlieb, E.; Sheard, M. Erdős-Szekeres results for set partitions. Integers 15
**2015**, 8, A29. [Google Scholar] - Romik, D. The Surprising Mathematics of Longest Increasing Subsequences. In Institute of Mathematical Statistics Textbooks, 4; Cambridge University Press: New York, NY, USA, 2015; p. xi+353. [Google Scholar]
- Stanley, R.P. Increasing and decreasing subsequences and their variants. Int. Congr. Math.
**2007**, I, 545–549. [Google Scholar] - Steele, J.M. Variations on the monotone subsequence theme of Erdős and Szekeres. In IMA Volumes in Mathematics and Its Applications; Springer: New York, NY, USA, 1995; Volume 72, pp. 111–131. [Google Scholar]
- Xu, X.; Liang, M.; Luo, H. Ramsey Theory: Unsolved Problems and Results; De Gruyter/University of Science and Technology of China Press: Berlin, Germany; Boston, MA, USA, 2018; p. 190. [Google Scholar]

© 2019 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (http://creativecommons.org/licenses/by/4.0/).