Overview

A -combination of objects is an unordered “choice” of objects from the collection of objects. Alternatively viewed, it is a set of objects - ordering within a set does not matter. Combinations are derived by considering the number of -permutations of objects and discarding order, i.e. dividing by .

void combinations_aux(
  const size_t n, int A[static n],
  const size_t k, int stack[static k],
  const size_t i
) {
  if (n < k) {
    return;
  }
  if (k == 0) {
    print_array(i, stack);
    return;
  }
  stack[i] = A[0];
  combinations_aux(n - 1, A + 1, k - 1, stack, i + 1);
  combinations_aux(n - 1, A + 1, k, stack, i);
}
 
void combinations(const size_t n, const size_t k, int A[static n]) {
  int *stack = calloc(k, sizeof(int));
  combinations_aux(n, A, k, stack, 0);
  free(stack);
}

The above approach prints out all -combinations of an array.

Pascal’s Triangle

A visual representation of the binomial coefficient’s is in the form of Pascal’s Triangle:

1
1   1
1   2   1
1   3   3   1
1   4   6   4   1
1   5  10  10   5   1
...

Terms are generated by adding the two terms above it, formalized via recurrence

Bit Strings

A bit string can be used to represent subsets of some finite set. A 1 value usually corresponds to inclusion in a subset, whereas a 0 value corresponds to exclusion. Thus, given set e.g. , would correspond to subset .

Bit strings also make it clear that the number of subsets with even cardinality must be equal to the number of subsets with odd cardinality. Hence,

Stars and Bars

The stars and bars chart refers to a graphical depiction of distributing objects (represented as ) into different buckets (delineated via . An example chart looks like so:

Notice there are bars and interspersed amongst the stars. In the above example, there are total symbols, of which are bars, meaning there are ways to distribute the objects amongst the buckets. We can represent this using bit strings instead, with 0s as stars and 1s as bars. The above example is equivalently written as:

Lattice Paths

A lattice path is one of the shorted possible paths connecting two points on a lattice, moving only horizontally and vertically. By representing each horizontal move by 1 and each vertical move by 1, we see every lattice path has a corresponding bit string.

In this example, the total number of lattice paths from point to is therefore .

Binomial Coefficients

A binomial is a polynomial containing two terms. Consider . We see that term maps to some bit string containing 1s and 0s. This might feel more obvious when expanding to . Since multiplication is commutative, the number of matching “bit strings” is the same as .

Bibliography