Document Open Access Logo

Galloping in Fast-Growth Natural Merge Sorts

Authors Elahe Ghasemi, Vincent Jugé , Ghazal Khalighinejad



PDF
Thumbnail PDF

File

LIPIcs.ICALP.2022.68.pdf
  • Filesize: 0.9 MB
  • 19 pages

Document Identifiers

Author Details

Elahe Ghasemi
  • Sharif University of Technology, Teheran, Iran
  • Univ Gustave Eiffel, CNRS, LIGM, F-77454 Marne-la-Vallée, France
Vincent Jugé
  • Univ Gustave Eiffel, CNRS, LIGM, F-77454 Marne-la-Vallée, France
Ghazal Khalighinejad
  • Duke University, Durham, NC, USA
  • Sharif University of Technology, Teheran, Iran

Cite AsGet BibTex

Elahe Ghasemi, Vincent Jugé, and Ghazal Khalighinejad. Galloping in Fast-Growth Natural Merge Sorts. In 49th International Colloquium on Automata, Languages, and Programming (ICALP 2022). Leibniz International Proceedings in Informatics (LIPIcs), Volume 229, pp. 68:1-68:19, Schloss Dagstuhl - Leibniz-Zentrum für Informatik (2022)
https://doi.org/10.4230/LIPIcs.ICALP.2022.68

Abstract

We study the impact of sub-array merging routines on merge-based sorting algorithms. More precisely, we focus on the galloping sub-routine that TimSort uses to merge monotonic (non-decreasing) sub-arrays, hereafter called runs, and on the impact on the number of element comparisons performed if one uses this sub-routine instead of a naive merging routine. The efficiency of TimSort and of similar sorting algorithms has often been explained by using the notion of runs and the associated run-length entropy. Here, we focus on the related notion of dual runs, which was introduced in the 1990s, and the associated dual run-length entropy. We prove, for this complexity measure, results that are similar to those already known when considering standard run-induced measures: in particular, TimSort requires only 𝒪(n + n log(σ)) element comparisons to sort arrays of length n with σ distinct values. In order to do so, we introduce new notions of fast- and middle-growth for natural merge sorts (i.e., algorithms based on merging runs). By using these notions, we prove that several merge sorting algorithms, provided that they use TimSort’s galloping sub-routine for merging runs, are as efficient as TimSort at sorting arrays with low run-induced or dual-run-induced complexities.

Subject Classification

ACM Subject Classification
  • Theory of computation → Sorting and searching
Keywords
  • Sorting algorithms
  • Merge sorting algorithms
  • Analysis of algorithms

Metrics

  • Access Statistics
  • Total Accesses (updated on a weekly basis)
    0
    PDF Downloads

References

  1. Nicolas Auger, Vincent Jugé, Cyril Nicaud, and Carine Pivoteau. On the worst-case complexity of timsort. In 26superscriptth Annual European Symposium on Algorithms (ESA), pages 4:1-13, 2018. Extended version available at: URL: https://arxiv.org/abs/1805.08612.
  2. Nicolas Auger, Cyril Nicaud, and Carine Pivoteau. Merge strategies: from merge sort to timsort. Research report hal-01212839, 2015. Google Scholar
  3. Jérémy Barbay and Gonzalo Navarro. On compressing permutations and adaptive sorting. Theoretical Computer Science, 513:109-123, 2013. Google Scholar
  4. Jérémy Barbay, Carlos Ochoa, and Srinivasa Rao Satti. Synergistic solutions on multisets. In 28superscriptth Annual Symposium on Combinatorial Pattern Matching (CPM), pages 31:2-14, 2017. Google Scholar
  5. Jon Bentley and Andrew Yao. An almost optimal algorithm for unbounded searching. Information Processing Letters, 5(3):82-87, 1976. Google Scholar
  6. Josh Bloch. Timsort implementation in java 13, retrieved 01/01/2022. URL: https://github.com/openjdk/jdk/blob/3afeb2cb4861f95fd20c3c04f04be93b435527c0/src/java.base/share/classes/java/util/ComparableTimSort.java.
  7. Sam Buss and Alexander Knop. Strategies for stable merge sorting. In 30superscriptth Annual ACM-SIAM Symposium on Discrete Algorithms (SODA), pages 1272-1290, 2019. Google Scholar
  8. Ben Cohen. Timsort implementation in java 13, retrieved 01/01/2022. URL: https://github.com/apple/swift/blob/4c1d46bc0980d84bf3178bc42295522c242fec86/stdlib/public/core/Sort.swift.
  9. Vladmir Estivill-Castro and Derick Wood. A survey of adaptive sorting algorithms. ACM Computing Surveys, 24(4):441-476, 1992. Google Scholar
  10. Adriano Garsia and Michelle Wachs. A new algorithm for minimal binary search trees. SIAM Journal on Computing, 6(4):622-642, 1977. Google Scholar
  11. Elahe Ghasemi, Vincent Jugé, and Ghazal Khalighinejad. Galloping in natural merge sorts. In 49superscriptth International Colloquium on Automata, Languages, and Programming (ICALP), pages 61:1-61:19, 2022. Extended version available at: URL: https://arxiv.org/abs/2012.03996.
  12. Te Hu and Alan Tucker. Optimal computer search trees and variable-length alphabetical codes. SIAM Journal on Applied Mathematics, 21(4):514-532, 1971. Google Scholar
  13. Vincent Jugé. Adaptive shivers sort: an alternative sorting algorithm. In 31superscriptth Annual ACM-SIAM Symposium on Discrete Algorithms (SODA), pages 1639-1654, 2020. Google Scholar
  14. Donald E. Knuth. The Art of Computer Programming, Volume 3: (2nd Ed.) Sorting and Searching. Addison Wesley Longman Publish. Co., 1998. Google Scholar
  15. Christos Levcopoulos and Ola Petersson. Sorting shuffled monotone sequences. Information and Computation, 112(1):37-50, 1994. Google Scholar
  16. Heikki Mannila. Measures of presortedness and optimal sorting algorithms. IEEE Trans. Computers, 34(4):318-325, 1985. Google Scholar
  17. Peter McIlroy. Optimistic sorting and information theoretic complexity. In 4superscriptth Annual ACM-SIAM Symposium on Discrete Algorithms (SODA), pages 467-474, 1993. Google Scholar
  18. Ian Munro and Philip Spira. Sorting and searching in multisets. SIAM journal on Computing, 5(1):1-8, 1976. Google Scholar
  19. Ian Munro and Sebastian Wild. Nearly-optimal mergesorts: Fast, practical sorting methods that optimally adapt to existing runs. In 26superscriptth Annual European Symposium on Algorithms (ESA 2018), pages 63:1-63:15, 2018. Google Scholar
  20. Tim Peters. Timsort description, retrieved 01/09/2021. URL: https://github.com/python/cpython/blob/24e5ad4689de9adc8e4a7d8c08fe400dcea668e6/Objects/listsort.txt.
  21. Clément Renault et al. Timsort implementation in rust, retrieved 01/01/2022. URL: https://github.com/rust-lang/rust/blob/a5a91c8e0732753de7c028182cbb02901fe1b608/library/alloc/src/slice.rs.
  22. Olin Shivers. A simple and efficient natural merge sort. Technical report, Georgia Institute of Technology, 2002. Google Scholar
  23. Guido van Rossum et al. Powersort implementation in cpython, retrieved 01/01/2022. URL: https://github.com/python/cpython/blob/c8749b578324ad4089c8d014d9136bc42b065343/Objects/listobject.c.
  24. Jeff Weaton and Markus Mützel. Timsort implementation in octave, retrieved 01/01/2022. URL: https://github.com/gnu-octave/octave/blob/7e6da6d504ad962a8d33622b6955b0210ff62365/liboctave/util/oct-sort.cc.
  25. Simon Zünd et al. Timsort implementation in v8, retrieved 01/01/2022. URL: https://github.com/v8/v8/blob/25f0e32915930df1d53722b91177b1dee5202499/third_party/v8/builtins/array-sort.tq.
Questions / Remarks / Feedback
X

Feedback for Dagstuhl Publishing


Thanks for your feedback!

Feedback submitted

Could not send message

Please try again later or send an E-mail