Proofs: Parallel radix sort
These are the human proofs of Parallel radix sort, at full length.
Parallel radix sort is correct and stable full
This proof shows: correctness.
Fix a pass and write . Give the items of their input positions . Block holds the positions to , so the blocks cut the positions into consecutive ranges in increasing order of .
Lemma 1. One pass is a stable counting sort on digit t
Define the order by digit : item comes before item if , or and has the smaller position. After the pass, the item with items before it in this order is at position of .
Proof. Let be an item in block with digit . The items before in the order by digit are of three kinds:
- the items with a digit less than , in any block; there are of them;
- the items with digit in a block , since these have smaller positions; there are of them;
- the items with digit in block that are to the left of .
By the order of the prefix sum on line L4, the starting value of is the sum of the counts of the first two kinds. Processor visits the keys of its block from left to right, and adds 1 to after each key with digit , so when it reaches the counter has grown by the number of items of the third kind. So is written at position , where is the number of items before .
The map from items to is a bijection onto , because the order by digit is a strict total order on the items. So every cell of is written exactly once.
Lemma 2. Exclusive access
Proof. On line L3, processor reads only its own block and writes only the counts . The prefix sum on line L4 can be done with exclusive reads and writes, as shown for the EREW PRAM on the page on prefix sums. On lines L5 to L7, processor reads its block and its own counters , and by Lemma 1 the cells of it writes are distinct from each other and from those of every other processor. So no cell is read or written by two processors in the same step.
Theorem. PAR-RADIX-SORT sorts stably
After the passes , the items are in the order of their low digits, read as a number, with ties in input order. So after all passes they are sorted, stably.
Proof. By induction on . For this is Lemma 1 with the input order. Assume it after pass , and take two items and with before after pass . By Lemma 1, either , and then the low digits of form a smaller number, or and was before after pass . In the second case, by induction, the low digits of form a number at most that of , with earlier in the input if they are equal. In both cases comes before in the order of the claim. A key of bits has all its bits in the low digits, so the last pass leaves the keys sorted, with equal keys in input order.