Why it matters
Randomization avoids worst-case input attacks. Understanding shapes robust sorting.
Advertisement
The architecture
Random pivot from range.
Partition around pivot.
Recurse both sides.
Advertisement
How it works end to end
Random pivot: uniform in range.
Expected comparisons: 2n ln n.
Worst case: exponentially rare.
In-place partition (Lomuto or Hoare).