Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is timsort general-purpose or Python-specific?

Timsort is an adaptive, stable, natural mergesort. It has supernatural performance on many kinds of partially ordered arrays (less than lg(N!) comparisons needed, and as few as N-1), yet as fast as Python's previous highly tuned samplesort hybrid on random arrays.

Have you seen timsort used outside of CPython? Does it make sense?

like image 896
Constantin Avatar asked Sep 30 '08 19:09

Constantin


People also ask

What programming languages use TimSort?

Timsort is the default sorting algorithm in Python, Java, and NodeJS.

What is TimSort Python?

Timsort is a hybrid, stable sorting algorithm, derived from merge sort and insertion sort, designed to perform well on many kinds of real-world data. It was implemented by Tim Peters in 2002 for use in the Python programming language.

Why is TimSort the best sorting algorithm?

It implements the idea that the real-world data sets almost always contain already ordered subsequences, so the sorting strategy is to identify them and sort them further using both merge and insert methods. Timsort is one of the best sorting algorithms in terms of complexity and stability.

Does Java use TimSort?

Java uses dual-pivot sort for primitives, which is an unstable sort. Java uses timsort, a stable sorting algorithm for objects.


1 Answers

Yes, it makes quite a bit of sense to use timsort outside of CPython, in specific, or Python, in general.

There is currently an effort underway to replace Java's "modified merge sort" with timsort, and the initial results are quite positive.

like image 156
plinehan Avatar answered Oct 04 '22 17:10

plinehan