IAE Academy

GATE 2026 CS2 Q.38: solution and answer

GATE 2026 · CS2Q.38 · 2 marks · MCQ

Consider an array of integers of size . The indices of run from to . An algorithm is to be designed to check whether satisfies the condition given below.

Which one of the following gives the worst case time complexity of the fastest algorithm that can be designed for the problem?

  1. (A)

  2. (B)

  3. (C)

  4. (D)

See the question in the paper

Answer and solution

ANSWER

The worst-case time complexity of the fastest algorithm is — option (A).

Official answer: ASource: Official answer key, GATE 2026 CS2 (IIT Guwahati)

  1. Let for — the sequence of consecutive differences of .

  2. The given condition says: for every pair in , . This is exactly the statement that , i.e. is strictly increasing.

  3. Strict inequality () is transitive, so it suffices to check only the consecutive pairs : if every adjacent pair satisfies , then by transitivity every non-adjacent pair with also satisfies .

  4. Algorithm (upper bound): scan the array once left to right, computing each in time and comparing it with the previous difference. This does arithmetic operations and comparisons in total, so the condition can be checked in time.

  5. Lower bound: whether satisfies the condition depends on every entry of — changing any single unread entry can change some and flip the answer. So any correct algorithm must inspect all entries in the worst case, giving .

  6. Since (achievable) meets (necessary), the worst-case time complexity of the fastest possible algorithm is — option (A).

KEY IDEA

A condition holding for every pair of indices (not just adjacent ones) is a disguised way of saying a derived sequence is strictly monotonic; strict monotonicity only ever needs to be checked between consecutive terms, because strict inequality is transitive.

WATCH OUT FOR

Assuming that a condition quantified over ALL pairs requires checking all pairs directly, leading to a wrongly assumed (or, worse, mistaking the transitivity shortcut for something that needs sorting, leading to a wrongly assumed ) — both miss that strict inequality between all pairs collapses to strict monotonicity, which is checkable with one linear pass over consecutive terms.

From the GATE 2026 CS2 paper. Every question of this paper · Download the full paper · All 14 Complexity questions, with notes

More Complexity questions