On the longest k-alternating subsequence

We show that the longest k-alternating substring of a random permutation has length asymptotic to 2 (n-k) / 3.

Let π be a uniformly chosen random permutation in S n and let L n,k = L n,k (π) denote the length of the longest k-alternating subsequence of π. Armstrong [Arm] made the following conjecture, and verified it via exact computation for certain small values of n and k.
Conjecture 1 (Armstrong, 2014). For all n ≥ 2 and k ∈ {1, . . . , n − 1}, we have: In this note we use probabilistic methods to prove the following asymptotic version of the conjecture.
This is proved via the related notion of x-alternation for x ∈ (0, 1), cf. [ACSS]. A vector Let µ denote product Lebesgue measure on [0, 1] n . Let Ψ be the map taking y ∈ [0, 1] n to the element π ∈ S n defined by π(j) = #{i ≤ n : y i ≤ y j } .
A well known fact attributed to Rényi (see [Res]) says that if y has law µ then Ψ(y) is uniformly distributed on S n . Let L n,x (y) denote the length of the longest x-alternating subsequence of y. No confusion can result between this and the definition of L n,k above, provided that we restrict x to [0, 1) and k to positive integral values. Theorem 2 is a consequence of the following results.
Lemma 3. Let Z be a binomial random variable with parameters n and 1 − x. Then In other words, the law of the longest x-alternating subsequence may be exactly simulated by choosing Z ∼ Bin(n, 1 − x), choosing π uniformly on S Z , and taking the longest alternating subsequence of π.
Lemma 5. Let y be random with law µ. Denote Then the following two implications hold with probability 1 − o(1) as n → ∞.
Proof of Theorem 2. The theorem follows from Corollary 4 and Lemma 5. Taking expectations in (6) we find that Corollary 4 then sandwiches EL n,k between two quantities both of which are asymptotic to (2/3)(n − k): where j ∈ {1, 2}.

Proof of Lemma 5
LetF denote the empirical distribution of the values of y:F (t) := n −1 j 1 y j ≤t . If (i) fails then there are i, j ≤ n with |y i − y j | ≥ x 2 and |π(i) − π(j)| < k, where π = Ψ(y). Letting t denote the minimum of y i and y j , this implies thatF (t + x 2 ) −F (t) < k/n. Becausê for some s ∈ (0, 1). In either case, But √ n sup s∈[0,1] |F (s) − s| converges in distribution to the Kolmogorov-Smirnov statistic (the law of the maximum of a Brownian bridge). Because n −1/3 /n −1/2 → ∞, this implies that P sup proving the lemma.

Proof of Lemma 3
We begin with another well known fact, attributed to M. Bóna in [S1]: for π ∈ S n , one alternating subsequence (π(i) : i ∈ A) of maximal length is obtained by selecting i ∈ A if and only if i is a peak or a valley, that is, π(i−1) < π(i) > π(i+1) or π(i−1) > i < π(i+1), except that we select 1 if and only if π(1) < π(2) (see the proof in [HR,§2]). This generalizes to k-alternating subsequences via the following algorithm which selects the index set A of a k-alternating subsequence of a given permutation s ∈ S n . In other words, when it is time for an upward step, if the next value goes up but not by k ignore it, if it goes up by k or more, accept it as the new provisional value, and if it goes down, replace the old provisional down step by the new value. The pointer i points to the provisional value at any time, and when a new provisional value is accepted (rather than replacing and old one), the old one becomes permanent.
Lemma 6. Let s ∈ S n . Then the subsequence (s(i) : i ∈ A) defined by the foregoing algorithm is a k-alternating subsequence of maximal length.
Proof: Regarding s as a word of length n, let s ′ denote the word of length n − 1 obtained by removing the initial element of s and let s ′′ denote the word of length n − 1 obtained by removing the second element of s. Let L * n,k denote the length of the longest k-alternating sequence beginning with a down step instead of an up step. We claim that s(1) < s(2) < s(1) + k ⇒ L n,k (s) = L n,k (s ′′ ) The first holds because we can't use both s(1) and s(2) and starting with s 1 dominates starting with s(2). The second holds because again we can't use both and this time starting from s 2 dominates starting from s(1). The last is true for the following reason. The LHS cannot be more than the RHS because any k-alternating subsequence restricts to a reverse k-alternating sequence of s ′ upon removal of its first element (here the inequalities in the definition of alternating sequence are reversed, not the word itself). On the other hand, if w is a reverse k-alternating subsequence of s ′ , then there are two cases. If the first element w(1) is at least s(2), we can prepend s(1) and obtain a k-alternating subsequence of s longer by one. Similarly, if the first element in w is less than s(2), we can replace w(1) by s(2) and then prepend s(1). This proves the claim. The lemma now follows by induction.
Replacing k-alternation by x-alternation, an identical argument shows that greedy provisional acceptance will also identify an x-alternating subsequence of y having maximal length. Next, we adjust the bookkeeping slightly as follows. The way the algorithm is written, the first element y 1 begins in a state of provisional acceptance. When y 1 > 1 − x, it is doomed eventually to be replaced, so instead of provisionally accepting it, we reject each initial value until we see a value that is at most 1 − x. This yields the following easy lemma.
Lemma 7. Conditional on y 1 , . . . , y j , the probability of rejecting y j+1 is always precisely x.
Proof: If no value has yet been provisionally accepted, then by rule we reject precisely those values above 1 − x. On the other hand, if any value has been provisionally accepted, it is easy to check inductively that when the state is "up", the provisional value y is at most 1 − x, and the rejection interval for the new value, [y, y + x) is entirely within [0, 1] and has length x. Similarly, when the state is "down", the provisionally accepted value is at least x and the rejection interval (y − x, y] again has length x.
Let A ⊆ {1, . . . , n} be the subset of indices i for which y i was at least provisionally accepted. The previous lemma shows that A has the distribution of a set selected by independent coin flips with success probability 1 − x.
Lemma 8. Let j 1 < j 2 < · · · < j r enumerate the set A. Let z i := y j i when y j i was provisionally accepted initially or after a down step and let z i := y j i − x when y i was provisionally accepted after an up step. Then z is a collection of independent variables uniform on [0, 1 − x] and is independent of A.
Proof: Condition on the y 1 , . . . , y j . We know that P(j + 1 ∈ A) = 1 − x. We therefore need to show that conditional on j + 1 ∈ A, and on y 1 , . . . y j , the value z i+1 is uniform on [0, 1 − x] where i is the cardinality of A ∩ {1, . . . , j}. When i = 0 we are in the initial phase and the result is obvious. If not, suppose first that the state is "up". Then z i ≤ 1 − x and the values of y j+1 for which provisional acceptance will occur are the union of two intervals [0, z i ] ∪ [z i + x, 1]. If y j+1 lies in the upper of these two intervals, it will be provisionally accepted after an up step while if it is in the lower interval it will be provisionally accepted replacing a previous down step value. Thus the two intervals together will map to the single interval [0, 1 − x]. Similarly, supposing instead that the state is "down", provisional acceptance will occur in [0, z i − x] ∪ [z i , 1]; z i+1 will be y j+1 − x in the upper interval and y j+1 in the lower interval, and again we see that z i+1 is uniform on [0, 1 − x].
Proof of Lemma 3: Let z be as in Lemma 8. By Lemma 6, the quantity L n,x (y) is equal to L |z|,0 (z). By Lemma 8, the joint distribution of |z|, z 1 − x is the product measure Bin(n, 1 − x) × µ. The permutation associated with z is the same as that associated with the dilation z/(1 − x), whence the conditional distribution of Ψ(z) given |z| is uniform on S |z| , which is enough fo prove the lemma.

Final remarks
The maximum of (1 − x)(2 + 5x) on [0, 1] occurs at x = 3/10. Consequently the variance of the length of the longest x-alternating sequence is maximized not at ordinary alternating sequences (x = 0) but at 0.3-alternating sequences.