Proofs: Cole's parallel merge sort
These are the human proofs of Cole's parallel merge sort, at full length.
Cole's merge sort sorts in 3 lg n stages full
This proof shows: correctness.
Let and assume the keys are distinct (ties are broken by input index). For a node of height , is the sorted list of the keys at the leaves below . Write and for the lists after stage , with at a leaf and at an inner node. A node is full at stage if .
Lemma 1. The lists are sorted subsets
For every and , and are sorted lists of distinct items of , provided that each stage computes as the sorted union of and .
Proof. By induction on . A sample of a sorted list of items of is again one. The union of a list of items of and one of items of has distinct items, because and are disjoint, and its items are in .
Lemma 2. Line L7 finds the rank
Let , let be the number of items of less than , and let and , with if and if . Let be the number of items of less than . Then the rank of in is plus the number of items of in that are less than .
Proof. We have . Items of less than are less than . Items of that are at least are at least , and none of them equals , because is below and they are below . So the items of less than are the items below and those in below .
The lemma holds for any lists. The 3-cover property only bounds the number of items in , which matters for the time and not for the result.
Lemma 3. The merge is correct
Line L8 writes each item of to a distinct position, and the result is the sorted union.
Proof. For , the items of the union less than are the items of less than and those of less than . Their number is the sum that line L8 uses, by Lemma 2, and the same holds for items of . In a set of distinct items, the number of smaller items is the position in sorted order.
Lemma 4. Size before a node is full
For a node of height and , . In particular for , so is not full before stage .
Proof. By induction on , with the claim for height read as: a leaf is full from stage on. Let and be the children of , of height . Then . We prove Lemmas 4 and 5 together by induction on , so we may use that and become full at exactly stage . For the list is empty, so let .
Case . The children are not full at stage , so their samples are every fourth item, and . Since , twice this is .
Case with . The children became full at stage , so their samples have , and items for , at most, which is . Twice this is .
Lemma 5. A node of height h is full at stage 3h
Proof. By induction on . Leaves are full at stage . Let have height . Its children are full at stage , so at stage their samples are all of and all of , and by Lemma 3, in sorted order, which is . By Lemma 4 it is not full earlier. After stage the node keeps its list, and it sends samples only in stages to .
Theorem
After stage , is , the input keys in sorted order.
Proof. The root has height , so this is Lemma 5 for . With ties broken by input index, equal keys keep their input order, and removing the padding keys, which are larger than all real keys and sit at the end, gives the sorted input.