Question 11090 – Programming
January 16, 2024Question 11095 – Programming
January 16, 2024Question 11094 – Programming
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.
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.
Correct Answer: B
Question 4 Explanation:
For some ‘i’ if we find that difference of (A[j] – A[i] < S) we increment ‘j’ to make this difference wider so that it becomes equal to S.
If at times difference becomes greater than S we know that it won’t reduce further for same ‘i’ and so we increment the ‘i’.
If at times difference becomes greater than S we know that it won’t reduce further for same ‘i’ and so we increment the ‘i’.
a[j] – a[i] > S
a[j] – a[i] < S
a[i] – a[j] < S
a[i] – a[j] > S
