LOGBOOK

HELP

Quiz Entry - updated: 2026.12.02

Quick-sort counts as an in-place sort, yet partitioning into new lists $L$, $E$ and $G$ needs extra memory. How does quick-sort partition inside the array?

Take the last element as pivot and move two indices towards each other: the left one stops at an element $\ge$ the pivot, the right one at an element $\le$ the pivot; swap those two and carry on. When the indices have crossed, swap the pivot into the left index's position: smaller elements end up to its left, larger ones to its right.

In-place partition of 85 24 63 45 17 31 96 50 around 50: two swaps, then the pivot moves into position 4

* Each swap fixes two misplaced elements at once. *

Trace with 85 24 63 45 17 31 96 50 and the pivot 50:

  1. The left index stops at 85, the right one at 31: swap, giving 31 24 63 45 17 85 96 50.
  2. The left index stops at 63, the right one at 17: swap, giving 31 24 17 45 63 85 96 50.
  3. The left index moves past 45 and stops at 63, which is beyond the right index: the scans have crossed.
  4. Swap 63 with the pivot: 31 24 17 45, then 50, then 85 96 63.

The recursion then continues on index ranges of the same array (positions 0 to 3 and 5 to 7) instead of on new lists, so the only extra memory is the recursion stack, about $\log n$ frames deep when the splits are balanced. The price: swapping elements across long distances scrambles the order of equal keys, so in-place quick-sort is not stable.

Go deeper:

From Quiz: ADS / Merge-Sort and Quick-Sort | Updated: Dec 02, 2026