LOGBOOK

HELP

Quiz Entry - updated: 2026.12.02

Quick-sort runs on 7 2 9 4 3 7 6 1 with pivot 6 at the root, then pivots 2 and 3 on the left and the last 7 on the right. What does the quick-sort tree look like?

The root splits into $L$ = 2 4 3 1 and $G$ = 7 9 7. On the left, pivot 2 leaves 1 and 4 3, and 4 3 with pivot 3 leaves an empty $L$ and 4. On the right, pivot 7 leaves an empty $L$, $E$ = 7 7 and $G$ = 9. Result: 1 2 3 4 6 7 7 9.

The quick-sort tree for 7 2 9 4 3 7 6 1 with the pivot of every call underlined and the empty calls drawn as dashed boxes

* Empty calls are leaves too: they return at once. *

Like the merge-sort tree, a quick-sort tree has one node per recursive call. A node shows the call's input with its pivot, and the sorted output it returns; the left child is the call on $L$, the right child the call on $G$. The elements of $E$ are not passed on to any child: they are already in their final place, between the two children's outputs.

Unlike the merge-sort tree, the shape is not fixed. It depends on the pivots alone: here the left side reaches depth 3 and the right side depth 2. A pivot near the median gives two children of similar size, an extreme pivot gives one child with almost everything and one empty child.

The two 7s also show that this quick-sort is not stable: the pivot was the second 7, it went into $E$ first, so it ends up in front of the 7 that came before it in the input.

Go deeper:

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