Let B[1...n] be an array of integers. To express that no integer occurs twice in the B We may write? (check all the answers that apply)
a) forall i 1..n forall j in 1...n B[i] != B[j]
b)for all i in 1...n forall j in 1...n, i != j => B[i] !=B[j]
c)forll i in 1...n forall j in 1...n i != j and B[i] != B[j]
d)forall i in 1...n forall j in 1...n B[i] =B[j] => i=j
e)forall i in 1...n-1 B[i] != B[i+1]
b)for all i in 1...n forall j in 1...n, i != j => B[i] !=B[j]
c)forll i in 1...n forall j in 1...n i != j and B[i] != B[j]
d)forall i in 1...n forall j in 1...n B[i] =B[j] => i=j
Explanation: to say that an integer at position i is not repeated again we have to check at every position from 1 to n other than i such that none of the integers at these positions should be equal to the integer at i. This should be checked for all positions from 1 to n to say that no integer occurs twice.
Why not a) forall i 1..n forall j in 1...n B[i] != B[j] ?
This will compare an integer at position i with itself and gives wring result
why not e)forall i in 1...n-1 B[i] != B[i+1] ?
This will check adjacent elements only.
Get Answers For Free
Most questions answered within 1 hours.