GATE / CS ARCHIVE

GATE CSE 2000 / QUESTION 1.15

Finding a small pair sum in a sorted array

Algorithms · Searching, Sorting & Selection · Full GATE CSE 2000 paper

GATE 2000, Q1.15 1 mark · MCQ
Report issue

Searching, Sorting & Selection

Question 1.15, GATE 2000: A sorted array s contains n integers. Determine whether two distinct elements sum to less than 1000. What is the most efficient asymptotic runtime, including choice O(1)?
Tap to enlarge
Your answer
Answer & solution

Answer: A (no official key was published)

Step 1: In ascending order, the smallest sum of two distinct positions is s[1]+s[2]. Every other pair replaces one or both elements by values at least as large.

Step 2: If that sum is below 1000, a qualifying pair exists; otherwise no pair can qualify. Only two accesses, an addition, and a comparison are needed.

Thus Θ(1), option A, for n≥2 with random-access storage. For n<2 return false immediately. Searching all pairs or applying a two-pointer scan is unnecessary for this inequality-existence question.

Original paper, page 2