Let a be an array containing n integers in increasing order. The following…
GATE · 2005 · IT
Let a be an array containing n integers in increasing order. The following algorithm determines whether there are two distinct numbers in the array whose difference is a specified number S > 0.
C
i = 0;
j = 1;
while (j < n )
{
if (E) j++;
else if (a[j] - a[i] == S) break;
else i++;
}
if (j < n)
printf("yes")
else
printf ("no");
Choose the correct expression for E.
- A.
a[j] - a[i] > S
- B.
a[j] - a[i] < S
- C.
a[i] - a[j] < S
- D.
a[i] - a[j] > S
Attempted by 126 students.
Sign up free to check your answer
Sign up freeLoading lesson…