GATE / CS ARCHIVE

SIMILAR QUESTIONS / ALGORITHMS

Find a non-extreme element from a constant-size sample

2 questions solved the same way, newest first. Back to Algorithms

How these are solved

Return a witness that is not an extreme without locating the global order statistic. Median of any3 is neither min nor max; smaller of any2 is not maximum.

1 mark · MCQ
Report issue

Searching, Sorting & Selection

Question 20, GATE 2025: An unordered list contains N distinct integers. In the comparison model, what is the minimum number of element comparisons needed to find any element that is not the largest? Assume N≥2.
Options: A. 1; B. N−1; C. N; D. 2N−1.
Tap to enlarge
Your answer
Answer & solution

Official answer: A

Compare any two distinct list elements, say a and b. If a<b, return a; otherwise return b. Because the keys are distinct, the returned key is strictly smaller than the other compared key, which also belongs to the list. This is already a certificate that the returned key is not the maximum of the entire list. We do not need to identify the maximum or inspect the other N−2 elements.

One comparison is sufficient and, in the worst-case comparison model, necessary. With zero comparisons there is no ordering evidence about the chosen element; arbitrary distinct input values could make it the largest. N−1 is the familiar bound for finding the actual maximum, which is a stronger problem. The assumption N≥2 is necessary: for N=1 no nonmaximum element exists. Answer: A.

Original paper, page 18 · Answer key

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