retagged by
5,508 views

1 Answer

Best answer
4 votes
4 votes

we can start comparing the elements pair wise and build a decision tree in which case it takes n-1 comparisons to obtain the highest element.

In order to get the second highest element we need to check only those elements which were compared with the highest element while building the decision tree, now as the height of the tree is logn as logn comparisons are required for the highest element to reach the top, so to obtain second highest element one need logn-1 comparisons so all together n-1+logn-1=n+logn-2 comparisons are required.

selected by

Related questions

2 votes
2 votes
1 answer
1
yes asked Oct 6, 2015
1,390 views
for example array contain a[1 2 3 3 3 3 3 4 5] then retun(1)
8 votes
8 votes
2 answers
3
6 votes
6 votes
2 answers
4
radha gogia asked Jul 15, 2015
9,054 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...