GATE | GATE-CS-2006 | Question 54
Suppose we have a set {1, 2, 3}. Find the XOR of all the subsets of the set.
(A)
1
(B)
2
(C)
3
(D)
0
Answer: (D)
Explanation:
The XOR of all the subsets of any set is always 0 when n > 1 and Set[0] when n is 1.
Because, When we apply XOR on all the subsets of a set, we can use the commutative and associative property of XOR which reduces the problem to finding XOR result of each element that depends on the total number of occurrences of each element. Eg. XOR([{1}, {2}, {3}, {1, 2}, {1, 3}, {2, 3}, {1, 2, 3}]) = XOR(XOR(1,1,1,1), XOR(2,2,2,2), XOR(3,3,3,3)) = 0
Let us consider n’th element, it can be included in the power set of remaining (n-1) elements. The number of subsets for (n-1) elements is equal to 2(n-1) which is always even when n>1. Thus, in the XOR result, every element is included even number of times, and the XOR of even occurrences of any number is 0.
Hence Option (D) is correct.
Quiz of this Question
Please comment below if you find anything wrong in the above post
Last Updated :
09 Sep, 2021
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...