Combinations

HSM Program 1.11 gives code that implements a recursive algorithm for generating all permutations of an array. A recursive algorithm for generating combinations of M elements from an array is:
Set combination to empty

Choose (M elements, from an Array)
if M == 0 then
    output the combination
else if the array has at least M elements then
        Add the first element to the combination
        Choose M-1 elements from the rest of the array
        if the array has more than M elements then
            Remove that first element that was added to the combination
            Choose M elements from the rest of the array

Answer