Merge Strategies: from Merge Sort to TimSort
Résumé
The introduction of TimSort as the standard algorithm for sorting in Java and Python questions the generally accepted idea that merge algorithms are not competitive for sorting in practice. In an attempt to better understand TimSort algorithm, we define a framework to study the merging cost of sorting algorithms that relies on merges of monotonic subsequences of the input. We propose an optimal strategy for lists and a 2-approximation for arrays. We compare them to the merging strategy of TimSort by designing a simpler yet competitive algorithm based on the same ideas. As a side benefit, our framework allows to establish the announced running time of TimSort, that is O(n log n).
Origine : Fichiers produits par l'(les) auteur(s)