Similar questions 1 more →
Searching, Sorting & Selection

Answer & solution
Official answer: A
Approach: Big-O and big-Omega describe upper and lower bounds on the same worst-case running-time function; they are not synonyms for worst case and best case.
1. Maintain whether any adjacent pair increases and whether any adjacent pair decreases. Each of the N−1 adjacent pairs requires only constant work. The single pass therefore takes at most cN+d operations, giving O(N).
2. On an already sorted array, no early contradiction occurs. The algorithm must examine through the final adjacent pair to certify the property. Such an input requires a number of comparisons proportional to N, giving a worst-case Ω(N) lower bound.
3. Together these bounds give Θ(N).
Answer: A. Some unsorted inputs may allow early termination, but that does not remove the linear worst-case lower bound.