GATE / CS ARCHIVE

GATE CSE 2007 / QUESTION 50

Comparison count to find both minimum and maximum

Algorithms · Searching, Sorting & Selection · Full GATE CSE 2007 paper

GATE 2007, Q50 2 marks · MCQ
Report issue

Searching, Sorting & Selection

Question 50, GATE 2007: Given an array of an even number n of values, both its minimum and maximum must be found. Which comparison-count claim is true?
Options:
(A) At least 2n−c comparisons are necessary for some constant c
(B) At most 1.5n−2 comparisons are sufficient
(C) At least n log₂ n comparisons are necessary
(D) None of these
Tap to enlarge
Your answer
Answer & solution

Answer: B (no official key was published)

1. Approach. A comparison within a pair simultaneously rules one element out as maximum and the other out as minimum. Exploit this dual use before separately reducing the two candidate sets.

2. Derivation and interpretation. Partition the even number n of values into n/2 pairs. Compare within each pair, putting its smaller member in a minimum-candidate set and larger member in a maximum-candidate set. Find the minimum of the n/2 smaller values and maximum of the n/2 larger values. The comparison count is n/2+(n/2−1)+(n/2−1)=3n/2−2, so B. This construction disproves the claimed asymptotically larger lower bounds in A and C.

Original paper, page 12