Longest alternating subsequence
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 x = { x 1 , x 2 , … , x n } {\displaystyle \mathbf {x} =\{x_{1},x_{2},\ldots ,x_{n}\}} is a sequence of distinct real numbers, then the subsequence { x i 1 , x i 2 , … , x i k } {\displaystyle \{x_{i_{1}},x_{i_{2}},\ldots ,x_{i_{k}}\}} is alternating (or zigzag or down-up) if x i 1 > x i 2 < x i 3 > ⋯ x i k and 1 ≤ i 1 < i 2 < ⋯ < i k ≤ n .
Source: Wikipedia — Longest alternating subsequence (CC BY-SA 4.0)