GATE / CS ARCHIVE

GATE CSE 2026 SET 2 / QUESTION 38

Checking increasing adjacent differences

Algorithms · Correctness, Invariants & Design · Full GATE CSE 2026 Set 2 paper

GATE 2026 Set 2, Q38 2 marks · MCQ
Report issue

Correctness, Invariants & Design

Question 38, GATE 2026: For integer A[1…n], determine whether for every i>j in {1,…,n−1}, A[i+1]−A[i] > A[j+1]−A[j]. Choose optimal worst-case time: A Θ(n); B Θ(log n); C Θ(n log n); D Θ(n²).
Tap to enlarge
Your answer
Answer & solution

Official answer: A

Givens and goal

For integer A[1…n], determine whether for every i>j in {1,…,n−1}, A[i+1]−A[i] > A[j+1]−A[j]. Choose optimal worst-case time: A Θ(n); B Θ(log n); C Θ(n log n); D Θ(n²).

Approach

Reduce all pairwise comparisons to adjacent comparisons using transitivity.

Step-by-step solution

1. Define d_i=A[i+1]−A[i]. The condition says each later difference is larger than every earlier one. This is equivalent to d_1<d_2<…<d_(n−1).
2. The forward implication includes all adjacent pairs. Conversely, if adjacent inequalities hold, chaining d_j<d_(j+1)<…<d_i proves the required inequality for every i>j.
3. Algorithm: if n≤2 return true; set previous=A[2]−A[1]; for i=2,…,n−1 set current=A[i+1]−A[i]; if current≤previous return false; otherwise set previous=current. If the loop ends return true. Only O(1) extra storage is needed.
4. The loop uses O(n) time. For a lower bound, consider a valid array such as A[i]=i², whose differences are strictly increasing. If any position is unread, an adversary can change that entry sufficiently to violate a neighboring comparison while leaving all inspected values unchanged. Thus worst-case inspection requires Ω(n) entries for n≥3.
5. The optimal bound is Θ(n), A. Use sufficiently wide arithmetic so subtraction does not overflow; the proof is in the mathematical-integer model.

Original paper, page 25 · Answer key