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.
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?
Why is the time complexity of sorting an array of strings not a function of the length of each string?
Complexity of Python Sort Method - Stack Overflow
What time complexity should one assume when using built in sort functions?
Radix sort vs quicksort. Which one is faster for int arrays? (benchmark with C/Java code)
Videos
The time complexity is `O(n log n)`, where `n` is the number of strings. However, comparing each pair of strings requires traversing both strings, which is `O(m)`, where `m` is the length of the shorter string. Shouldn't the time complexity be `O(n log n * avg(m))`?