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, giving 2 choices per element.
intermediate Click to reveal answer
In Go, how do you check if the j-th bit in an integer i is set?
Use the expression (i & (1 << uint(j))) != 0 to check if the j-th bit is 1.
intermediate Click to reveal answer
Why is bitmask method efficient for generating subsets compared to recursion?
Bitmask uses simple bit operations and loops, avoiding function call overhead and making it easy to implement iteratively.
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 3 elements has 2^3 = 8 subsets.
Which bitwise operation checks if a bit is set in bitmask?
✗ Incorrect
AND (&) operation with a mask checks if a specific bit is set.
What does the bitmask 0101 represent for a set [a, b, c, d]?
✗ Incorrect
Bits 0 and 2 are set (counting from 0), so elements a and c are included.
What is the time complexity of generating all subsets using bitmask for n elements?
✗ Incorrect
There are 2^n subsets, so the time complexity is O(2^n).
In Go, what does (1 << j) do?
✗ Incorrect
(1 << j) shifts the number 1 to the left by j bits, creating a mask with only the j-th bit set.
Explain how to generate all subsets of a set using bitmasking.
Think of each subset as a number where bits tell which elements to pick.
You got /4 concepts.
Describe how to check if an element should be included in a subset using bitmask in Go.
Use (i & (1 << uint(j))) != 0 to check the j-th bit.
You got /3 concepts.
