In
computer science
Computer science is the study of computation, automation, and information. Computer science spans theoretical disciplines (such as algorithms, theory of computation, information theory, and automation) to Applied science, practical discipli ...
, 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
Measure may refer to:
* Measurement, the assignment of a number to a characteristic of an object or event
Law
* Ballot measure, proposed legislation in the United States
* Church of England Measure, legislation of the Church of England
* Mea ...
, 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
In mathematics, a total or linear order is a partial order in which any two elements are comparable. That is, a total order is a binary relation \leq on some set X, which satisfies the following for all a, b and c in X:
# a \leq a ( reflexive) ...
. A run of
is a maximal
increasing sequence . That is,
and
assuming that
and
exists. For example, if
is a
natural number
In mathematics, the natural numbers are those numbers used for counting (as in "there are ''six'' coins on the table") and ordering (as in "this is the ''third'' largest city in the country").
Numbers used for counting are called ''Cardinal n ...
, the sequence
has the two runs
and
.
Let
be defined as the number of positions
such that