Open In App
Related Articles

Algorithms | Misc | Question 13

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

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: 

C

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
Please comment below if you find anything wrong in the above post

Last Updated : 28 Jun, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads