Longest alternating subsequence
From Wikipedia, the free encyclopedia
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 is a sequence of distinct real numbers, then the subsequence is alternating[1] (or zigzag or down-up) if
Similarly, is reverse alternating (or up-down) if
Note that every sequence of length 1 is both alternating and reverse alternating.
Let denote the length (number of terms) of the longest alternating subsequence of . For example, if we consider some of the permutations of the integers 1,2,3,4,5, we have that
- , because there are alternating subsequences of length 2, (for example 5,4 or 5,2 or 3,1), but all subsequences of length 3 are not alternating;
- , because all subsequences of length 2 are not alternating. (actually, they are reverse alternating);
- because 5,1,3,2 and 5,1,4,2 and 5,3,4,2 are all alternating, and there is no alternating subsequence with more elements;
- because 4,3,5,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 elements can be found in time . 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 is a random permutation of the integers and , then it is possible to show[3][4][5] that
Moreover, as , the random variable , 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 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 of independent random variables with common continuous distribution , 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 .[6]
As , the optimal number of online alternating selections appropriately centered and scaled converges to a normal distribution.[7]
See also
- Alternating permutation
- Permutation pattern and pattern avoidance
- Counting local maxima and/or local minima in a given sequence
- Turning point tests for testing statistical independence of observations
- Number of alternating runs
- Longest increasing subsequence
- Longest common subsequence
References
Wikiwand - on
Seamless Wikipedia browsing. On steroids.