Comparison counts of merge sort with any comparator #
CSLib bounds the comparisons of Cslib.Algorithms.Lean.TimeM.mergeSort, which compares with ≤
in a linear order. Clients that sort by a key, such as symbols by weight or edges by weight, call
List.mergeSortM with their own comparator. This file gives the same bounds for any comparator
le : α → α → TimeM ℕ Bool that costs at most one tick per call: merging takes at most
xs.length + ys.length ticks, and merge sort at most n * ⌈log₂ n⌉.
Main results #
Cslib.Algorithms.Lean.TimeM.mergeM_time: the merge bound.Cslib.Algorithms.Lean.TimeM.mergeSortM_time_le: merge sort within the recurrenceCslib.Algorithms.Lean.TimeM.timeMergeSortRec.Cslib.Algorithms.Lean.TimeM.mergeSortM_time: merge sort withinn * ⌈log₂ n⌉ticks.