The complexity of the Python sorting method

If I need to sort some list, say a, using sort method

in Python like below.

print a


What are the worst, average and best cases

sorting programs for such programs? And what difficulties do they have in each? What sorting method does python use in this?


source to share

1 answer

Python uses Timsort , which was named after Tim Peters, the Python developer who invented it. The Wikipedia page contains information on difficulty:

Worst case performance  O(nlogn)
Best case performance   O(n)
Average case performance    O(nlogn)
Worst case space complexity O(n)




All Articles