GATE / CS ARCHIVE

GATE CSE 2014 SET 1 / QUESTION 39

GATE CSE 2014 Set 1 Q39

Algorithms · Searching, Sorting & Selection · Full GATE CSE 2014 Set 1 paper

GATE 2014 Set 1, Q39 2 marks · NAT
Report issue

Searching, Sorting & Selection

Question 39, GATE 2014: What is the minimum worst-case number of comparisons needed to find both the minimum and maximum of 100 numbers?
Tap to enlarge
Answer & solution

Official answer: 147.1 to 148.1

Our answer: 148 worst-case comparisons

1. Method and setup. Finding extrema separately takes 99+99 comparisons and wastes information. Pair the elements: one comparison per pair identifies a candidate for the minimum and a candidate for the maximum. Thereafter only the pair-losers need participate in the minimum search and only the pair-winners in the maximum search.

2. Work through the result and its assumptions. Compare50 disjoint pairs. Find the minimum among 50 smaller values in 49 comparisons and maximum among 50 larger values in 49. Total 50+49+49=148. This matches the optimal worst-case lower bound ceil(3n/2)−2; an adversary forces enough first comparisons to classify candidates before eliminating all but one in each class.

Original paper, page 17 · Answer key