Algorithms and Data Structures · Junior · Question 59 of 75
What is the complexity of finding the maximum of an unsorted array?
- 1O(1)
- ✓Correct answer: O(n)
- 3O(log n)
Explanation
Any element could be the maximum, so each one must be checked at least once. One pass with a running maximum is optimal. Sorting first would be O(n log n), slower than needed.