0 votes 0 votes naveen bhatt asked Jan 23, 2019 naveen bhatt 264 views answer comment Share Follow See all 2 Comments See all 2 2 Comments reply Swapnil Naik commented Jan 24, 2019 reply Follow Share If I have an array of n elements {1,2,3,4,5,6,7} or may be unsorted the possible outputs of this array are 3,4,5,6,7 and there will be always two elements which will be always less than all elements. I can find those 2 small elements in $\theta(n)$ time, and can print the rest again in $\theta(n)$ time, so the overall complexity becomes O(n). 1 votes 1 votes OneZero commented Jan 24, 2019 reply Follow Share consider S as 1,5,6,3,8,2 itr 1 : select first 3 elements i.e.. 1,5,6. compare it to find largest element which takes O(1). Function returns 6. itr 2 : take the left out numbers i.e.. 1,5 and compare it with the next element in the array i.e.. 3. Function returns 5. itr 3 : 1,3,8. Function returns 8. itr 4 : 1,3,2. Function returns 3. O(n) BUT @Swapnil Naik solution is better than mine as it takes less no.of comparisons. 0 votes 0 votes Please log in or register to add a comment.