Post · 5 min read· pp. 122–125

2.1 Counting


Video Available Video Available

Remember that for a finite sample space SS with equally likely outcomes, the probability of an event AA is given by

P(A)=∣A∣∣S∣=MNP(A)=\frac{|A|}{|S|}=\frac{M}{N}
Thus, finding probability of AA reduces to a counting problem in which we need to count how many elements are in AA and SS. In this section, we will discuss ways to count the number of elements in a set in an efficient manner. Counting is an area of its own and there are books on this subject alone. Here we provide a basic introduction to the material that is usually needed in probability. Almost everything that we need about counting is the result of the multiplication principle. We previously saw the multiplication principle when we were talking about Cartesian products. Here we look at it from a different perspective. Let us look at a simple example.


Example

Suppose that I want to purchase a tablet computer. I can choose either a large or a small screen; a $64$GB, $128$GB, or $256$GB storage capacity, and a black or white cover. How many different options do I have?

  • Solution
    • Here are the options:

      1. L-64-B
      2. L-64-W
      3. L-128-B
      4. L-128-W
      5. L-256-B
      6. L-256-W
      7. S-64-B
      8. S-64-W
      9. S-128-B
      10. S-128-W
      11. S-256-B
      12. S-256-W Thus, there are $12$ possible options. The multiplication principle states that we can simply multiply the number of options in each category (screen size, memory, color) to get the total number of possibilities, i.e., the answer is $2 \times 3 \times 2 =12$.

Here is a formal statement of the multiplication principle.

Multiplication Principle

Suppose that we perform rr experiments such that the kkth experiment has nkn_k possible outcomes, for k=1k=1,$2,,\cdots,,r$. Then there are a total of n1×n2×n3×⋯×nrn_1 \times n_2 \times n_3 \times \cdots \times n_r possible outcomes for the sequence of rr experiments.


Example I need to choose a password for a computer account. The rule is that the password must consist of two lowercase letters (a to z) followed by one capital letter (A to Z) followed by four digits ($0,1,\cdots,9$). For example, the following is a valid password

ejT3018ejT3018

  • Find the total number of possible passwords, NN.

  • A hacker has been able to write a program that randomly and independently generates $10^8$ passwords according to the above rule. Note that the same password could be generated more than once. If one of the randomly chosen passwords matches my password, then he can access my account information. What is the probability that he is successful in accessing my account information?

  • Solution

    • To choose a password, I need to first choose a lowercase letter, then another lowercase letter, then one capital letter, and then $4$ digits. There are $26$ lowercase letters, $26$ capital letters, and $10$ digits. Thus, by the multiplication principle, the total number of possible valid passwords is

      N=26×26×26×10×10×10×10=263×104N=26 \times 26 \times 26 \times 10 \times 10 \times 10 \times 10=26^3 \times 10^4
      Let GiG_i denote the event that the hacker's iith guess matches mine, for i=1,2,⋯ ,108i=1,2,\cdots, 10^8. The probability that the iith randomly chosen password matches mine is
      P(Gi)=1NP(G_i)=\frac{1}{N}
      Now let phackp_{hack} be the probability that the hacker is successful, that is at least one of the randomly chosen passwords matches mine. Recall that "at least" means union:
      phack=P(⋃iGi)p_{hack}=P\bigg(\bigcup_{i} G_i\bigg)
      Note that the events GiG_i are independent since the guesses are independently generated, but they are not disjoint since multiple guesses could be correct if the hacker's program generates the same password. Therefore in this case it is easier to work with intersections than unions, so we will find the probability of the complement event first:

      P(⋃iGi)cP\bigg(\bigcup_{i} G_i\bigg)^c=P(⋂iGic)= P\bigg(\bigcap_{i} G_i^c\bigg)
      =∏i=1NP(Gic)=\prod_{i=1}^{N} P(G_i^c) \hspace{30pt}(by independence)\textrm{(by independence)}
      =(1−1N)108=\bigg(1-\frac{1}{N}\bigg)^{10^8}

      Therefore,

      phackp_{hack}=1−(1−1N)108=1-\bigg(1-\frac{1}{N}\bigg)^{10^8}
      =1−(1−1263×104)108=1-\bigg(1-\frac{1}{26^3 \times 10^4}\bigg)^{10^8}
      =0.4339=0.4339

Example

Let AA be a set with ∣A∣=n<∞|A|=n < \infty. How many distinct subsets does AA have?

  • Solution
    • Let's assume A={a1,a2,a3,⋯ ,an}A=\{a_1, a_2, a_3, \cdots,a_n\}. We can look at this problem in the following way. To choose a subset BB, we perform the following experiment. First we decide whether or not a1∈Ba_1 \in B (two choices), then we decide whether or not a2∈Ba_2 \in B (two choices), then we decide whether or not a3∈Ba_3 \in B (two choices), ..., and finally we decide whether or not an∈Ba_n \in B (two choices). By the multiplication principle, the total number of subsets is then given by $2 \times 2 \times 2 \times \cdots \times 2=2^n$. To check our answer, let's assume A={1,2}A=\{1,2\}. Then our formula states that there are $4$ possible subsets. Indeed, the subsets are
      1. {}=∅\{\}=\emptyset
      2. {1}\{1\}
      3. {2}\{2\}
      4. {1,2}\{1,2\}

Here, we would like to provide some general terminology for the counting problems that show up in probability to make sure that the language that we use is precise and clear.

  • Sampling: sampling from a set means choosing an element from that set. We often draw a sample at random from a given set in which each element of the set has equal chance of being chosen.

  • With or without replacement: usually we draw multiple samples from a set. If we put each object back after each draw, we call this sampling with replacement. In this case a single object can be possibly chosen multiple times. For example, if A={a1,a2,a3,a4}A=\{a_1, a_2, a_3, a_4\} and we pick 3 elements with replacement, a possible choice might be (a3,a1,a3)(a_3,a_1,a_3). Thus "with replacement" means "repetition is allowed." On the other hand, if repetition is not allowed, we call it sampling without replacement.

  • Ordered or unordered: If ordering matters (i.e.: a1,a2,a3≠a2,a3,a1a_1, a_2, a_3 \neq a_2, a_3, a_1), this is called ordered sampling. Otherwise, it is called unordered.

Thus when we talk about sampling from sets, we can talk about four possibilities.

  • ordered sampling with replacement
  • ordered sampling without replacement
  • unordered sampling without replacement
  • unordered sampling with replacement

We will discuss each of these in detail and indeed will provide a formula for each. The formulas will be summarized at the end in Table 2.1. Nevertheless, the best approach here is to understand how to derive these formulas. You do not actually need to memorize them if you understand the way they are obtained.