2 votes 2 votes An unordered list contains n distinct elements. Number of comparisons to find element larger than second minimum is O(1) O(n) None Algorithms algorithms time-complexity easy + – gate_forum asked Jan 16, 2019 • retagged Jun 22, 2022 by makhdoom ghaya gate_forum 647 views answer comment Share Follow See all 2 Comments See all 2 2 Comments reply garimanand commented Jan 17, 2019 reply Follow Share i think answer should be O(n) because we have given a list so to find second minimum it will take O(n) then we will iterate again to find the larger element than this second minimum for that we just need to take two var first in which we see whether this given element is greater than second min and using other we will ensure that it should be least large 0 votes 0 votes Satbir commented Jan 17, 2019 reply Follow Share O(1) time. 1 votes 1 votes Please log in or register to add a comment.
Best answer 1 votes 1 votes the trick here. since it is given that the list has distinct elements =>when we select any 3 numbers the largest of the 3 will always be greater than the second minimum. Number of comparisons to find element larger than second minimum suppose there are numbers 2,3,8,1,4,5,9 take any 3 no. lets take 3,8,1. select the greatest number from it i.e. 8. we need only 2 comparisons ( O(1) ) 8 > 2.... answer. Satbir answered Jan 17, 2019 • selected Feb 6, 2019 by Pragy Agarwal Satbir comment Share Follow See all 10 Comments See all 10 10 Comments reply Show 7 previous comments Verma Ashish commented Jan 17, 2019 reply Follow Share If you solved this question- https://gateoverflow.in/8113/gate2015-2-22 then you can get the logic begind it... Really good& tricky question..👍 0 votes 0 votes Satbir commented Jan 17, 2019 reply Follow Share It is not asking you to find second minimum element. It is asking you to find any no. Greater than second minimum. ----------------------------------------------------------------------------------------- Lets take a smaller problem for better understanding. If i give you a list and tell you to find any no. Greater than minimum element of list. Then you select 2 numbers and after selecting those 2 numbers 2 cases can be possible Case 1. In that 2 numbers it is possible that you have included the minimum element. so you compare the two numbers and display the greater one. Hence , it will be greater than the minimum element.(Since you compared it with the minimum no. of the list ) Case 2. In that 2 numbers the minimum element of list is not included. So you can display any one of them as output (since both are greater than minimum element of list ) but for your surity you select the greater number and display it. (Since it is greater than some element of the list =>it is definitely greater than minimum element of the list ). ------------------------------------------------------------------------------------------ Same is the case for selecting for a number greater than 2nd minimum element of list. Just for surity we are comparing the three selected numbers. (Since the greatest of the 3 numbers is greater than atleast 2 numbers => it will be definitely greater than the 2nd minimum element of the list ) 2 votes 2 votes Verma Ashish commented Jan 17, 2019 reply Follow Share @Satbir well explained.. Are you gate2020 aspirant? 0 votes 0 votes Please log in or register to add a comment.