On the Worst-Case Complexity of TimSort

05/22/2018
by   Nicolas Auger, et al.
0

TimSort is an intriguing sorting algorithm designed in 2002 for Python, whose worst-case complexity was announced, but not proved until our recent preprint. In fact, there are two slightly different versions of TimSort that are currently implemented in Python and in Java respectively. We propose a pedagogical and insightful proof that the Python version runs in O(n n). The approach we use in the analysis also applies to the Java version, although not without very involved technical details. As a byproduct of our study, we uncover a bug in the Java implementation that can cause the sorting method to fail during the execution. We also give a proof that Python's TimSort running time is in O(n + nρ), where ρ is the number of runs (i.e. maximal monotonic sequences), which is quite a natural parameter here and part of the explanation for the good behavior of TimSort on partially sorted inputs.

READ FULL TEXT

page 1

page 2

page 3

page 4

research
01/29/2018

Generalized Leapfrogging Samplesort: A Class of O(n ^2 n) Worst-Case Complexity and O(n n) Average-Case Complexity Sorting Algorithms

The original Leapfrogging Samplesort operates on a sorted sample of size...
research
11/02/2018

Worst-Case Efficient Sorting with QuickMergesort

The two most prominent solutions for the sorting problem are Quicksort a...
research
08/13/2023

Py-Tetrad and RPy-Tetrad: A New Python Interface with R Support for Tetrad Causal Search

We give novel Python and R interfaces for the (Java) Tetrad project for ...
research
04/26/2018

QuickMergesort: Practically Efficient Constant-Factor Optimal Sorting

We consider the fundamental problem of internally sorting a sequence of ...
research
05/10/2018

Nearly-Optimal Mergesorts: Fast, Practical Sorting Methods That Optimally Adapt to Existing Runs

We present two stable mergesort variants, "peeksort" and "powersort", th...
research
09/14/2022

Multiway Powersort

Powersort (Munro Wild, ESA2018) has recently replaced Timsort's subo...

Please sign up or login with your details

Forgot password? Click here to reset