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.
(A) a[j] – a[i] > S
(B) a[j] – a[i] < S
(C) a[i] – a[j] < S
(D) a[i] – a[j] > S
Answer: (B)
Explanation: Please see the link below for full explanation
https://www.geeksforgeeks.org/find-a-pair-with-the-given-difference/amp/
Quiz of this Question