Math Fundamentals18 sections · 814 units
Open in Course

Subset Operations

Union, intersection, difference

When subsets are represented as bitmasks, set operations become bitwise operations:

• Union of sets AA and BB: ABA | B (OR combines both)

• Intersection of sets AA and BB: A&BA \& B (AND keeps common elements)

• Difference ABA - B: A&(B)A \& (\sim B) (elements in AA but not in BB)

• Check if element ii is in set SS: (S&(1<<i))0(S \& (1 << i)) \neq 0

These operations run in O(1)O(1) time when n32n \leq 32 or n64n \leq 64, making bitmask DP transitions run in O(1)O(1) time.