ArticleslgStudy

computer science

Run of a sequence

Run of a sequence is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Run of a sequence rather than just read about it. In short: 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.

Key takeaways

  • Run of a sequence belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Run of a sequence to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Run of a sequence from memory before moving on to harder problems.

Reference excerpt

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 X = ⟨ x 1 , … , x n ⟩ {\displaystyle X=\langle x_{1},\dots ,x_{n}\rangle } be a sequence of elements from a totally ordered set. A run of X {\displaystyle X} is a maximal increasing sequence ⟨ x i , x i + 1 , … , x j − 1 , x j ⟩ {\displaystyle \langle x_{i},x_{i+1},\dots ,x_{j-1},x_{j}\rangle } . That is, x i − 1 > x i {\displaystyle x_{i-1}>x_{i}} and x j > x j + 1 {\displaystyle x_{j}>x_{j+1}} assuming that x i − 1 {\displaystyle x_{i-1}} and x j + 1 {\displaystyle x_{j+1}} exists. For example, if n {\displaystyle n} is a natural number, the sequence ⟨ n + 1 , n + 2 , … , 2 n , 1 , 2 , … , n ⟩ {\displaystyle \langle n+1,n+2,\dots ,2n,1,2,\dots ,n\rangle } has the two runs ⟨ n + 1 , … , 2 n ⟩ {\displaystyle \langle n+1,\dots ,2n\rangle } and ⟨ 1 , … , n ⟩ {\displaystyle \langle 1,\dots ,n\rangle } . Let r u n s ( X ) {\displaystyle {\mathtt {runs}}(X)} be defined as the number of positions i {\displaystyle i} such that 1 ≤ i < n {\displaystyle 1\leq i<n} and x i + 1 < x i {\displaystyle x_{i+1}<x_{i}} . It is equivalently defined as the number of runs of X {\displaystyle X} minus one. This definition ensure that r u n s ( ⟨ 1 , 2 , … , n ⟩ ) = 0 {\displaystyle {\mathtt {runs}}(\langle 1,2,\dots ,n\rangle )=0} , that is, the r u n s ( X ) = 0 {\displaystyle {\mathtt {runs}}(X)=0} if, and only if, the sequence X {\displaystyle X} is sorted. As another example, r u n s ( ⟨ n , n − 1 , … , 1 ⟩ ) = n − 1 {\displaystyle {\mathtt {runs}}(\langle n,n-1,\dots ,1\rangle )=n-1} and r u n s ( ⟨ 2 , 1 , 4 , 3 , … , 2 n , 2 n − 1 ⟩ ) = n {\displaystyle {\mathtt {runs}}(\langle 2,1,4,3,\dots ,2n,2n-1\rangle )=n} .

Sorting sequences with a low number of runs The function r u n s {\displaystyle {\mathtt {runs}}} is a measure of presortedness. The natural merge sort is r u n s {\displaystyle {\mathtt {runs}}} -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 runs can be sorted 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. doi:10.1109/TC.1985.5009382.

Worked examples

Example 1 — a first encounter with Run of a sequence

Start with the simplest possible case. Write down what Run of a sequence claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Run of a sequence before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Run of a sequence ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Run of a sequence

In research
Run of a sequence appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Run of a sequence in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Run of a sequence is common in secondary-school and first-year university syllabi. It links to neighbouring topics Sorting algorithms, so understanding it makes those chapters shorter.
In everyday life
Look for Run of a sequence outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.

Affiliate

Preply — study more efficiently by working with a personal tutor. 50% off.

How to study Run of a sequence in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Run of a sequence means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Run of a sequence out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Run of a sequence in simple terms?

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.

Why does Run of a sequence matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Run of a sequence?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Run of a sequence.

Tags

  • Sorting algorithms

Keep exploring