Consider an array π΄ of integers of size π. The indices of π΄ run from 1 toβ¦
2026
Consider an array π΄ of integers of size π. The indices of π΄ run from 1 to π. An algorithm is to be designed to check whether π΄ satisfies the condition given below
βπ,π β {1, β¦ , π β 1} such that π > π, (π΄[π + 1] β π΄[π]) > (π΄[π + 1] β π΄[π])
Which one of the following gives the worst case time complexity of the fastest algorithm that can be designed for the problem?
- A.
Ξ(n)
- B.
Ξ(logβ‘n)
- C.
Ξ(nlogβ‘n)
- D.
Ξ(n2)
Attempted by 78 students.
Show answer & explanation
Correct answer: A
The given condition requires checking if the difference between consecutive elements is strictly increasing for all valid indices.
Let D[i] = A[i+1] - A[i]. The condition becomes D[i] > D[j] for all i > j, which implies the sequence D must be strictly increasing.
We can compute all D values and verify the increasing order in a single pass through the array. This involves O(n) operations to calculate differences and O(n) to check the order.
Thus, the total time complexity is Ξ(n), as we only need to traverse the array once to validate the property.