I was just thinking today that the best approach to find two smallest numbers in any array would be to first sort(ascending order) it with some efficient algorithm like Quicksort
(Average case complexity: nlogn
) and then access the first two members of the array in O(1)
.
Is my approach optimal or there are some alternative better approaches?