Skip to content
ExtendedSource checked

Bitmask Subset Enumeration

Enumerates subsets by treating integers as bit masks.

Quick Facts

Compact metadata for implementation and discovery.

Category
Procedural Generation
Difficulty
Intermediate
Family
Combinatorial generation
Tier
Extended
Status
Reviewed
Review
Ai Reviewed
Sources
1
Formulas
0
Relationships
1
Code example
Not ready
Visualization
Not ready
Aliases
Subset bitmask enumeration, Submask enumeration

Overview

Bitmask Subset Enumeration loops over integer masks and interprets each bit as selecting or excluding an element, producing all subsets or all submasks of a set.

Core Concepts

subset enumerationbitmasksubmask iterationexponential search

Quick facts

Complexity

Runtime and memory behavior at a glance.

Best

O(2^n) for all subsets

Average

O(2^n) for all subsets; O(3^n) for nested mask/submask enumeration

Worst

O(2^n) for all subsets; O(3^n) for all masks with all submasks

Space

O(1) iterator state plus output storage if materialized

When to Use

  • Use when the set is small enough for 2^n enumeration.

When Not to Use

  • Avoid when the number of subsets is too large for exhaustive enumeration.

What It Does

  • Maps each bit position to one input element.
  • Iterates masks to represent all subsets.
  • Optionally iterates submasks of a fixed mask.

Use Cases

  • Subset dynamic programming
  • Brute-force combinatorics
  • State compression

Inputs

  • A set represented by bit positions, or a mask whose submasks should be enumerated.

Outputs

  • A stream of subset masks or submasks.

Pseudocode

  1. 1.For mask from 0 to 2^n - 1.
  2. 2.Map set bits to selected elements.
  3. 3.Emit the subset.

Canonical Example

Input
A set {A, B, C}.
Output
All eight subsets represented by masks 000 through 111.
Explanation
Each mask bit decides whether the corresponding element is present.

Implementation Notes

  • Submask iteration commonly uses the recurrence sub = (sub - 1) & mask.

Common Pitfalls

  • Off-by-one errors in mask bounds and signed shifts are common.

Interactive Mechanism Walkthrough

Spatial Primitive & Sweep-Line Canvas

Show bit positions toggling through subset masks and the descending submask iteration pattern.

Bitmask Subset Enumeration mechanism walkthrough step 1 of 3
Step 1 of 3: For mask from 0 to 2^n - 1.
bitmask-enumeration

Notes

Bitmask Subset Enumeration covers explicit subset and submask iteration using integer masks; a stronger textbook or paper source would improve the active application package.

Sources (1)

What each reference supports for this entry.

CP-Algorithms submask enumeration

Documentation

Supports the standard submask iteration idiom `(s - 1) & m`, its descending-order behavior, and O(3^n) nested mask/submask iteration.

Open source

Explore Next

Good next jumps from the relationship graph, ranked for useful discovery.

Bitmask Subset Enumeration uses bit operations to represent membership and advance through subsets or submasks.

Related Algorithms

Tags

Bit LevelProcedural Generation