paper

Strategies for Stable Merge Sorting

arXiv:1801.04641

Abstract

We introduce new stable natural merge sort algorithms, called -merge sort and -merge sort. We prove upper and lower bounds for several merge sort algorithms, including Timsort, Shivers' sort, -stack sorts, and our new -merge and -merge sorts. The upper and lower bounds have the forms and for inputs of length~ comprising ~monotone runs. For Timsort, we prove a lower bound of . For -merge sort, we prove optimal upper and lower bounds of approximately . We prove similar asymptotically matching upper and lower bounds for -merge sort, when , where is the golden ratio. Our bounds are in terms of merge cost; this upper bounds the number of comparisons and accurately models runtime. The merge strategies can be used for any stable merge sort, not just natural merge sorts. The new -merge and -merge sorts have better worst-case merge cost upper bounds and are slightly simpler to implement than the widely-used Timsort; they also perform better in experiments. We report also experimental comparisons with algorithms developed by Munro-Wild and Jugé subsequently to the results of the present paper.

38 pages, 5 figures