edited by
3,695 views
3 votes
3 votes

Given an integer array of size $N$, we want to check if the array is sorted (in either ascending or descending order). An algorithm solves this problem by making a single pass through the array and comparing each element of the array only with its adjacent elements. The worst-case time complexity of this algorithm is

  1. both $\mathrm{O}(N)$ and $\Omega(N)$
  2. $\mathrm{O}(N)$ but $\operatorname{not} \Omega(N)$
  3. $\Omega(N)$ but not $\mathrm{O}(N)$ 
  4. neither $\mathrm{O}(N)$ nor $\Omega(N)$
edited by

1 Answer

4 votes
4 votes
The objective of the algorithm is to check whether the array is sorted or not, and it does so by making a single pass through the array.

For this the worst case will be when the array is already sorted.

So, for this worst case, the algorithm has to traverse the whole array and in doing so it will take $O(n)$ time when specified in $O(.)$ notation or $\Omega(n)$ time when specified in $\Omega(.)$ notation.

Answer - A
Answer:

Related questions

1 votes
1 votes
1 answer
1
Arjun asked Feb 16
2,650 views
​​​​​An array $[82,101,90,11,111,75,33,131,44,93]$ is heapified. Which one of the following options represents the first three elements in the heapified array?$...