Вопрос по python, sorting – Какой алгоритм использует Python sorted ()? [Дубликат]
Possible Duplicate:
About python's built in sort() method
Имя говорит само за себя.
Я пытаюсь объяснить кому-то, почему им следует использовать встроенную функцию Python sorted () вместо собственной, и я понял, что понятия не имею, какой алгоритм он использует.
Если это имеет значение, мы говорим на Python 2.7.
Python использует алгоритм под названием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.
Начиная с 2.3 Python использует timsort.
Больше информации:http://bugs.python.org/file4451/timsort.txt