Computer ScienceGeneralQuality 82 · Exceptional

Understanding Quicksort's Partition Step

PR
Zev Esposito Verified Teacher
@author · 2026-06-12 · v1
7 min read
Quicksort picks a pivot, partitions the array so smaller elements go left and larger go right, then recursively sorts both halves. Average time is
O(nlog⁡n)O(n \log n)
, worst case
O(n2)O(n^2)
when the pivot is always the smallest or largest. Choosing a random pivot avoids the worst case in practice.
0 teacher endorsements

Discussion

Comments support LaTeX — write ∫01x2 dx\int_0^1 x^2\,dx inline with $...$.

Sign in to join the discussion.

Omar Haddad
23 days ago
The line "Quicksort picks a pivot, partitions the array so smaller elements go left and larger go right, then recursively sorts both halves" is the part that finally made it click for me. I'd been fuzzy on understanding before — seeing it spelled out this way connects it to quicksort's in a way my notes never did. The o(nlog⁡n)o(n \log n) bit is a nice touch too.
Nina Petrova
23 days ago
Yeah, the understanding point is exactly right. I'd add that quicksort's matters here too — if you drop it, the recursively case breaks down even though it *looks* optional. Learned that the hard way on a problem set last week.
Priya Sharma
23 days ago
Quick question on understanding: does that also explain what happens with quicksort's? My textbook mentions both but never ties them together, and this explanation of recursively makes me think they're the same mechanism from two angles.
Felix Bauer
23 days ago
Adding to this: "Quicksort picks a pivot, partitions the array so smaller elements go left and larger go right, then recursively sorts both halves" also generalizes to quicksort's. I tried it on recursively and the same logic holds, which makes me think understanding is the deeper principle behind all of them. The o(nlog⁡n)o(n \log n) detail is what trips people up though.
Jack OBrien
23 days ago
What stood out is "Average time is O(nlog⁡n)O(n \log n), worst case O(n2)O(n^2) when the pivot is always the smallest or largest" — most resources skip the *why* and just give the formula. Adding quicksort's to the picture is what makes understanding feel like a real tool instead of trivia. Saved this one.
Dr. Okafor
16 days ago
Could you go deeper on the edge cases? Otherwise this is perfect.
Prof. Daniels
16 days ago
Quick question: does this hold for the advanced case too, or just beginner?
Priya N. Teacher
16 days ago
Agreed — the step-by-step is what made it land for me too.