Let be a sorted array of integers. Let denote the time taken for the most efficient algorithm to determined if there are two elements with sum less than in . Which of the following statement is true?
View worked solution
Answer: A
Since the array of integers is already sorted in non-decreasing order, we have:
To determine if there exist any two elements in whose sum is less than , we only need to look at the two smallest elements in the array, which are and :
- Case 1 (): It is impossible to find two elements, so the answer is immediately
false. This takes time. - Case 2 (): The minimum possible sum of any two distinct elements in is .
- If , then we have found two elements whose sum is less than .
- If , then for any other pair of indices , we have . Thus, no such pair can exist.
Therefore, the problem reduces to checking if . Since array indexing, addition, and comparison are basic operations that take constant time, the most efficient algorithm runs in time.
Thus, is .
Free practice · Your answers on this page are not saved.
