The GATE Grind

GATE 2015 CS (CS2) – Question 16

Algorithms · Asymptotic Analysis and Time/Space Complexity · 1 mark · Multiple choice

An unordered list contains n distinct elements. How many comparisons are needed to find any element that is neither its maximum nor minimum? Assume n≥3.

  1. $\Theta(n\log n)$
  2. $\Theta(n)$
  3. $\Theta(\log n)$
  4. $\Theta(1)$

Practise this question in The GATE Grind →

Show answer and explanation

Correct answer: (D) $\Theta(1)$

Explanation

Inspect any three elements and return their median, found using at most three comparisons. At least one selected element is smaller and another larger, so this median cannot be a global extreme. The work is independent of n, hence Θ(1), D.

More Asymptotic Analysis and Time/Space Complexity questions

All Asymptotic Analysis and Time/Space Complexity questions →