Aspire's Library

A Place for Latest Exam wise Questions, Videos, Previous Year Papers,
Study Stuff for MCA Examinations - NIMCET

Previous Year Question (PYQs)



The second smallest of $n$ elements can be found with __________ comparisons in the worst case.





Solution

To find the second smallest element, first find the smallest element using tournament method.

Finding the smallest element requires:

$n-1$ comparisons

The smallest element can lose comparisons against at most:

$\lceil \log n\rceil$ elements

Now, to find the second smallest among these elements, comparisons required are:

$\lceil \log n\rceil-1$

Total comparisons:

$(n-1)+(\lceil \log n\rceil-1)$

$=n+\lceil \log n\rceil-2$



Online Test Series,
Information About Examination,
Syllabus, Notification
and More.

Click Here to
View More


Online Test Series,
Information About Examination,
Syllabus, Notification
and More.

Click Here to
View More

Ask Your Question or Put Your Review.

loading...