GATE / CS ARCHIVE

GATE CSE 2008 / QUESTION 40

Majority test in a sorted array

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

GATE 2008, Q40 2 marks · MCQ
Report issue

Searching, Sorting & Selection

Question 40, GATE 2008: What is the minimum worst-case number of comparisons needed to determine whether some integer appears more than n/2 times in a sorted array of n integers?

(A) Θ(n)
(B) Θ(log n)
(C) Θ(log* n)
(D) Θ(1)
Tap to enlarge
Your answer
Answer & solution

Answer: B (no official key was published)

1. If a value occurs more than n/2 times, it must occupy the middle array position. Take that value as candidate and use binary searches for its first and last occurrences; accept exactly when the count exceeds n/2.
2. This needs Θ(log n) comparisons in the worst case. A logarithmic lower bound follows by locating a candidate-block boundary among linearly many possible positions while distinguishing length floor(n/2) from floor(n/2)+1.
3. Sortedness is essential; without it a linear majority scan is needed. Thus B.

Original paper, page 7