What algorithm does python's sorted() use?

PythonSorting

Python Problem Overview


> Possible Duplicate:
> About python's built in sort() method

Name says it all.

I'm trying to explain to someone why they should use Python's builtin sorted() function instead of rolling their own, and I realized I have no idea what algorithm it uses.

If it matters, we're talking python 2.7

Python Solutions


Solution 1 - Python

Python uses an algorithm called Timsort:

> Timsort is a hybrid sorting algorithm, derived from merge sort and > insertion sort, designed to perform well on many kinds of real-world > data. It was invented by Tim Peters in 2002 for use in the Python > programming language. The algorithm finds subsets of the data that are > already ordered, and uses the subsets to sort the data more > efficiently. This is done by merging an identified subset, called a > run, with existing runs until certain criteria are fulfilled. Timsort > has been Python's standard sorting algorithm since version 2.3. It is > now also used to sort arrays in Java SE 7, and on the Android > platform.

Solution 2 - Python

The sort algorithm is called Timsort. See timsort

Solution 3 - Python

Since 2.3 Python has used timsort.

More info: http://bugs.python.org/file4451/timsort.txt

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionHartley BrodyView Question on Stackoverflow
Solution 1 - PythonbgporterView Answer on Stackoverflow
Solution 2 - PythonPierceView Answer on Stackoverflow
Solution 3 - PythonDavid HaynesView Answer on Stackoverflow