Recall & Review
beginner Click to reveal answer
What is the main idea behind generating subsets using bitmask?
Each subset corresponds to a binary number where each bit represents whether an element is included (1) or excluded (0) from the subset.
beginner Click to reveal answer
How many subsets can be generated from a set of size n using bitmask?
There are 2^n subsets because each element can either be included or excluded independently.
intermediate Click to reveal answer
In C++, how do you check if the j-th element is included in the subset represented by bitmask i?
Use the expression (i & (1 << j)) != 0. If true, the j-th element is included.
intermediate Click to reveal answer
Why is bitmask generation of subsets efficient compared to recursive methods?
It uses simple bit operations and loops, avoiding function call overhead and making it easy to implement and understand.
beginner Click to reveal answer
What is the output of subsets generated by bitmask for the set {a, b}?
The subsets are: {}, {a}, {b}, {a, b}.
How many subsets does a set with 3 elements have?
✗ Incorrect
A set with n elements has 2^n subsets. For n=3, 2^3 = 8.
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 include a (bit 0) and c (bit 2).
Which operation checks if an element is in the subset using bitmask?
✗ Incorrect
The & operator with (1 << j) checks if the j-th bit is set.
What is the total number of subsets for an empty set?
✗ Incorrect
The empty set has exactly one subset: the empty set itself.
Which of these is NOT a subset of {x, y}?
✗ Incorrect
{x, y, z} contains an element not in the original set, so it is not a subset.
Explain how to generate all subsets of a set using bitmasking.
Think of binary numbers as switches for elements.
You got /3 concepts.
Describe how to check if the j-th element is in a subset represented by a bitmask integer.
Use & operator and bit shifting.
You got /3 concepts.
