Permutations & Combinations

As you may have already noticed, finding patterns in the possible ways events can occur is very useful in helping us count the number of desirable events in our sample space. Two of the easiest methods for doing this are with permutations (when order matters) and combinations (when order doesn't matter).

Permutations

An ordered arrangement of rr objects from a set, AA, of nn objects (where 0<rn0<r\leq n) is called an rr-element permutation of AA. You can also think of this as a permutation of AA's elements taken rr at a time. The number of rr-element permutations of an nn-object set is denoted by the following formula: nPr=n!(nr)!_nP_r =\frac{n!}{(n-r)!}

Note: We define 0!0! to be 11; otherwise, nPn_nP_n would be n!0\frac{n!}{0} (when r=nr=n).

permutations = 3 * 2 * 1 = 3! = 6

-> written as n! numpy.math.factorial(n)numpy.math.factorial(n)

- of a subset

k-permutations = 8 * 7 * 6 = 3366

select k elements out of a pool of n objects

n(n1)...(nk+1)Pkn=n!(nk)!n * (n-1) * ... * (n - k + 1)\newline P_k^n=\frac{n!}{(n-k)!}

from numpy.math import factorial as fact

def permutation(n, k):
    return fact(n) / fact(n-k)

- with replacement

Now the number of possible outcomes is 3 * 3 * 3.

Generalizing this to n, this means that the number of permutations with replacenent when having n distinct objects is equal to n^j where j is the number of “draws”.

Combinations

An unordered arrangement of rr objects from a set, AA, of nn objects (where rnr \leq n) is called an rr-element combination of AA. You can also think of this as a combination of AA's elements taken rr at a time.

Because the only difference between permutations and combinations is that combinations are unordered, we can easily find the number of rr-element combinations by dividing out the permutations (r!r!): nCr=nPrr!=n!r!(nr)!_nC_r=\frac{_nP_r}{r!}=\frac{n!}{r! * (n-r)!}

When we talk about combinations, we're talking about the number of subsets of size rr that can be made from a set of size nn. In fact, nCr_nC_r is often referred to as "nn choose rr", because it's counting the number of rr-element combinations that can be chosen from a set of nn elements. In notation, nCR_nC_R is typically written as (nr)\binom{n}{r}.

In general, combinations answer the question: "How many ways can we create a subset k out of n objects?". The subset is not ordered.

(nk)=Pknk!=n!(nk)!k!=n!(nk)!k!\binom{n}{k}=\frac{P_k^n}{k!} = \frac{\frac{n!}{(n-k)!}}{k!} = \frac{n!}{(n-k)!k!}

def combination(n, k):
  return fact(n) / (fact(n-k)*fact(k))

We define a binomial process to be a binomial experiment meeting the following conditions:

  • The number of successes is k.

  • The total number of trials is n.

  • The probability of success of 1 trial is p.

  • The probability of failure of 1 trial q, where q = 1 - p.

  • b(n, k, p) is the binomial probability, meaning the probability of having exactly successes out of n trials.

The binomial random variable is the number of successes, k, out of n trials.

The binomial distribution is the probability distribution for the binomial random variable, given by the following probability mass function:

b(n,k,p)=(nk)pkq(nk)b(n, k, p) = \binom nk * p^k * q^{(n-k)}

def bernoulli(n, k, p):
    return combination(n, k) * p**k * (1-p)**(n-k)

Last updated