Array max()

Accepted Reply

Does max() sort the array first?

No, it scans the unordered array from first to last.


Generally simple max() takes O(n), and sorting takes O(n*log(n)). Sorting is not a good starategy when you need one maximum value.


One more, `max()` is a method defined in Swift Standard Library, so, Cocoa Touch is not a good place to ask.

Replies

Does max() sort the array first?

No, it scans the unordered array from first to last.


Generally simple max() takes O(n), and sorting takes O(n*log(n)). Sorting is not a good starategy when you need one maximum value.


One more, `max()` is a method defined in Swift Standard Library, so, Cocoa Touch is not a good place to ask.