Skip to content
Related Articles

Related Articles

Save Article
Improve Article
Save Article
Like Article

Algorithms | Misc | Question 13

  • Last Updated : 28 Jun, 2021

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

gate_2006_50

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=O; i<n; ++i)
     z[i] = (x[i] ^ ~y[i]) V (~x[i] ^ y[i])
}

The set Z computed by the algorithm is:
(A) (X Intersection Y)
(B) (X Union Y)
(C) (X-Y) Intersection (Y-X)
(D) (X-Y) Union (Y-X)


Answer: (D)

Explanation: The expression x[i] ^ ~y[i]) results the only 1s in x where corresponding entry in y is 0. An array with these set bits represents set X ā€“ Y
The expression ~x[i] ^ y[i]) results the only 1s in y where corresponding entry in x is 0. An array with these set bits represents set Y ā€“ X.
The operator ā€œVā€ results in Union of the above two sets.

Quiz of this Question

My Personal Notes arrow_drop_up
Recommended Articles
Page :