retagged by
2,173 views
3 votes
3 votes

Consider an array contains 2k distinct elements. How many comparisons are needed to find the smallest and the second smallest elements in the given array?

  1.  2k comparisons
  2.   2k-2 comparisons
  3.   2k + k -2 comparisons
retagged by

1 Answer

Best answer
5 votes
5 votes

To understand easily we take an example for any k.(here i assumed k=2)

Now we have 4 distinct elements.

No of comparisons to get smallest of them = 3

Now to get second smallest we need to compare  between the elements that are compared with smallest element.

Here 2 and 3 are compared with smallest element.

So 1 comparsion among them ==>Total = 4 comparisons.

For $2^{k}$ elements we need $2^{k} + k - 2$ comparisons.

selected by

Related questions

1 votes
1 votes
3 answers
1
Rohan Mundhey asked Nov 9, 2016
1,043 views
Consider an array of 19 elements, Find the minimum number of comparisons required to find minimum and maximum elements in an array
3 votes
3 votes
3 answers
2
Himanshu1 asked Dec 16, 2015
1,599 views