82, 88, 94, 101 are locked in at the tail in that exact order — the telltale fingerprint. The front 14 elements are still churning: partially shuffled by adjacent swaps but not yet sorted.Every split, every merge.
We recursively halve the vector until each piece is a single element, then merge the pieces back together in sorted order. Splits descend; merges ascend.
Merge trace — how the final merge works
[8, 22, 33, 51, 76, 95] with [2, 5, 16, 46, 60, 82] — compare heads, take smaller:
Every recursive call, every swap.
Partition around the leftmost element. Elements < pivot go left, elements > pivot go right, then recurse on each side. The pivot lands in its final resting place each call.
[22, 76, 51, 8, 33, 5, 82, 46, 16, 60, 2]. Right side is empty.[8, 5, 16, 2], right on [76, 51, 33, 82, 46, 60].[5, 2]. Right: [16] (base case).[2] is a base case. Left partition of Call 2 is now 2 5 8 16.[51, 33, 46, 60]. Right: [82] (base case).[33, 46]. Right: [60] (base case).[46] (base case). Right partition of Call 2 resolves to 33 46 51 60 76 82.When the elegant algorithm degrades.
QuickSort’s efficiency comes from balanced partitions. When the pivot is always the smallest or largest element, the recursion tree becomes a degenerate chain instead of a branching tree.
Worst case: already-sorted (or reverse-sorted) input with a first/last element pivot.
With the first element as pivot on a sorted vector like [2, 5, 8, 16, 22, …], the pivot is always the minimum. Every partition produces an empty left side and a right side of size n − 1.
That makes n recursive calls, each doing O(n) work — total O(n²). Reverse-sorted input behaves the same way because the pivot is always the maximum.
Side note — how to avoid it
In practice, the worst case is sidestepped by picking the pivot more carefully: randomly, as the median-of-three (first, middle, last), or by shuffling before sorting. These tricks don’t change the theoretical worst case, but they make it vanishingly unlikely on real inputs.
Eight fingerprints, eight algorithms.
[12 21 35 50 94], [5 47 88 101], [10 28 59 61 82], [9 17 36 69]. Each chunk is internally sorted — textbook merge signature.5 is out of order). It’s Shell sort: after sorting with decreasing gaps, elements are mostly in order with local inversions like 10 5 and 36 35. The tell is large-scale order with small local disorder.50, after 4 passes (inserting 21, 94, 35, 12) the first five elements are 12 21 35 50 94 — sorted — and the rest of the tail is untouched. Perfect insertion signature.0,0,1,1,1,2,2,4,5,5,6,7,7,8,8,9,9,9, perfectly ordered. The array is sorted by ones digit.50 is in its final sorted index with everything smaller to its left and everything larger to its right. Merge would leave its chunks internally sorted; this doesn’t.5, 9, 10, 12, 17 sit at the front in order, and the tail is in its original relative order minus those five — which matches exactly.82, 88, 94, 101 are sorted at the rear. The messy-looking front is the remaining heap — notice it’s not sorted like bubble would produce, but the parent-greater-than-child heap property holds (69 ≥ 59, 61; 59 ≥ 47, 50; etc.).