One could use the combinatorial number system to list or traverse all "k"-combinations of a given finite set, but this is a very inefficient way to do that. Indeed, given some "k"-combination it is much easier to find the next combination in lexicographic ordering directly than to convert a number to a "k"-combination by the method indicated above. To find the next combination, find the smallest "i" ≥ 2 for which "c""i" ≥ "c""i−1"+2 (if there is no such "i", take "i" = "k"+1); then increase "c""i"−1 by one and set all "c""j" with to their minimal value . If the "k"-combination is represented by its characteristic vector, that is as a binary value with "k" bits 1, then the next such value can be computed without any loop using bitwise arithmetic: the following C++ function will advance to that value or return :