Algorithm for generating subsets of finite sets

algorithmscomputational mathematicsgraph theoryreference-requestrelations

Obviously there is no method to generate a sequence of subsets of $\mathbb N$ that, in analogue with diagonalizing elements in $\mathbb N^2$, gives an arbitrary number of arbitrary elements.

But is there a method to, one bye one, generate all subsets of $\mathbb Z_n$ without having to generate big subsets of $2^{\mathbb Z_n}$?

In order to investigate graphs and certain finite relations I would like to generate elements of sets as $2^{A\times B}$ without having to consume enormous amounts of time and memory.

Best Answer

Since subsets of an $n$-set are in bijection with binary strings of length $n$, Gray code should help here. Also, check out Combinatorial Algorithms by Nijenhuis and Wilf, it has several algorithms similar to what you're looking for.

Related Question