run of a sequence
{{more footnotes|date=June 2021}}
{{More citations needed|date=April 2021}}
In computer science, a run of a sequence is a non-decreasing range of the sequence that cannot be extended. The number of runs of a sequence is the number of increasing subsequences of the sequence. This is a measure of presortedness, and in particular measures how many subsequences must be merged to sort a sequence.
Definition
Let be a sequence of elements from a totally ordered set. A run of is a maximal increasing sequence . That is, and {{clarify|reason=In order to match with definition of "increasing sequence" and with that of Runs, ≥ should be used instead of >.|date=May 2021}} assuming that and exists. For example, if is a natural number, the sequence has the two runs and .
Let be defined as the number of positions such that
Sorting sequences with a low number of runs
The function
Long runs
A long run is defined similarly to a run, except that the sequence can be either non-decreasing or non-increasing. The number of long runs is not a measure of presortedness. A sequence with a small number of long runs can be sorted efficiently by first reversing the decreasing runs and then using a natural merge sort.
References
- {{cite report |last1=Powers |first1=David M. W. |last2=McMahon |first2=Graham B. |date=1983 |section=A compendium of interesting prolog programs |title=DCS Technical Report 8313 |publisher=Department of Computer Science, University of New South Wales}}
- {{cite journal |last1=Mannila |first1=H |title=Measures of Presortedness and Optimal Sorting Algorithms |journal=IEEE Trans. Comput. |date=1985 |issue=C-34 |pages=318–325|doi=10.1109/TC.1985.5009382 }}