Proofs: Sample sort
These are the human proofs of Sample sort, at full length.
Sample sort is correct, and its buckets are small with high probability full
This proof shows: correctness.
Let the keys be distinct. If they are not, pair each key with its input index and order the pairs by key and then by index. The pairs are distinct and sorting them sorts the keys stably, so this case reduces to distinct keys.
Lemma 1. The output is sorted
Proof. Let and . By line L4, a key is in bucket exactly when , because the splitters are sorted. So if is in bucket and is in bucket , then . Each bucket is sorted on line L6, so the concatenation on line L7 is sorted. Each key goes to exactly one bucket, so the output is a permutation of the input. This holds for every sample.
Lemma 2. A large bucket leaves a run of keys with few draws
Let . Call a set of keys that are consecutive in sorted order a run. If some bucket has more than keys, then some run gets at most of the draws of line L1.
Proof. Let bucket have more than keys, and let be its smallest keys. They are consecutive in sorted order, because the bucket holds all the keys of an interval, so is a run. Every key of is greater than and, since the bucket has a larger key, less than .
Let a draw have its key in . In the sorted sample , its position satisfies , so when , and , so when . For the positions are less than , and for they are greater than and less than . In each case the positions lie in a set of at most integers, so at most draws have their key in .
Theorem. Bucket bound
Let and . With probability at least , every bucket has at most keys. For , the probability is at least .
Proof. Fix one run of keys. Each draw falls in with probability , independently of the other draws. So the number of draws in is a binomial variable with mean . By the Chernoff bound with ,
There are runs. By Lemma 2 and a union bound, the probability that some bucket has more than keys is at most . For this is at most .
Running time
On the CREW PRAM with processors, lines L1 to L3 take time with the sample sorted on one processor. Line L4 takes time , line L5 takes time , and on the event of the theorem, line L6 takes time . Line L7 is free when the buckets were placed in order on line L5. So with probability at least the time is .