ArticleslgStudy

computer science

Selection algorithm

Selection algorithm 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 Selection algorithm rather than just read about it. In short: In computer science, a selection algorithm is an algorithm for finding the k {\displaystyle k} th smallest value in a collection of orderable values, such as numbers. The value that it finds is called the k {\displaystyle k} th order statistic.

Selection algorithm — main illustration
Selection algorithm — illustration

Key takeaways

  • Selection algorithm 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 Selection algorithm to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Selection algorithm from memory before moving on to harder problems.

Reference excerpt

In computer science, a selection algorithm is an algorithm for finding the k {\displaystyle k} th smallest value in a collection of orderable values, such as numbers. The value that it finds is called the k {\displaystyle k} th order statistic. Selection includes as special cases the problems of finding the minimum, median, and maximum element in the collection. Selection algorithms include quickselect, and the median of medians algorithm. When applied to a collection of n {\displaystyle n} values, these algorithms take linear time, O ( n ) {\displaystyle O(n)} as expressed using big O notation. For data that is already structured, faster algorithms may be possible; as an extreme case, selection in an already-sorted array takes time O ( 1 ) {\displaystyle O(1)} .

Problem statement An algorithm for the selection problem takes as input a collection of values, and a number k {\displaystyle k} . It outputs the k {\displaystyle k} th smallest of these values, or, in some versions of the problem, a collection of the k {\displaystyle k} smallest values. The latter version can be further specified as some versions output the k smallest values in sorted order, while others return them in arbitrary order. For this to be well-defined, it should be possible to sort the values into an order from smallest to largest; for instance, they may be integers, floating-point numbers, or some other kind of object with a numeric key. However, they are not assumed to have been already sorted. Often, selection algorithms are restricted to a comparison-based model of computation, as in comparison sort algorithms, where the algorithm has access to a comparison operation that can determine the relative ordering of any two values, but may not perform any other kind of arithmetic operations on these values. To simplify the problem, some works on this problem assume that the values are all distinct from each other, or that some consistent tie-breaking method has been used to assign an ordering to pairs of items with the same value as each other. Another variation in the problem definition concerns the numbering of the ordered values: is the smallest value obtained by setting k = 0 {\displaystyle k=0} , as in zero-based numbering of arrays, or is it obtained by setting k = 1 {\displaystyle k=1} , following the usual English-language conventions for the smallest, second-smallest, etc.? This article follows the conventions used by Cormen et al., according to which all values are distinct and the minimum value is obtained from k = 1 {\displaystyle k=1} . With these conventions, the maximum value, among a collection of n {\displaystyle n} values, is obtained by setting k = n {\displaystyle k=n} . When n {\displaystyle n} is an odd number, the median of the collection is obtained by setting k = ( n + 1 ) / 2 {\displaystyle k=(n+1)/2} . When n {\displaystyle n} is even, there are two choices for the median, obtained by rounding this choice of k {\displaystyle k} down or up, respectively: the lower median with k = n / 2 {\displaystyle k=n/2} and the upper median with k = n / 2 + 1 {\displaystyle k=n/2+1} .

Algorithms

Sorting and heapselect As a baseline algorithm, selection of the k {\displaystyle k} th smallest value in a collection of values can be performed by the following two steps:

… excerpt ends here. Continue reading the full article.

Illustrations

Selection algorithm: Finding the median of five values using six comparisons. Each step shows the comparisons to be performed next as yellow line segments, and a Hasse diagram of the order relations found so far (with smaller=lower and larger=higher) as blue line segments. The red elements have already been found to be greater than  three others and so cannot be the median. The larger of the two elements in the final comparison is the median.
Finding the median of five values using six comparisons. Each step shows the comparisons to be performed next as yellow line segments, and a Hasse diagram of the order relations found so far (with smaller=lower and larger=higher) as blue line segments. The red elements have already been found to be greater than three others and so cannot be the median. The larger of the two elements in the final comparison is the median.

Worked examples

Example 1 — a first encounter with Selection algorithm

Start with the simplest possible case. Write down what Selection algorithm 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 Selection algorithm 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 Selection algorithm 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 Selection algorithm

In research
Selection algorithm 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 Selection algorithm 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
Selection algorithm is common in secondary-school and first-year university syllabi. It links to neighbouring topics Selection algorithms, so understanding it makes those chapters shorter.
In everyday life
Look for Selection algorithm 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.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Selection algorithm” →

Affiliate

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

How to study Selection algorithm in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Selection algorithm 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 Selection algorithm out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Selection algorithm in simple terms?

In computer science, a selection algorithm is an algorithm for finding the k {\displaystyle k} th smallest value in a collection of orderable values, such as numbers. The value that it finds is called the k {\displaystyle k} th order statistic.

Why does Selection algorithm 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 Selection algorithm?

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 Selection algorithm.

Tags

  • Selection algorithms

Keep exploring