Basic properties of Array.mergeSort. #
pairwise_mergeSort:mergeSortproduces a sorted array.mergeSort_perm:mergeSortis a permutation of the input array.mergeSort_of_pairwise:mergeSortdoes not change a sorted array.sublist_mergeSort: ifcis a sorted sublist ofl, thencis still a sublist ofmergeSort le l.
The result of Array.mergeSort is sorted,
as long as the comparison function is transitive (le a b → le b c → le a c)
and total in the sense that le a b || le b a.
The comparison function need not be irreflexive, i.e. le a b and le b a is allowed even when a ≠ b.
This merge sort algorithm is stable, in the sense that breaking ties in the ordering function using the position in the array has no effect on the output.
That is, elements which are equal with respect to the ordering function will remain in the same order in the output array as they were in the input array.
See also:
sublist_mergeSort: ifc <+ landc.Pairwise le, thenc <+ (mergeSort le l).toList.pair_sublist_mergeSort: if[a, b] <+ landle a b, then[a, b] <+ (mergeSort le l).toList)
Another statement of stability of merge sort.
If c is a sorted sublist of xs.toList,
then c is still a sublist of (mergeSort le xs).toList.
Another statement of stability of merge sort.
If a pair [a, b] is a sublist of xs.toList and le a b,
then [a, b] is still a sublist of (mergeSort le xs).toList.