in reply to Re: assigning the maximum of two numbers
in thread assigning the maximum of two numbers
Especially for large arrays? Wouldn't this be an O(nlogn) function? I mean, if you wanted an arbitrary number of the maximum numbers in a list, sure, you're pretty much already sorting. But for just the top 1, you should use an O(n) algorithm, which gets even more important for "large arrays".
For short arrays, the difference between sort and looping with a ternary will be minor. For long arrays, well, it becomes a bit more important.
|
|---|