Practice Discrete Math

Algorithms / Quickselect Kth

Least You Need to Know: Quickselect, kth Element, and One-Sided Recursion

Quickselect uses partitioning to find a target rank without fully sorting the array. Its main idea is that once the pivot rank is known, only one side can still contain the kth element. That one-sided recursion is why quickselect is typically faster than full quicksort when only a single rank is needed.

The least you need to know

Key notation

k target rank or target index after normalization
pivot index rank position determined by partition
one-sided recursion only one recursive subproblem remains relevant

Tiny worked example

  • Partition the array around a pivot.
  • Let `p` be the pivot's final rank.
  • If `p = k`, return the pivot.
  • If `k < p`, recurse left; if `k > p`, recurse right with the adjusted target rank.

Common mistakes

How to recognize this kind of problem

Start practice