Coding & data structures · Sorting and selection — order, and the parts of it you actually need

Partitioning: quickselect, and the k-th without the order

One pass can put a pivot in its final position and split everything else into "smaller" and "larger" — and that single primitive gives you the k-th smallest element in expected linear time, sorts an array with three-way splits, solves the three-colour problem in one scan, and explains why every production quicksort is really three algorithms glued together.

28 min read Full lesson in the app Patterns: Lomuto partition, Hoare partition, quickselect, three-way partition, randomised pivot

What you'll be able to do

Before this: merge-and-divide-and-conquer, two-pointers

The rest of this lesson is in the app

One pass can put a pivot in its final position and split everything else into "smaller" and "larger" — and that single primitive gives you the k-th smallest element in expected linear time, sorts an array with three-way splits, solves the three-colour problem in one scan, and explains why every production quicksort is really three algorithms glued together. This walkthrough runs about 28 minutes, with runnable code you can edit and re-run as you read.

Continue in ChannelPulse

The first module of every track is free to read on the web — see what's open in Coding & data structures.