Discrete MathCounting

Counting the Complement

Count "at least one" as all the possibilities minus the ones with none.

Not started Jump to practice

"At least one" problems are everywhere: committees with at least one woman, passwords with at least one digit. Counting them head-on means many cases. Counting the opposite is usually one short step, built from the sum rule and combinations.

Key idea

To count the outcomes with a property, count all outcomes and subtract those without it: $$\#(\text{at least one}) = \#(\text{all}) - \#(\text{none}).$$

Listen for the words "at least one," "some," "not all" and "contains a." Each is the opposite of a simple condition (none, all, never), and that opposite is usually a single product. A password with no digit is just a string of letters; a committee with no women is just a committee of men; a sequence of dice rolls with no 6 has $5$ choices per roll.

Why it works

Every outcome either has at least one of the thing or has none, never both. So by the sum rule, all $=$ (none) $+$ (at least one). Rearranging gives the formula. The "none" case is usually simple: a committee with no women is just a committee chosen from the men.
A tempting shortcut that overcounts: "choose one woman first, then anyone." A committee with two women is produced twice, once for each woman picked first.

Worked examples

Worked example: Committees with at least one woman

A committee of $3$ is chosen from $4$ women and $3$ men. How many committees include at least one woman?
  1. All committees: $\binom{7}{3} = 35$.
  2. No women: all three from the $3$ men, $\binom{3}{3} = 1$.
  3. At least one woman: $35 - 1 = 34$.

Answer: $34$

Worked example: Bit strings

How many bit strings of length $8$ contain at least one 1? At least two 1s?
  1. All strings: $2^{8} = 256$. The only string with no 1 is 00000000, so at least one 1: $255$.
  2. "At least two 1s" is the opposite of "zero or one 1." There is $1$ string with no 1 and $8$ with exactly one (choose its position).
  3. At least two: $256 - 1 - 8 = 247$.

Answer: $255$ and $247$

Worked example: Repeated digits

How many $4$-digit PINs (digits 0–9) have at least one repeated digit?
  1. All PINs: $10^{4} = 10{,}000$.
  2. No repeated digit: $10 \cdot 9 \cdot 8 \cdot 7 = 5{,}040$.
  3. At least one repeat: $10{,}000 - 5{,}040 = 4{,}960$.

Answer: $4{,}960$

Common mistake

Choosing "one first, then anyone." For the committees above it is tempting to pick a woman ($4$ ways) and then any $2$ of the other $6$ people ($\binom{6}{2} = 15$), giving $60$. But the committee $\{W_{1}, W_{2}, M_{1}\}$ is produced twice: once with $W_{1}$ picked first and once with $W_{2}$. Committees with more women are counted more times, so $60$ is far too big. Check: a correct method produces each outcome exactly once; ask how many ways your method can produce one particular outcome.

Practice

Pass with 3 right answers, the last 2 in a row. Each right answer earns 2 XP.

Loading practice…

Builds on

Leads to

Sources and further reading

  • Oscar Levin, Discrete Mathematics: An Open Introduction (3rd ed.), sections "Combinations and Permutations" and "Advanced Counting Using PIE"
  • MIT OpenCourseWare 6.042J Mathematics for Computer Science (Lehman, Leighton and Meyer), chapter "Cardinality Rules"
@teddyrookbook GitHub