Many problems that require traversing all combinations of a given type that satisfy a number of conditions and performing computations/manipulations on each combination can be conveniently framed in terms of \textbf{multisets}. A multiset
If a combination is represented by a multiset, all combinations that need to be enumerated can form a collection of multisets. Let
To account for all the combinations, it might be useful to impose some kind of ordering on them and, consequently, a rule prescribing how to move from one combination to the next. Ultimately, finding a rule that would allow one to efficiently traverse all the necessary combinations is the problem to solve. Since a combination can be represented by a single number, moving from that combination to the next can be as simple as incrementing or decrementing that number or, if there are constraints (e.g. a bound on a sum of the digits of the number), moving to the closest "allowed" number. Because different representations of a combination described above are bijective, the "next" number uniquely defines a combination in the collection. A diagram below shows how the chain of these representations can be used to move from a given combination to the next one.
A base, or radix, is the number of unique digits at each position: the smallest digit is
- Standard systems: fixed base -- same base at each position (e.g. decimal system: base 10, binary system: base 2);
- Non-standard systems: varying base -- different bases are allowed at each position. Time measurement is a common example of that, with 7 days in a week, 24 hours in a day, 60 minutes in an hour and so on.
The number represented by a sequence of digits
Incrementing a number in a mixed radix system can follow the same principal as in standard systems: going from right to left, find the first position that can be incremented, add
The star in the top panel that graphically represents
The incrementing procedure described above is outlined in \cite{knuth2011art} Algorithm M (Mixed-radix generation) for generating all
- Generate all the collections of non-unique elements of a given size
$n$ from a set$A$ of their unique elements (all the multisets$M_l$ such that$|M_l| = n$ and$Supp(M_l) = A$ ); - Find all the sub-collections of a given collection
$B$ with a cardinality constraint$n$ (all the multisets$M_l$ such that$M_l \subseteq B$ and$|M_l| \leqslant n$ ); - Find all the binary sequences with elements in
${0, 1}$ of length$k$ where the number of$1$ 's does not exceed$n \leqslant k$ ; - Generate all the collections of elements whose sum is equal to a given number
$n$ . - Generate all the combinations of
$k$ out of$n$ elements.


