Quickselect
Find the k-th smallest element in O(n) on average — partition like quicksort, then recurse into one side only.
This topic is part of Pro.
Free covers the C and Python courses, the first three DSA topics, the opening system design lessons and the beginner AI lessons, all with the full coach. Pro opens the rest of the library in the FollowtheDamnCode app.
What is in it
- 1Partitioning around a pivotRearrange so smaller values are left of the pivot and larger ones right — the pivot lands in its final sorted position. Pro
- 2The quickselect algorithmPartition, compare the pivot's index with k, and continue into one side — expected 2n work. Pro
- 3Choosing a selection methodSort, heap, quickselect, or counting — matched to the size of k, the data, and whether it's a stream. Pro