Galloping in fast-growth natural merge sorts
Elahe Ghasemi, Vincent Jug\'e, Ghazal Khalighinejad, Helia Yazdanyar

TL;DR
This paper analyzes the efficiency of TimSort's galloping routine, showing its limitations and proposing modifications that improve worst-case comparison bounds for arrays with few distinct values.
Contribution
It introduces a modified galloping routine and the concepts of dual runs and growth properties, enhancing understanding of merge sort efficiency on arrays with limited distinct values.
Findings
Original galloping routine does not prevent Θ(n log n) comparisons for arrays with three values.
Modified routine achieves O(n + n log σ) comparisons for arrays with σ distinct values.
New notions of fast- and middle-growth algorithms optimize merge sort performance on low-complexity arrays.
Abstract
We study the impact of merging routines in merge-based sorting algorithms. More precisely, we focus on the galloping routine that TimSort uses to merge monotonic sub-arrays, hereafter called runs, and on the impact on the number of element comparisons performed if one uses this routine instead of a na\"ive merging routine. This routine was introduced in order to make TimSort more efficient on arrays with few distinct values. Alas, we prove that, although it makes TimSort sort array with two values in linear time, it does not prevent TimSort from requiring up to element comparisons to sort arrays of length~ with three distinct values. However, we also prove that slightly modifying TimSort's galloping routine results in requiring only element comparisons in the worst case, when sorting arrays of length with distinct…
Peer Reviews
No public reviews on file for this paper yet. If you reviewed it on a platform where reviews are public (OpenReview, ICLR, NeurIPS, ICML), you can paste yours below so the community can read it here.
Videos
No videos yet. Explain this paper in a talk, walkthrough, or lecture? Add one.
