Home » Programming & Data Structure » Programming and data structure miscellaneous » Question

Programming and data structure miscellaneous

Programming & Data Structure

  1. A set X can be represented by an array x [n] as follows

    Consider the following algorithm in which x, y and z are Boolean arrays of size n:
      algorithm zzz (x[], y[], z []) {
      int i;
      for (i = 0; i < n; + + i)
       z [i] = (x[i] ^ ∼ y [i] ∨ ( ∼ x [i] ^ y [i])
    }
    The set Z computed by the algorithm is
    1. (X ∪ Y )
    2. (X ∩ Y)
    3. (X – Y) ∩ (Y – X)
    4. (X – Y) ∪ (Y – X)
Correct Option: D

The condition given in the FOR loop is
z[i] = {x[i] ∧ ∼ y[i]} ∨ (∼ x[i] ∧ y[i])
Now, we clearly can see that the condition reflect the XOR operation and in the XOR operation set obtained is (X ∩ Y') ∪ (X' ∩ Y)
Since, the formula is X ∩ Y' = X' – Y
Result obtained is (X – Y) ∪ (Y – X)



Your comments will be displayed only after manual approval.