Post · 8 min read· pp. 141–146

2.1.5 Solved Problems: Combinatorics


Problem

Let AA and BB be two finite sets, with ∣A∣=m|A|=m and ∣B∣=n|B|=n. How many distinct functions (mappings) can you define from set AA to set BB, f:A→Bf:A \rightarrow B?

  • Solution
    • We can solve this problem using the multiplication principle. Let
      A={a1,a2,a3,...,am},A =\{a_1,a_2,a_3,...,a_m\},
      B={b1,b2,b3,...,bn}.B =\{b_1,b_2,b_3,...,b_n\}.
      Note that to define a mapping from AA to BB, we have nn options for f(a1)f(a_1), i.e., f(a1)∈B={b1,b2,b3,...,bn}f(a_1) \in B=\{b_1,b_2,b_3,...,b_n\}. Similarly we have nn options for f(a2)f(a_2), and so on. Thus by the multiplication principle, the total number of distinct functions f:A→Bf:A \rightarrow B is
      n⋅n⋅n⋯n=nm.n \cdot n \cdot n \cdots n = n^m.

Problem

A function is said to be one-to-one if for all x1≠x2x_1\neq x_2, we have f(x1)≠f(x2)f(x_1)\neq f(x_2). Equivalently, we can say a function is one-to-one if whenever f(x1)=f(x2)f(x_1)=f(x_2), then x1=x2x_1=x_2. Let AA and BB be two finite sets, with ∣A∣=m|A|=m and ∣B∣=n|B|=n. How many distinct one-to-one functions (mappings) can you define from set AA to set BB, f:A→Bf:A \rightarrow B?

  • Solution
    • Again let
      A={a1,a2,a3,...,am},A =\{a_1,a_2,a_3,...,a_m\},
      B={b1,b2,b3,...,bn}.B =\{b_1,b_2,b_3,...,b_n\}.
      To define a one-to-one mapping from AA to BB, we have nn options for f(a1)f(a_1), i.e., f(a1)∈B={b1,b2,b3,...,bn}f(a_1) \in B=\{b_1,b_2,b_3,...,b_n\}. Given f(a1)f(a_1), we have n−1n-1 options for f(a2)f(a_2), and so on. Thus by the multiplication principle, the total number of distinct functions f:A→Bf:A \rightarrow B, is
      n⋅(n−1)⋅(n−2)⋯(n−m+1)=Pmn.n \cdot (n-1) \cdot (n-2) \cdots (n-m+1) = P^n_{m}.
      Thus, in other words, choosing a one-to-one function from AA to BB is equivalent to choosing an mm-permutation from the nn-element set BB (ordered sampling without replacement) and as we have seen there are PmnP^n_{m} ways to do that.

Problem

An urn contains $30$ red balls and $70$ green balls. What is the probability of getting exactly kk red balls in a sample of size $20$ if the sampling is done with replacement (repetition allowed)? Assume $0\leq k \leq 20$.

  • Solution
    • Here any time we take a sample from the urn we put it back before the next sample (sampling with replacement). Thus in this experiment each time we sample, the probability of choosing a red ball is 30100\frac{30}{100}, and we repeat this in $20$ independent trials. This is exactly the binomial experiment. Thus, using the binomial formula we obtain
      P(k red balls)=(20k)(0.3)k(0.7)20−k.P(k \textrm{ red balls})={20 \choose k} (0.3)^k(0.7)^{20-k}.

Problem

An urn consists of $30$ red balls and $70$ green balls. What is the probability of getting exactly kk red balls in a sample of size $20$ if the sampling is done without replacement (repetition not allowed)?

  • Solution
    • Let AA be the event (set) of getting exactly kk red balls. To find P(A)=∣A∣∣S∣P(A)=\frac{|A|}{|S|}, we need to find ∣A∣|A| and ∣S∣|S|. First, note that ∣S∣=(10020)|S|={100 \choose 20}. Next, to find ∣A∣|A|, we need to find out in how many ways we can choose kk red balls and $20-k$ green balls. Using the multiplication principle, we have
      ∣A∣=(30k)(7020−k).|A|= {30 \choose k}{70 \choose 20-k}.
      Thus, we have
      P(A)=(30k)(7020−k)(10020).P(A)= \frac{{30 \choose k}{70 \choose 20-k}}{{100 \choose 20}}.

Problem Assume that there are kk people in a room and we know that:

  • k=5k=5 with probability 14\frac{1}{4};
  • k=10k=10 with probability 14\frac{1}{4};
  • k=15k=15 with probability 12\frac{1}{2}.
  1. What is the probability that at least two of them have been born in the same month? Assume that all months are equally likely.
  2. Given that we already know there are at least two people that celebrate their birthday in the same month, what is the probability that k=10k=10?
  • Solution
      1. The first part of the problem is very similar to the birthday problem, one difference here is that here n=12n=12 instead of $365$. Let AkA_k be the event that at least two people out of kk people have birthdays in the same month. We have

        P(Ak)=1−Pk1212k,for k∈{2,3,4,...,12}P(A_k)=1-\frac{P^{12}_k}{12^k}, \textrm{for } k \in \{2,3,4,...,12\}
        Note that P(Ak)=1P(A_k)=1 for k>12k>12. Let AA be the event that at least two people in the room were born in the same month. Using the law of total probability, we have

        P(A)P(A)=14P(A5)+14P(A10)+12P(A15)= \frac{1}{4} P(A_5)+\frac{1}{4} P(A_{10})+ \frac{1}{2} P(A_{15})
        =14(1−P512125)+14(1−P10121210)+12= \frac{1}{4} \left(1-\frac{P^{12}_5}{12^5}\right)+\frac{1}{4} \left(1-\frac{P^{12}_{10}}{12^{10}}\right)+ \frac{1}{2}.
      2. The second part of the problem asks for P(k=10∣A)P(k=10 | A). We can use Bayes' rule to write

        P(k=10∣A)P(k=10 | A)=P(A∣k=10)P(k=10)P(A)=\frac{P(A|k=10)P(k=10)}{P(A)}
        =P(A10)4P(A)= \frac{P(A_{10})}{4P(A)}
        =1−P10121210(1−P512125)+(1−P10121210)+2=\frac{1-\frac{P^{12}_{10}}{12^{10}}}{(1-\frac{P^{12}_5}{12^5})+(1-\frac{P^{12}_{10}}{12^{10}})+ 2}.

Problem

How many distinct solutions does the following equation have?

x1+x2+x3+x4=100, such that x_1+x_2+x_3+x_4=100, \textrm{ such that }
x1∈{1,2,3..},x2∈{2,3,4,..},x3,x4∈{0,1,2,3,...}.x_1 \in \{1,2,3..\}, x_2 \in \{2,3,4,..\}, x_3,x_4 \in \{0,1,2,3,...\}.

  • Solution
    • We already know that in general the number of solutions to the equation
      x1+x2+...+xn=k, where xi∈{0,1,2,3,...}x_1+x_2+...+x_n=k, \textrm{ where } x_i \in \{0,1,2,3,...\}
      is equal to
      (n+k−1k)=(n+k−1n−1).{n+k-1 \choose k}={n+k-1 \choose n-1}.
      We need to convert the restrictions in this problem to match this general form. We are given that x1∈{1,2,3..}x_1 \in \{1,2,3..\}, so if we define
      y1=x1−1,y_1=x_1-1,
      then y1∈{0,1,2,3,...}y_1 \in \{0,1,2,3,...\}. Similarly define y2=x2−2y_2 =x_2-2, so y2∈{0,1,2,3,...}y_2 \in \{0,1,2,3,...\}. Now the question becomes equivalent to finding the number of solutions to the equation
      y1+1+y2+2+x3+x4=100, where y1,y2,x3,x4∈{0,1,2,3,...},y_1+1+y_2+2+x_3+x_4=100, \textrm{ where } y_1,y_2,x_3,x_4 \in \{0,1,2,3,...\},
      or equivalently, the number of solutions to the equation
      y1+y2+x3+x4=97, where y1,y2,x3,x4∈{0,1,2,3,...}.y_1+y_2+x_3+x_4=97, \textrm{ where } y_1,y_2,x_3,x_4 \in \{0,1,2,3,...\}.
      As we know, this is equal to
      (4+97−13)=(1003).{4+97-1 \choose 3}={100 \choose 3}.

Problem (The matching problem)

Here is a famous problem: NN guests arrive at a party. Each person is wearing a hat. We collect all hats and then randomly redistribute the hats, giving each person one of the NN hats randomly. What is the probability that at least one person receives his/her own hat? Hint: Use the inclusion-exclusion principle.

  • Solution
    • Let AiA_i be the event that ii'th person receives his/her own hat. Then we are interested in finding P(E)P(E), where E=A1∪A2∪A3∪...∪ANE=A_1 \cup A_2 \cup A_3 \cup ... \cup A_N. To find P(E)P(E), we use the inclusion-exclusion principle. We have

      P(E)=P(⋃i=1NAi)P(E)=P\biggl(\bigcup_{i=1}^N A_i\biggr)=∑i=1NP(Ai)−∑i,j : i<jP(Ai∩Aj)=\sum_{i=1}^N P(A_i)-\sum_{i,j\,:\,i < j}P(A_i\cap A_j)
      +∑i,j,k : i<j<kP(Ai∩Aj∩Ak)− ⋯ +(−1)N−1 P(⋂i=1NAi)+\sum_{i,j,k\,:\,i < j < k}P(A_i\cap A_j\cap A_k)-\ \cdots\ +(-1)^{N-1}\, P\biggl(\bigcap_{i=1}^N A_i\biggr).

      Note that there is complete symmetry here, that is, we can write

      P(A1)=P(A2)=P(A3)=...=P(AN);P(A_1) =P(A_2)=P(A_3)=...=P(A_N);
      P(A1∩A2)=P(A1∩A3)=...=P(A2∩A4)=...;P(A_1 \cap A_2)=P(A_1 \cap A_3)=...=P(A_2 \cap A_4)=...;
      P(A1∩A2∩A3)=P(A1∩A2∩A4)=...=P(A2∩A4∩A5)=...;P(A_1 \cap A_2 \cap A_3)=P(A_1 \cap A_2 \cap A_4)=...=P(A_2 \cap A_4 \cap A_5)=...;
      ......
      Thus, we have
      ∑i=1NP(Ai)=NP(A1);\sum_{i=1}^N P(A_i)=N P(A_1);
      ∑i,j : i<jP(Ai∩Aj)=(N2)P(A1∩A2);\sum_{i,j\,:\,i < j}P(A_i\cap A_j)= {N \choose 2} P(A_1 \cap A_2);
      ∑i,j,k : i<j<kP(Ai∩Aj∩Ak)=(N3)P(A1∩A2∩A3);\sum_{i,j,k\,:\,i < j < k}P(A_i\cap A_j\cap A_k)={N \choose 3} P(A_1 \cap A_2 \cap A_3);
      ......
      Therefore, we have

      P(E)P(E)=NP(A1)−(N2)P(A1∩A2)=NP(A_1)- {N \choose 2} P(A_1 \cap A_2)
      +(N3)P(A1∩A2∩A3)−...+(−1)N−1P(A1∩A2∩A3...∩AN)(2.5)+ {N \choose 3} P(A_1 \cap A_2 \cap A_3)-...+(-1)^{N-1}P(A_1 \cap A_2 \cap A_3 ... \cap A_N) \hspace{30pt} (2.5)

      Now, we only need to find P(A1)P(A_1), P(A1∩A2)P(A_1 \cap A_2), P(A1∩A2∩A3)P(A_1 \cap A_2 \cap A_3), etc. to finish solving the problem. To find P(A1)P(A_1), we have

      P(A1)=∣A1∣∣S∣.P(A_1)=\frac{|A_1|}{|S|}.
      Here, the sample space SS consists of all possible permutations of NN objects (hats). Thus, we have
      ∣S∣=N!|S|=N!
      On the other hand, A1A_1 consists of all possible permutations of N−1N-1 objects (because the first object is fixed). Thus
      ∣A1∣=(N−1)!|A_1|=(N-1)!
      Therefore, we have
      P(A1)=∣A1∣∣S∣=(N−1)!N!=1NP(A_1)=\frac{|A_1|}{|S|}=\frac{(N-1)!}{N!}=\frac{1}{N}
      Similarly, we have
      ∣A1∩A2∣=(N−2)!|A_1 \cap A_2|=(N-2)!
      Thus,
      P(A1∩A2)=∣A1∩A2∣∣S∣=(N−2)!N!=1PN−2N.P(A_1 \cap A_2)=\frac{|A_1 \cap A_2|}{|S|}=\frac{(N-2)!}{N!}=\frac{1}{P^{N}_{N-2}}.
      Similarly,
      P(A1∩A2∩A3)=∣A1∩A2∩A3∣∣S∣=(N−3)!N!=1PN−3N;P(A_1 \cap A_2 \cap A_3)=\frac{|A_1 \cap A_2 \cap A_3|}{|S|}=\frac{(N-3)!}{N!}=\frac{1}{P^{N}_{N-3}};
      P(A1∩A2∩A3∩A4)=∣A1∩A2∩A3∩A4∣∣S∣=(N−4)!N!=1PN−4N;P(A_1 \cap A_2 \cap A_3 \cap A_4)=\frac{|A_1 \cap A_2 \cap A_3 \cap A_4|}{|S|}=\frac{(N-4)!}{N!}=\frac{1}{P^{N}_{N-4}};
      ......
      Thus, using Equation 2.5 we have
      P(E)=N.1N−(N2)⋅1PN−2N+(N3)⋅1PN−3N−...+(−1)N−11N!(2.6)P(E)=N. \frac{1}{N}- {N \choose 2} \cdot \frac{1}{P^{N}_{N-2}}+ {N \choose 3} \cdot \frac{1}{P^{N}_{N-3}}-...+(-1)^{N-1}\frac{1}{N!} \hspace{40pt} (2.6)
      By simplifying a little bit, we obtain
      P(E)=1−12!+13!−....+(−1)N−11N!.P(E) =1- \frac{1}{2!}+\frac{1}{3!}-....+(-1)^{N-1}\frac{1}{N!}.
      We are done. It is interesting to note what happens when NN becomes large. To see that, we should remember the Taylor series expansion of exe^{x}. In particular,
      ex=1+x1!+x22!+x33!+...e^x=1+\frac{x}{1!}+\frac{x^2}{2!}+\frac{x^3}{3!}+...
      Letting x=−1x=-1, we have
      e−1=1−11!+12!−13!+...e^{-1}=1-\frac{1}{1!}+\frac{1}{2!}-\frac{1}{3!}+...
      Thus, we conclude that as NN becomes large, P(E)P(E) approaches $1-\frac{1}{e}$.