Open In App

GATE | GATE-CS-2000 | Question 15

Let s be a sorted array of n integers. Let t(n) denote the time taken for the most efficient algorithm to determined if there are two elements with sum less than 1000 in s. which of the following statements is true?
a) t (n) is O(1)
b) n < t (n) < n 
c) n log 2 n < t (n) < 
d) t (n) = [/Tex]{n \choose 2} [/Tex] 
(A) a (B) b (C) c (D) d
Answer:(A)
Explanation: Let array be sorted in ascending order, if sum of first two elements is less than 1000 then there are two elements with sum less than 1000 otherwise not. For array sorted in descending order we need to check last two elements. For an array data structure, number of operations are fixed in both the cases and not dependent on n, complexity is O(1)
Quiz of this Question
Article Tags :