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.
What you'll be able to do
- Implement Lomuto and Hoare partitioning and state the loop invariant each maintains
- Derive quickselect's expected O(n) from the geometric series, and explain what randomising the pivot buys
- Build the O(n^2) worst case deliberately, and measure how a random or median-of-three pivot removes it
- Use three-way partitioning for the three-colour problem and for arrays with many duplicate keys
- Explain how a production sort combines quicksort, insertion sort, and heap sort, and why
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 ChannelPulseThe first module of every track is free to read on the web — see what's open in Coding & data structures.