retagged by
1,137 views
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
retagged by

3 Answers

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.

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

Related questions

2 votes
2 votes
1 answer
1
yes asked Oct 6, 2015
1,329 views
for example array contain a[1 2 3 3 3 3 3 4 5] then retun(1)
0 votes
0 votes
1 answer
2
soorajchn asked Mar 14, 2015
5,452 views
a) n- ( lg(n)) - 2b) n + (lg(n)-2)
6 votes
6 votes
2 answers
4
radha gogia asked Jul 15, 2015
8,998 views
Assume that a CPU can process $10^8$ operations per second. Suppose you have to sort an array with $10^6$ elements. Which of the following is true? 1. Insertion sort will...