If I have to sort some list, say a, using the sort method
in Python such as below..
a=[3,7,1,0,2,8]
a.sort()
print a
What are the worst, average and best cases
of such programs in case of sorting ? And what complexities would they have in each ? What sorting technique does python use in this ?
Python uses Timsort, which was named after Tim Peters, the Python developer who invented it. The Wikipedia page has complexity information:
Worst case performance O(nlogn)
Best case performance O(n)
Average case performance O(nlogn)
Worst case space complexity O(n)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With