Skip to content
Official PYQ · 2014

GATE CS 2014 Set 1 Q39 — Searching, Sorting, Hashing

Explain with AI
The minimum number of comparisons required to find the minimum and the maximum of 100100 numbers is ________
View worked solution

Answer: 147.1 : 148.1

To find both the minimum and maximum of nn elements with the minimum number of comparisons, we use the optimal pairwise comparison algorithm.

Algorithm Strategy:
  • Case 1: nn is even
    • Compare the first two elements to initialize min and max. This takes 11 comparison.
    • Process the remaining n−2n - 2 elements in pairs. For each pair: compare the two elements with each other (1 comparison), compare the smaller element with the current min (1 comparison), and compare the larger element with the current max (1 comparison). This requires 33 comparisons per pair.
    • Total comparisons = 1+3×(n−22)=3n2−21 + 3 \times \left(\frac{n - 2}{2}\right) = \frac{3n}{2} - 2.
  • Case 2: nn is odd
    • Initialize both min and max to the first element (0 comparisons).
    • Process the remaining n−1n - 1 elements in pairs.
    • Total comparisons = 3×(n−12)=3n−323 \times \left(\frac{n - 1}{2}\right) = \frac{3n - 3}{2}.
Calculation for n=100n = 100:

Since 100100 is an even number, we use the formula for even nn:

Total comparisons=3×1002−2=150−2=148\text{Total comparisons} = \frac{3 \times 100}{2} - 2 = 150 - 2 = 148

Thus, the minimum number of comparisons required is 148.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Searching, Sorting, Hashing questions