I have a long list of unsorted integers, and I am iterating over the list, and for each iteration, I want to obtain the maximum- this would result in time complexity: n + (n-1) + (n-2) + ... = O(n^2)
The alternative is to sort the entire list, which I believe takes O(n log n)
for time complexity. Then simply popping from the end- which would be O(n)
, so this won't affect the overall complexity.
So am I right in saying that sorting the list would be more efficient than taking the maximum each time?