Skip to content
Related Articles
Get the best out of our app
GFG App
Open App
geeksforgeeks
Browser
Continue

Related Articles

Algorithms | Analysis of Algorithms | Question 17

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

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? (GATE CS 2000)
a) t (n) is 0 (1)
b) n < t (n) < n {log_2 n}
c) n log 2 n < t (n) < {n \\choose 2}
d) t (n) = {n \\choose 2}

(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 the last two elements. For an array data structure, the number of operations is fixed in both cases and not dependent on n, Therefore the complexity is O(1)


Quiz of this Question
Please comment below if you find anything wrong in the above post

My Personal Notes arrow_drop_up
Last Updated : 28 Jun, 2021
Like Article
Save Article
Similar Reads