The complexity of the Python sorting method

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

in Python like below.

a=[3,7,1,0,2,8]
a.sort()
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?

+3


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)

      

+6


source







All Articles