Proofs: Parallel sorting by regular sampling
These are the human proofs of Parallel sorting by regular sampling, at full length.
PSRS sorts, and every processor gets at most 2n/p − p keys full
This proof shows: correctness.
Let the keys be distinct, let divide and let , so each block has keys. Equal keys reduce to this case by pairing each key with its input index and ordering the pairs by key, then index.
Lemma 1. The output is sorted
Proof. Let and . The samples are sorted, so . Each key lies in exactly one bucket , the one with . If is in bucket and is in bucket , then . Each block is sorted, so its keys of bucket form a sorted, contiguous piece, found on line L4 by binary search. Line L6 merges the pieces of bucket into a sorted list of all its keys. So the buckets, in order, are the sorted output.
Lemma 2. Each bucket contains exactly p samples
Proof. The keys are distinct, so the samples are distinct, and . With , the samples in bucket are those with , where for the lower bound is and for the upper bound is , which is for the samples. These are , which are samples.
Lemma 3. A stretch of a block with c samples has at most (c + 1)w − 1 keys
Within a sorted block, the samples are at positions . Let a stretch of consecutive positions contain of these positions. Then .
Proof. If , the stretch lies between two consecutive sample positions , or after the last one, . In both cases it has at most positions. If , let the sample positions in the stretch be . The stretch starts after the previous sample position, so , or if . In both cases . It ends before the next sample position, so , which also holds at the end of the block, where and . So .
Theorem. Bucket bound
Every bucket has at most keys.
Proof. Fix bucket . In block , the keys of bucket form a stretch of consecutive positions, by Lemma 1. Let be the number of samples of block in this stretch. The samples of a block lie in the bucket exactly when they lie in this stretch, so by Lemma 2, . By Lemma 3, the bucket has at most
keys.
The example on the page has and , and its third bucket has keys, so for these values of and the bound is reached.