English

Strategies for Stable Merge Sorting

Data Structures and Algorithms 2019-02-12 v4

Abstract

We introduce new stable natural merge sort algorithms, called 22-merge sort and α\alpha-merge sort. We prove upper and lower bounds for several merge sort algorithms, including Timsort, Shivers' sort, α\alpha-stack sorts, and our new 22-merge and α\alpha-merge sorts. The upper and lower bounds have the forms cnlogmc \cdot n \log m and cnlognc \cdot n \log n for inputs of length~nn comprising mm~monotone runs. For Timsort, we prove a lower bound of (1.5o(1))nlogn(1.5 - o(1)) n \log n. For 22-merge sort, we prove optimal upper and lower bounds of approximately (1.089±o(1))nlogm(1.089 \pm o(1))n \log m. We prove similar asymptotically matching upper and lower bounds for α\alpha-merge sort, when φ<α<2\varphi < \alpha < 2, where φ\varphi 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 22-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. We report also experimental comparisons with algorithms developed by Munro-Wild and Jug\'e subsequently to the results of the present paper.

Keywords

Cite

@article{arxiv.1801.04641,
  title  = {Strategies for Stable Merge Sorting},
  author = {Sam Buss and Alexander Knop},
  journal= {arXiv preprint arXiv:1801.04641},
  year   = {2019}
}

Comments

38 pages, 5 figures

R2 v1 2026-06-22T23:44:53.803Z