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.

  1. A.

    a[j] - a[i] > S

  2. B.

    a[j] - a[i] < S

  3. C.

    a[i] - a[j] < S

  4. D.

    a[i] - a[j] > S

Attempted by 126 students.

Sign up free to check your answer

Sign up free

Explore the full course: Gate Guidance By Sanchit Sir

Loading lesson…