IAE Academy

GATE 2025 CS2 Q.41: solution and answer

GATE 2025 · CS2Q.41 · 2 marks · MCQ

An array of length with distinct elements is said to be bitonic if there is an index such that is sorted in the non-decreasing order and is sorted in the non-increasing order.

Which ONE of the following represents the best possible asymptotic bound for the worst-case number of comparisons by an algorithm that searches for an element in a bitonic array ?

  1. (A)

  2. (B)

  3. (C)

  4. (D)

See the question in the paper

Answer and solution

ANSWER

The best possible worst-case bound is — option D.

Official answer: DSource: Official answer key, GATE 2025 CS2 (IIT Roorkee)

  1. A bitonic array rises (non-decreasing) up to some peak index and then falls (non-increasing) after it; since all elements are distinct, both the rising part and the falling part are strictly monotonic.

  2. Stage 1 — locate the peak in comparisons: at a probe index , compare with its neighbours. If the peak lies to the right; if it lies to the left; otherwise itself is the peak. Each such probe (a constant number of comparisons) discards half the remaining range, exactly like binary search, so the peak index is found using comparisons.

  3. Stage 2 — search each monotonic half: once is known, is sorted ascending and is sorted descending. An ordinary binary search for the target on costs comparisons, and a binary search (with the inequality direction reversed) on also costs comparisons. In the worst case the target can require probing both halves, but that only adds two terms.

  4. Total worst-case cost: (find peak) (binary search the halves) .

  5. This bound is also the best possible one: searching for an arbitrary target among distinct candidate values, using only comparisons, is a decision problem with (or , including "not found") possible outcomes, so any comparison-based search algorithm needs comparisons in the worst case, on any array — bitonic or otherwise. Combining the matching upper and lower bounds gives a worst-case comparison count of .

  6. This rules out the other options: is what a naive linear scan gives, far more than necessary; is impossible because the target can be any one of values and the algorithm must in general inspect enough elements to distinguish among them; is achievable (e.g. binary searching both halves without first locating the peak) but is not the best possible bound, since the two-stage algorithm above already achieves the smaller . Hence the correct choice is option D.

KEY IDEA

A bitonic array can be searched in two binary-search-style stages — first locate the peak (the point where the array switches from ascending to descending), then binary-search whichever monotonic half is needed — giving comparisons; since any comparison-based search over distinct values needs comparisons in the worst case, the tight, best-possible bound is .

WATCH OUT FOR

Assuming a bitonic array needs comparisons because it "looks like" you must binary-search twice (once to find the peak, once inside a half) and multiplying the two stages together instead of adding them — the two stages are sequential (add), not nested (multiply), so the total stays , not .

From the GATE 2025 CS2 paper. Every question of this paper · Download the full paper · All 18 Sorting & hashing questions, with notes

More Sorting & hashing questions