3 ms·
What about the time taken to do the sorting? Is there some rule of thumb that hints at whether taking the time to sort the data is going to be a net win?
by grannyg00se 14y ago
What about the time taken to do the sorting? Is there some rule of thumb that hints at whether taking the time to sort the data is going to be a net win?
- Tichy 14y agoI would expect sorting to take a lot longer than just summing.
- chiph 14y agoUnless you have external information, you will need to take at least one pass through the data to determine if its sorted or not.
- saraid216 14y agoThe time it takes to sort an array is a rather well-understood problem. If you can reason about how much performance gain you'll get from looping through a sorted versus unsorted array, you can probably estimate the additional cost of the sort itself.
- propercoil 14y agosorting an array of integers that you know the max value of (like in the question in SO) will take you O(n) with count sort, so this will be pretty damn fast