Algorithm Search⌘K

Proofs: Hyperquicksort

These are the human proofs of Hyperquicksort, at full length.

Hyperquicksort sorts in processor order full

This proof shows: correctness.

Let p=2dp = 2^d. For a processor number qq and 0≤i<d0 \le i < d, write qiq_i for bit ii of qq. Call the rounds by their dimension ii, which runs from d−1d - 1 down to 00. Let Hi(q)H_i(q) be the subcube of dimension i+1i + 1 that contains qq: the processors whose numbers agree with qq on the bits above bit ii.

Lemma 1. Keys are kept and lists stay sorted

Proof. Line L1 sorts each list. In a round, a pair q,q′q, q' splits its two sorted lists into four sorted parts, and lines L6 and L7 put each key into exactly one of the two merged lists. Merging two sorted lists gives a sorted list. Processors not in a pair with a pivot keep their lists. So after every round, the multiset of all keys is the input, and each list is sorted. □\square

Lemma 2. Keys stay inside the subcubes of later rounds

After round ii, and in all later rounds, keys move only between processors that agree on bits ii and above.

Proof. In round i′≤ii' \le i, keys move only between qq and q+2i′q + 2^{i'}, which differ only in bit i′i'. If i′<ii' < i, they agree on bits ii and above. □\square

Lemma 3. Round i splits each subcube by its pivot

Let xx be the pivot of the subcube H=Hi(q)H = H_i(q) in round ii. After round ii, every key on a processor of HH with bit ii equal to 00 is at most xx, and every key on a processor of HH with bit ii equal to 11 is greater than xx.

Proof. The processors of HH with bit ii equal to 00 are paired with those with bit ii equal to 11 by q↦q+2iq \mapsto q + 2^i, and every processor of HH is in exactly one pair. By lines L6 and L7, after the round the lower processor of each pair holds exactly the keys at most xx of the pair, and the upper one holds exactly the keys greater than xx. If no processor of HH has keys, there is nothing to show. □\square

Theorem. The output is sorted in processor order

At the end, each list is sorted, and for q<q′q < q' every key on processor qq is at most every key on processor q′q'.

Proof. By Lemma 1 the lists are sorted and hold the input keys. Let q<q′q < q' and let ii be the highest bit where they differ, so qi=0q_i = 0 and qi′=1q'_i = 1, and both lie in the subcube H=Hi(q)H = H_i(q). By Lemma 3, right after round ii, the processors of HH with bit ii equal to 00 hold only keys at most the pivot xx of HH, and those with bit ii equal to 11 hold only keys greater than xx. By Lemma 2, all later moves are between processors that agree on bit ii and above, so the keys of the lower half of HH stay in the lower half, and the same for the upper half. So at the end, every key on qq is at most xx, and every key on q′q' is greater than xx. □\square

Back to Hyperquicksort