Maths WorkshopMaths problems with full solutions
Exercise 1809Combinatorics › Pigeonhole principleOlympiadAdded 3 Nov 2026

Increasing or decreasing subsequence

#pigeonhole#Erdős–Szekeres#subsequence

Statement

Show that any sequence of n2+1n^2+1 distinct real numbers contains an increasing subsequence of length n+1n+1 or a decreasing subsequence of length n+1n+1.

Hint

Assign to each element the pair (inc,dec)(\text{inc},\text{dec}) where inc is the length of the longest increasing subsequence ending there, dec similarly for decreasing.

Show solutionHide solution

Solution

Pairs. For each element aka_k, let inck\text{inc}_k be the length of the longest increasing subsequence ending at kk, and deck\text{dec}_k similarly for decreasing.

Distinctness. If i<ji<j and ai<aja_i<a_j, then incj>inci\text{inc}_j>\text{inc}_i. If ai>aja_i>a_j, then decj>deci\text{dec}_j>\text{dec}_i. So all pairs (inck,deck)(\text{inc}_k,\text{dec}_k) are distinct.

Pigeonhole. Each coordinate is at most nn if no inc or dec subsequence of length n+1n+1 exists. So at most n2n^2 distinct pairs. But there are n2+1n^2+1 elements. Contradiction.

Conclusion. Either an increasing or a decreasing subsequence of length n+1n+1 exists. (Erdős–Szekeres theorem.)