Strategies for Stable Merge Sorting

We introduce new stable, natural merge sort algorithms, called 2-merge sort and $\alpha$-merge sort. We prove upper and lower bounds for several merge sort algorithms, including Timsort, Shiver's sort, $\alpha$-stack sorts, and our new 2-merge and $\alpha$-merge sorts. The upper and lower bounds have the forms $c \cdot n \log m$ and $c \cdot n \log n$ for inputs of length $n$ comprising $m$ runs. For Timsort, we prove a lower bound of $ (1.5 - o(1)) n \log n $. For 2-merge sort, we prove optimal upper and lower bounds of approximately $ (1.089 \pm o(1))n \log m $. We prove similar asymptotically matching upper and lower bounds for $\alpha$-merge sort, when $\varphi < \alpha < 2$, where $\varphi$ is the golden ratio. These merge strategies can be used for any stable merge sort, not just natural merge sorts. The new 2-merge and $\alpha$-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.

[1]  Michael A. Langston,et al.  Practical in-place merging , 1987, CACM.

[2]  Muthu Dayalan,et al.  MapReduce : Simplified Data Processing on Large Cluster , 2018 .

[3]  Richard E. Ladner,et al.  The influence of caches on the performance of sorting , 1997, SODA '97.

[4]  Jyrki Katajainen,et al.  Asymptotically Efficient In-Place Merging , 1995, MFCS.

[5]  Christos Levcopoulos,et al.  Splitsort - An Adaptive Sorting Algorithm , 1990, Inf. Process. Lett..

[6]  James Harris Sorting unsorted and partially sorted lists using the natural merge sort , 1981 .

[7]  Cyril Nicaud,et al.  On the Worst-Case Complexity of TimSort , 2018, ESA.

[8]  宮尾 淳一,et al.  An Optimal Sorting Algorithm for Presorted Sequences , 1991 .

[9]  David Thomas,et al.  The Art in Computer Programming , 2001 .

[10]  Derick Wood,et al.  A survey of adaptive sorting algorithms , 1992, CSUR.

[11]  Cyril Nicaud,et al.  Merge Strategies: from Merge Sort to TimSort , 2015 .

[12]  Heikki Mannila,et al.  A Simple Linear-Time Algorithm for in Situ Merging , 1984, Inf. Process. Lett..

[13]  Frank S. de Boer,et al.  OpenJDK's Java.utils.Collection.sort() Is Broken: The Good, the Bad and the Worst Case , 2015, CAV.

[14]  Heikki Mannila,et al.  Measures of Presortedness and Optimal Sorting Algorithms , 1985, IEEE Transactions on Computers.

[15]  Steven Skiena,et al.  Encroaching lists as a measure of presortedness , 1988, BIT.

[16]  Curtis R. Cook,et al.  Best sorting algorithm for nearly sorted lists , 1980, CACM.

[17]  Peter M. McIlroy Optimistic sorting and information theoretic complexity , 1993, SODA '93.

[18]  Frank K. Hwang,et al.  A Simple Algorithm for Merging Two Disjoint Linearly-Ordered Sets , 1972, SIAM J. Comput..

[19]  Gonzalo Navarro,et al.  On compressing permutations and adaptive sorting , 2011, Theor. Comput. Sci..

[20]  Badrish Chandramouli,et al.  Patience is a virtue: revisiting merge and sort on modern processors , 2014, SIGMOD Conference.

[21]  Vincent Jugé,et al.  Adaptive Shivers Sort: An Alternative Sorting Algorithm , 2018, SODA.

[22]  Alistair Moffat,et al.  An Overview of Adaptive Sorting , 1992, Aust. Comput. J..

[23]  Domenico Cantone,et al.  NeatSort - A practical adaptive algorithm , 2014, ArXiv.

[24]  Sanjay Ghemawat,et al.  MapReduce: Simplified Data Processing on Large Clusters , 2004, OSDI.

[25]  Svante Carlsson,et al.  Sublinear merging and natural mergesort , 2005, Algorithmica.