Question

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

∀i,j∈{1,…,n−1} such that i>j,(A[i+1]−A[i])>(A[j+1]−A[j])\forall i, j \in \{1, \dots, n - 1\} \text{ such that } i > j, \quad (A[i + 1] - A[i]) > (A[j + 1] - A[j])

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

Choose one option
Official answer and solution
Official answer
A
From
Official GATE 2026 answer key

Solution

Observe that the condition simply states that the adjacent difference sequence D[k]=A[k+1]−A[k]D[k] = A[k+1] - A[k] is strictly increasing.

Let D[k]=A[k+1]−A[k]D[k] = A[k+1] - A[k] for k=1,…,n−1k = 1, \dots, n-1. By transitivity of >>, the condition D[i]>D[j]D[i] > D[j] for all i>ji > j holds if and only if D[k+1]>D[k]D[k+1] > D[k] for every consecutive index k∈{1,…,n−2}k \in \{1, \dots, n-2\}. We can verify this in a single pass over the array in Θ(n)\Theta(n) time, and in the worst case every element of AA must be inspected at least once (Ω(n)\Omega(n)). Therefore, the optimal worst-case time complexity is Θ(n)\Theta(n).

Final answer

Option (A)

The answer is the one in the official GATE answer key. The solution is this site's own explanation.

Source

Paper
GATE 2026 Computer Science and Information Technology - Session 2 (CS2)
Question
38 of 65
Section
Computer Science and Information Technology

Report an error in this question

GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.