Run of a sequence

From Wikipedia, the free encyclopedia

In computer science, a run of a sequence is a longest non-decreasing range of the sequence. The number of runs of a sequence is the number of increasing subsequences of the sequence. This is a , and in particular measures how many sequences must be merged to sort a sequence.

Definition[]

Let be a sequence. A run of is a maximal increasing sequence . That is, and [clarification needed] assuming that and exists. For example, in , the two runs are and .

Let be defined as the number of such that . It is equivalently defined as the number of runs minus one. This definition ensure that , that is, the function returns 0 on sorted list and only on them. As another example and .

Sorting sequences with a low number of runs[]

The function Runs is a . The natural merge sort, is -optimal. That is, if it is known that a sequence has a low number of runs, it can be efficiently sorted using the natural merge sort.

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 run can be merged efficiently by first reversing the decreasing runs and then using a natural merge sort.

References[]

  • Powers, David M. W.; McMahon, Graham B. (1983). "A compendium of interesting prolog programs". DCS Technical Report 8313 (Report). Department of Computer Science, University of New South Wales.
  • Mannila, H (1985). "Measures of Presortedness and Optimal Sorting Algorithms". IEEE Trans. Comput. (C-34): 318–325.
Retrieved from ""