Longest alternating subsequence

From HandWiki

In combinatorial mathematics, probability, and computer science, in the longest alternating subsequence problem, one wants to find a subsequence of a given sequence in which the elements are in alternating order, and in which the sequence is as long as possible. Formally, if [math]\displaystyle{ \mathbf{x} = \{x_1, x_2, \ldots, x_n\} }[/math] is a sequence of distinct real numbers, then the subsequence [math]\displaystyle{ \{x_{i_1}, x_{i_2}, \ldots, x_{i_k}\} }[/math] is alternating[1] (or zigzag or down-up) if

[math]\displaystyle{ x_{i_1} \gt x_{i_2} \lt x_{i_3} \gt \cdots x_{i_k}\qquad \text{and} \qquad 1\leq i_1 \lt i_2 \lt \cdots \lt i_k \leq n. }[/math]

Similarly, [math]\displaystyle{ \mathbf{x} }[/math] is reverse alternating (or up-down) if

[math]\displaystyle{ x_{i_1} \lt x_{i_2} \gt x_{i_3} \lt \cdots x_{i_k}\qquad \text{and} \qquad 1\leq i_1 \lt i_2 \lt \cdots \lt i_k \leq n. }[/math]

Let [math]\displaystyle{ {\rm as}_n(\mathbf{x}) }[/math] denote the length (number of terms) of the longest alternating subsequence of [math]\displaystyle{ \mathbf{x} }[/math]. For example, if we consider some of the permutations of the integers 1,2,3,4,5, we have that

  • [math]\displaystyle{ {\rm as}_5(1,2,3,4,5) = 2 }[/math]; because any sequence of 2 distinct digits are (by definition) alternating. (for example 1,2 or 1,4 or 3,5);
  • [math]\displaystyle{ {\rm as}_5(1,5,3,2,4) = 4, }[/math] because 1,5,3,4 and 1,5,2,4 and 1,3,2,4 are all alternating, and there is no alternating subsequence with more elements;
  • [math]\displaystyle{ {\rm as}_5(5,3,4,1,2) = 5, }[/math] because 5,3,4,1,2 is itself alternating.

Efficient algorithms

In a sequence of distinct elements, the subsequence of local extrema (elements larger than both adjacent elements, or smaller than both adjacent elements) forms a canonical longest alternating sequence.[2] As a consequence, the longest alternating subsequence of a sequence of [math]\displaystyle{ n }[/math] elements can be found in time [math]\displaystyle{ O(n) }[/math]. In sequences that allow repetitions, the same method can be applied after first replacing each run of repeated elements by a single copy of that element.[citation needed]

Distributional results

If [math]\displaystyle{ \mathbf{x} }[/math] is a random permutation of the integers [math]\displaystyle{ 1,2,\ldots,n }[/math] and [math]\displaystyle{ A_n \equiv {\rm as}_n(\mathbf{x}) }[/math], then it is possible to show[3][4][5] that

[math]\displaystyle{ E[A_n] = \frac{2 n}{3} + \frac{1}{6} \qquad \text{and} \qquad \operatorname{Var}[A_n] = \frac{8 n}{45} - \frac{13}{180}. }[/math]

Moreover, as [math]\displaystyle{ n \rightarrow \infty }[/math], the random variable [math]\displaystyle{ A_n }[/math], appropriately centered and scaled, converges to a standard normal distribution.

Online algorithms

The longest alternating subsequence problem has also been studied in the setting of online algorithms, in which the elements of [math]\displaystyle{ \mathbf{x} }[/math] are presented in an online fashion, and a decision maker needs to decide whether to include or exclude each element at the time it is first presented, without any knowledge of the elements that will be presented in the future, and without the possibility of recalling on preceding observations.

Given a sequence [math]\displaystyle{ X_1, X_2, \ldots, X_n }[/math] of independent random variables with common continuous distribution [math]\displaystyle{ F }[/math], it is possible to construct a selection procedure that maximizes the expected number of alternating selections. Such expected values can be tightly estimated, and it equals [math]\displaystyle{ (2-\sqrt{2})n + O(1) }[/math].[6]

As [math]\displaystyle{ n \rightarrow \infty }[/math], the optimal number of online alternating selections appropriately centered and scaled converges to a normal distribution.[7]

See also

References

  1. Stanley, Richard P. (2011), Enumerative Combinatorics, Volume I, second edition, Cambridge University Press 
  2. Romik, Dan (2011), "Local extrema in random permutations and the structure of longest alternating subsequences", 23rd International Conference on Formal Power Series and Algebraic Combinatorics (FPSAC 2011), Discrete Math. Theor. Comput. Sci. Proc., AO, Assoc. Discrete Math. Theor. Comput. Sci., Nancy, pp. 825–834, https://dmtcs.episciences.org/2956 
  3. Widom, Harold (2006), "On the limiting distribution for the length of the longest alternating sequence in a random permutation", Electron. J. Combin. 13: Research Paper 25, 7, http://www.combinatorics.org/Volume_13/Abstracts/v13i1r25.html 
  4. "Longest alternating subsequences of permutations", Michigan Math. J. 57: 675–687, 2008, doi:10.1307/mmj/1220879431 
  5. Houdré, Christian; Restrepo, Ricardo (2010), "A probabilistic approach to the asymptotics of the length of the longest alternating subsequence", Electron. J. Combin. 17: Research Paper 168, 19, http://www.combinatorics.org/Volume_17/Abstracts/v17i1r168.html 
  6. Arlotto, Alessandro; Chen, Robert W. (2011), "Online selection of alternating subsequences from a random sample", J. Appl. Probab. 48 (4): 1114–1132, doi:10.1239/jap/1324046022 
  7. Arlotto, Alessandro (2014), "Optimal online selection of an alternating subsequence: a central limit theorem", Adv. Appl. Probab. 46 (2): 536–559, doi:10.1239/aap/1401369706, https://repository.upenn.edu/fnce_papers/57