Skip to content
Official PYQ · 2026

GATE CS 2026 Set 2 Q28 — Asymptotic Worst Case Time and Space Complexity

Explain with AI

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}\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?

Choose one option
View worked solution

Answer: A

To find the worst-case time complexity of the fastest algorithm to check the given condition, let us simplify the mathematical statement.

Let D[k]=A[k+1]−A[k]D[k] = A[k+1] - A[k] for k=1,2,…,n−1k = 1, 2, \ldots, n-1. The given condition is:

∀i,j∈{1,…,n−1} such that i>j,D[i]>D[j]\forall i, j \in \{1, \ldots, n-1\} \text{ such that } i > j, \quad D[i] > D[j]

This condition states that for any index ii greater than jj, the difference D[i]D[i] must be strictly greater than D[j]D[j]. This is equivalent to saying that the sequence of differences must be strictly increasing:

D[1]<D[2]<D[3]<⋯<D[n−1]D[1] < D[2] < D[3] < \dots < D[n-1]

Algorithm to Check the Condition:

We can verify this condition by checking if each adjacent pair of differences is strictly increasing:

  1. Iterate through the array from k=1k = 1 to n−2n-2.
  2. For each kk, check if A[k+2]−A[k+1]>A[k+1]−A[k]A[k+2] - A[k+1] > A[k+1] - A[k].
  3. If the inequality is violated at any point, return False.
  4. If the loop completes without any violation, return True.

Complexity Analysis:

  • Time Complexity: The algorithm performs a single pass over the array of size nn, doing a constant number of operations at each step. This takes Θ(n)\Theta(n) time.
  • Lower Bound: Any algorithm must examine at least Ω(n)\Omega(n) elements in the worst case. If an algorithm skips even one element, an adversary can alter that element to violate the condition without the algorithm detecting it. Thus, we cannot do better than Θ(n)\Theta(n).

Therefore, the worst-case time complexity of the fastest algorithm is Θ(n)\Theta(n).

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Asymptotic Worst Case Time and Space Complexity questions