Array max()

Does max() sort the array first?

Answered by OOPer in 283911022

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.

Accepted Answer

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.

Array max()
 
 
Q