A four-digit access code may use any of the ten digits in each position, and a leading zero is allowed. How many codes are there, and how does that number change when no digit may repeat or when the code may not start with zero? When every outcome is equally likely, a probability is a ratio of two such counts, so the counts have to be right. This lesson sets out when to multiply numbers of choices, when to add the sizes of separate cases, and which factors a restriction changes.
Key terms
Product rule for counting
Definition Suppose every outcome is built by a sequence of choices. The first choice has options, and for every way of making the first choices, the th choice has exactly options. Suppose also that different sequences of choices produce different outcomes and that every outcome comes from some sequence. Then the number of outcomes is
The options available at a stage may depend on the earlier choices. Only their number has to be the same along every path. The factors are counts of options, not probabilities, and the rule assumes nothing about independence or about how an outcome is later selected.
In plain words When every outcome is assembled step by step in exactly one way, and at each step every partial outcome can be continued in the same number of ways, multiply those numbers. Each factor answers one question, namely how many options remain at that step.
Example A workshop label is one letter from A, B, C and D followed by one digit from 0 to 9. Each of the 4 letters can be followed by any of the 10 digits, so there are labels. If a mechanism picks one label uniformly, each label has probability . A mechanism that favors labels starting with A assigns different probabilities, but the set still holds 40 labels.
Sum rule for counting
Definition If a finite set is the union of sets that are pairwise disjoint, so that no outcome lies in two of them, then
where is the number of elements of . When the sets overlap, the plain sum counts every shared outcome more than once. For two sets the corrected count is
In plain words When each outcome belongs to exactly one of several separate formats or cases, count each case and add. The addition is correct because no outcome is counted twice.
Example A registration tag is either two letters or three digits, with all 26 letters and all 10 digits allowed and repetition permitted. There are letter tags and digit tags. No tag is of both kinds, so there are tags. The product would instead count a two-letter part followed by a three-digit part, which is a different, five-character format.
Counting by cases and decision trees
Definition Counting by cases splits the set of outcomes into cases that do not overlap and together cover every outcome, counts each case separately, often with the product rule, and adds the case counts by the sum rule. A decision tree draws the choices in stages. Each branch leaving a node is one available option, and each complete path from the root to a leaf is one outcome. When different paths give different outcomes and every outcome has a path, the number of outcomes is the number of leaves. If every node at each stage has the same number of branches, the leaves can be counted with the product rule. If not, split the tree into cases by the earlier branches that change a later count, count the leaves in each case separately and add.
In plain words When the number of options at some step depends on what happened earlier, that step has no single factor, so the steps in that order do not give one product. Split into cases by the earlier choice that changes the count, count each case on its own and add. A small tree shows which numbers to multiply and which to add, and it lists actual outcomes to compare with the final count.
Example A worker chooses a workstation and then a tool available there. Workstation A has 2 permitted tools and workstation B has 3. The tree has 2 leaves under A and 3 under B, so there are workstation and tool pairs. The product would invent a third tool at A.
Selection with and without replacement
Definition Choose items one after another from distinct items and record the order. In selection with replacement, every item stays available at every stage, so items can repeat and there are ordered selections. In selection without replacement, each item can be used at most once, so the stage counts are and the number of ordered selections is
If , this product contains the factor and so equals , which matches the fact that the items run out before the last stage. The names come from drawing objects from a box and returning them or not, but the same counts apply to symbols, such as digits that may or may not repeat in a code.
In plain words With replacement, a used option goes back into the pool. Without replacement, the pool shrinks by one at each stage, so each factor is one less than the factor before it.
Example For four-digit codes with a leading zero allowed, repetition gives codes, and no repetition gives
codes. If a code is chosen uniformly from all 10000, the probability that it has no repeated digit is .
Counting with restrictions
Definition A restriction is a condition that every valid outcome must satisfy. It can remove outcomes from the set being counted, and when the valid outcomes form the sample space, it changes that sample space too. To count valid outcomes with the product rule, give each stage the number of options that satisfy every restriction applying to that stage, given the earlier choices. Each restriction has a scope, the positions or stages it applies to. If the resulting stage counts are not the same along every path, split into cases.
In plain words Write each position’s rule in words before writing its factor, and ask how many options are still allowed after the earlier choices. A rule about one position limits only that position, so a ban on a leading zero does not ban zero from the other positions.
Example For four-digit codes with a nonzero first digit and repetition allowed, the first position has 9 options and each other position 10, giving codes. With a nonzero first digit and no repeated digit anywhere, the count is
The second factor is 9, not 8, because zero is banned only from the first position, so after the first digit is chosen nine digits remain, zero among them. The two restrictions together also change probabilities. A code chosen uniformly from all 10000 codes ends in 0 with probability , and so does a code chosen uniformly under either restriction alone. Among the 4536 codes that satisfy both, end in 0, so a code chosen uniformly from them ends in 0 with probability .
Check yourself
- Use only the letters A, B, C and D and the digits 0, 1 and 2. A tag is either two different letters followed by a digit, or one letter followed by two digits that may repeat. How many tags are there? How does the total change if the two digits in the second format must differ?
Show the answer
The first format has 4 choices for the first letter, 3 for the second because it must differ, and 3 for the digit, so it has tags. The second format has 4 letter choices and 3 choices for each digit, again tags. The second character is a letter in the first format and a digit in the second, so the formats are disjoint and the total is .
If the two digits must differ, only the last factor of the second format changes, from 3 to 2. That format then has tags, and the new total is .
- A classmate counts four-digit codes with a nonzero first digit and no repeated digit as . Find the mistake and the correct count.
Show the answer
The classmate treats zero as banned from every position. The restriction applies to the first position only. After a nonzero first digit is chosen, 9 digits remain for the second position, zero among them, then 8 and then 7. The correct count is . In fact 3024 is the number of valid codes that contain no zero at all, so the other valid codes contain a zero in one of the last three positions.
- How many whole numbers from 100 to 999 are even and have three different digits? Explain why a single product does not give the count.
Show the answer
Choose the last digit first, because evenness restricts it, and split into two cases.
If the last digit is 0, the first digit has 9 options (1 to 9) and the middle digit has 8 options (any digit not yet used), giving numbers.
If the last digit is 2, 4, 6 or 8, there are 4 options for it. The first digit cannot be 0 or the last digit, which leaves 8 options, and the middle digit can be any of the 8 digits not yet used. That gives numbers.
The cases are disjoint and cover every possibility, so the total is . A single product fails in this order because once the last digit is chosen, the first digit has 9 options in one case and 8 in the other, so the stage count is not fixed. Choosing the first digit first runs into the same problem, since the last digit then has 4 even options if the first digit was even and 5 if it was odd. In fact no product of three stage counts can work in any order, because and the prime 41 is larger than the 10 digits any stage can offer.