Practice Discrete Math

Algorithms / Sorting Selection Order Statistics

Least You Need to Know: Sorting, Selection, and Order Statistics

Sorting, selection, and order statistics are related but not identical tasks. Sorting asks for the entire order, selection asks for one rank such as the median or kth element, and top-k variants often need only a partial order. Choosing the right task often changes the best algorithm and the runtime target.

The least you need to know

Key notation

kth smallest the element with rank `k` in sorted order
order statistic an element identified by rank rather than value
top-k the `k` largest or smallest items under the objective

Tiny worked example

  • If a prompt asks for only the median, fully sorting the array is not conceptually necessary.
  • A selection algorithm can search for the median rank directly.
  • If the prompt asks for the entire order, then sorting is the correct target.
  • If the prompt asks for the largest `k` streaming values, a heap often becomes the right data structure.

Common mistakes

How to recognize this kind of problem

Start practice