Size $n$ of ground set | (max. 20) |
Size $k$ of subsets | (between 0 and $n$) |
Algorithm | |
Print set representation | |
Output format | |
Lex | Colex | Cool-lex | MC | EMK | Chase |
All those algorithms are part of Jörg Arndt's FXT library. The algorithm for lexicographic ordering is explained as Algorithm L in Knuth's book [Section 7.2.1.3, Knu11]. The prefix rotation algorithm was discovered by Ruskey and Williams [RW05], and they named this ordering cool-lex in their paper. By restricting the binary reflected Gray code (BRGC) to bitstrings with a fixed Hamming weight (=number of 1s), we obtain a minimal-change order of combinations, where in each step only a single 0- and 1-bit are swapped. This was first observed by Tang and Liu [TL73], and the corresponding algorithm is described as Algorithm R in Knuth's book [Knu11] (see also [BER76, PI79]). In the algorithm due to Eades and McKay [EM84], we only allow swaps between a 0 and 1 where all bits in between are 0s. We can think of the 1-bits as pressed keys on a piano; then in each step only a single finger moves, and it does not cross the other fingers. In the two-close Gray code, we only allow swaps between a neighboring 0 and 1, or a 0 and 1 with a single 0 in between. The corresponding Gray code was first discovered by Chase [Cha89] and is described as Algorithm C in Knuth's book [Knu11].
Combinations are generalized by multiset permutations, and more algorithms for generating them can be found in that section.