GATE / CS ARCHIVE

GATE CSE 2015 SET 2 / QUESTION 16

GATE CSE 2015 Set 2 Q16

Algorithms · Searching, Sorting & Selection · Full GATE CSE 2015 Set 2 paper

GATE 2015 Set 2, Q16 1 mark · MCQ
Report issue

Searching, Sorting & Selection

Question 16, GATE 2015: An unordered list has n distinct elements. What is the asymptotic number of comparisons needed to find an element that is neither maximum nor minimum? AΘ(nlogn), BΘ(n), CΘ(logn), DΘ(1), assuming n≥3.
Tap to enlarge
Your answer
Answer & solution

Official answer: D

Assuming n≥3, inspect any three distinct elements and return their median using at most three comparisons. It has a smaller and larger element within those three, so cannot be the global minimum or maximum. A constant positive number of comparisons suffices and is necessary, Θ(1), D.

Choose any three distinct list elements and compare them to identify their middle value. That value is larger than one chosen element and smaller than another, so it cannot be an extreme of the full list. This uses at most three comparisons regardless of n. At least some information is needed to certify a nonextreme value on arbitrary unsorted data, so the asymptotic requirement is constant. For n<3 no such value exists, which is why that natural premise is stated.

Original paper, page 32 · Answer key