Recall & Review
beginner Click to reveal answer
What is the main idea behind generating subsets using bitmask?
Each subset can be represented by a binary number where each bit indicates whether an element is included (1) or excluded (0) from the subset.
beginner Click to reveal answer
How many subsets does a set with n elements have?
A set with n elements has 2^n subsets, including the empty set and the set itself.
intermediate Click to reveal answer
In C#, how do you check if the j-th bit in an integer i is set (1)?
Use the expression: (i & (1 << j)) != 0. It returns true if the j-th bit is 1, false otherwise.
intermediate Click to reveal answer
Why is bitmasking an efficient way to generate subsets?
Because it uses simple bitwise operations to represent inclusion/exclusion, avoiding recursion and reducing complexity in code.
beginner Click to reveal answer
What is the output of subsets generation using bitmask for the set [1, 2]?
The subsets are: [] (empty), [1], [2], [1, 2].
How many subsets will be generated for a set of 3 elements using bitmask?
✗ Incorrect
A set with 3 elements has 2^3 = 8 subsets.
What does the bitmask 0101 represent for a set [a, b, c, d]?
✗ Incorrect
Bits from right to left represent elements [a, b, c, d]. 0101 means bits 0 and 2 are set, so elements a and c are included.
Which operator is used to check if a bit is set in bitmasking?
✗ Incorrect
The bitwise AND operator (&) is used to check if a specific bit is set.
What is the time complexity of generating all subsets using bitmask for n elements?
✗ Incorrect
There are 2^n subsets and each subset can take up to n steps to build, so total complexity is O(2^n * n).
In C#, what does (1 << j) do?
✗ Incorrect
(1 << j) shifts the binary 1 left by j positions, creating a mask to check or set the j-th bit.
Explain how to generate all subsets of a set using bitmasking in C#.
Think of binary numbers as switches for elements.
You got /4 concepts.
Describe the advantages of using bitmasking for subset generation compared to recursion.
Consider performance and code simplicity.
You got /4 concepts.
