Provided itemgetter(0) is O(1) when used with data, the sort is O(n log n) both on average and in the worst case.
For more information on the sorting method used in Python, see Wikipedia.
Answer from NPE on Stack OverflowProvided itemgetter(0) is O(1) when used with data, the sort is O(n log n) both on average and in the worst case.
For more information on the sorting method used in Python, see Wikipedia.
sorted is like sort except that the first builds a new sorted list from an iterable while sort do sort in place. The main difference will be space complexity.
Time Complexities of all Sorting Algorithms
What time complexity should one assume when using built in sort functions?
Sorting lists in python: sorted() vs sort()
A new sorting algorithm for 2025, faster than Powersort!
Videos
Let's say I want to find a number in an unordered array in O(log n) time. Implementing binary search is already O(log n) time but because I have to sort the array first do we take that into account in the time complexity calculations?
The problem gets worse if you're using a built in sort that you don't know the time complexity, for example, if you were doing this in JavaScript [5,4,12,3,56,1, ...].sort() what time complexity would you attribute to it?