Skip to main content

GATE CSE 2026Algorithms › Growth of Functions & Complexity AnalysisVerified

GATE CSE 2026 PYQ: Consider an array A A A of integers of size n n n . The indices of A A A run from 1 1 1 to n n n . An…

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

∀i,j∈{1,…,n−1}\forall i, j \in\{1, \ldots, n-1\} such that i>j,(A[i+1]−A[i])>(A[j+1]−A[j])i>j,(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?

  1. A
    Θ(n)\Theta(n)
    Correct answer
  2. B
    Θ(log⁡(n))\Theta(\log (n))
  3. C
    Θ(nlog⁡(n))\Theta(n \log (n))
  4. D
    Θ(n2)\Theta\left(n^{2}\right)

Answer

(A) Θ ( n ) \Theta(n) Θ ( n )

Approach

Define the adjacent differences $d_i =$ A[i+1] - A[i] for i = 1, 2, ..., n-1. The condition says that for every pair i > j, $d_i$ > $d_j$. This is exactly the statement that the sequence $d_1, d_2, ..., d_{n-1}$ is strictly increasing. Therefore, it is enough to check only consecutive differences: verify $d_1$ < $d_2$ < ... < $d_{n-1}$. If all adjacent inequalities hold, transitivity guarantees all pairwise inequalities; otherwise the violating adjacent pair witnesses failure. This takes one linear scan of the array.

The condition ∀i,j with i>j: (A[i+1]-A[i]) > (A[j+1]-A[j]) is equivalent to saying the sequence of adjacent differences is strictly increasing. This can be checked by comparing each adjacent difference with the previous one in a single pass, giving Θ(n) time. Therefore option A is correct.

Reviewed by GateIQ Editorial Team: IIT & IISc Alumni.