2 votes 2 votes How many comparisons are there for finding any second element that is neither minimum or maximum. 10 5 50 70 80 2 3 Algorithms algorithms time-complexity sorting + – gari asked Jun 21, 2017 retagged Jun 23, 2022 by makhdoom ghaya gari 1.1k views answer comment Share Follow See all 3 Comments See all 3 3 Comments reply Niraj Singh 2 commented Jun 21, 2017 reply Follow Share what is meaning of 2nd element . if we sort array in ascending order , 2,3,5,10,50,70,80 , from left 5 is 2nd element which is neither max or min but if sort it in descending order 80,70,50,10,5,3,2 then from left , 50 is 2nd element which is neither max or minimum. can u provide more detail explanation for ur question? 0 votes 0 votes junaid ahmad commented Jun 21, 2017 reply Follow Share http://www.geeksforgeeks.org/gate-gate-cs-2015-set-2-question-32/ 1 votes 1 votes gari commented Jun 21, 2017 reply Follow Share any second element that is neither a min nor max. 0 votes 0 votes Please log in or register to add a comment.
0 votes 0 votes take first five element and sort them pick tne 3rd element which is 2nd nither maximam nor minimam . it will takeO(nlogn) time SO total comprasons = 5log5= 12 comprasons. abhishekmehta4u answered Apr 1, 2018 abhishekmehta4u comment Share Follow See all 0 reply Please log in or register to add a comment.
0 votes 0 votes Take any 3elements. Compare them with each other. It will take exactly 3comparisons. The element which is neither highest nor the lowest of the three picked is your number. So in constant time you can do this. Precisely 3comparisons only yuyutsu answered Oct 9, 2023 yuyutsu comment Share Follow See all 0 reply Please log in or register to add a comment.
–1 votes –1 votes best way is, build heap(either max or min)..it will take 8 comparisons...now A[0] will be maximum and A[1] will be neither max nor min.. hence total '8' comparisons... joshi_nitish answered Jun 21, 2017 joshi_nitish comment Share Follow See all 3 Comments See all 3 3 Comments reply gari commented Jun 21, 2017 reply Follow Share if we can just find out the middle element in the sorted array suppose sorted array is 2,3,5,10,50,70,80 and middle is 5 and it's neither max nor min. if we find 2 max and 2 minimum OR if we find the 3rd minimum so 3rd minimum is neither the first 2 minimums and nor the last 2 maximums. Please throw some light. 0 votes 0 votes joshi_nitish commented Jun 22, 2017 reply Follow Share ohh sorry, it can be done by taking any 3 elements and compare among them.. 0 votes 0 votes gari commented Jun 22, 2017 reply Follow Share i think we should consider first five elements because in worst case it could contain 2 minimum's and 2 maximum's and the left element would be the desired one... if we do so ....taking first five 10 5 50 70 80 then how many comparisons amongst them to find out that 50 is the desired element? 0 votes 0 votes Please log in or register to add a comment.