edited by
604 views
1 votes
1 votes

Consider a set of 156 elements to find minimum and maximum elements in the given set, the minimum number of comparisons required is___? You have given an array of 512 elements,minimum number of comparisons required to find out second largest element among all will be___?

  1.   230 & 517
  2.   229 & 516
  3.   231 & 518
  4.   232 & 519
edited by

1 Answer

1 votes
1 votes
The number of comparisons to find minimum and maximum simultaneously will be $3n/2-2$ if we put the value for n this will be 232

Now for the second one at first we have to find the largest element using the tournament search and number of comparison for this will be n-1.And each element is involved in comparison at most “logn” times.Second largest element will be one of the elements with which largest element is compared and largest element wins.So there will be at most “logn” number of elements.So the number of comparisons will be (n-1)+(logn-1) which n+logn-2.

Related questions

1 votes
1 votes
1 answer
2