• retagged by
2,128 views
2 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

3 Answers

0 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.

0 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
–1 –1 vote
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...
Position:
Show:

Related questions

0 0 votes
1 answers 1 answer
6.9k
6.9k views
soorajchn asked Mar 14, 2015
6,850 views
a) n- ( lg(n)) - 2b) n + (lg(n)-2)
2 2 votes
1 1 answer
2.2k
2.2k views
yes asked Oct 6, 2015
2,208 views
for example array contain a[1 2 3 3 3 3 3 4 5] then retun(1)
2 2 votes
1 answers 1 answer
6.1k
6.1k views
Nandkishor3939 asked Jan 15, 2019
6,073 views
I was going through the heap concept and one question came into my mind what will be the best case time complexity of finding the minimum element in a max heap?Thank you:...