retagged by
315 views

1 Answer

1 votes
1 votes
To find an element that is neither the 2nd minimum nor the 2nd maximum, We can pick any five elements from the array and sort them...the middle element of these five elements will be guaranteed to be a number which is neither the 2nd minimum nor the 2nd maximum,

Hence, let's pick the first five elements of the array and apply Insertion sort on them. We will, in worst case, have to make $10$ comparisons. And time complexity of this algorithm will be $O(1)$.

Related questions

0 votes
0 votes
1 answer
1
Shankar Jha asked Jun 15, 2018
603 views
Assume that merge sort algorithm in the worst case takes 30 seconds for an input of size 64 which of The following most closely approximates the maximum input size of a p...
2 votes
2 votes
3 answers
2
Jyoti Kumari97 asked May 25, 2019
6,021 views
Question:$T(1)=1$$T(n) = 2 T(n - 1) + n$evaluates to?Can anyone solve it by substitution method?Given answer $T(n) = 2^{n+1} - (n+2)$How?
0 votes
0 votes
3 answers
3
Priyanka Agarwal asked Jul 11, 2018
1,068 views
3 votes
3 votes
2 answers
4