Basic properties of mergeSort. #
- sorted_mergeSort:- mergeSortproduces a sorted list.
- mergeSort_perm:- mergeSortis a permutation of the input list.
- mergeSort_of_sorted:- mergeSortdoes not change a sorted list.
- mergeSort_cons: proves- mergeSort le (x :: xs) = l₁ ++ x :: l₂for some- l₁, l₂so that- mergeSort le xs = l₁ ++ l₂, and no- a ∈ l₁satisfies- le a x.
- sublist_mergeSort: if- cis a sorted sublist of- l, then- cis still a sublist of- mergeSort le l.
splitInTwo #
zipIdxLE #
merge #
If the ordering relation le is transitive and total (i.e. le a b || le b a for all a, b)
then the merge of two sorted lists is sorted.
mergeSort #
The result of 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 list 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 list as they were in the input list.
See also:
- sublist_mergeSort: if- c <+ land- c.Pairwise le, then- c <+ mergeSort le l.
- pair_sublist_mergeSort: if- [a, b] <+ land- le a b, then- [a, b] <+ mergeSort le l)
Equations
Instances For
Another statement of stability of merge sort.
If c is a sorted sublist of l,
then c is still a sublist of mergeSort le l.
Equations
Instances For
Another statement of stability of merge sort.
If a pair [a, b] is a sublist of l and le a b,
then [a, b] is still a sublist of mergeSort le l.