Discrete MathematicsCounting: Choices, Arrangements and Selections1 of 7
Counting: Choices, Arrangements and Selections · 1

The Sum and Product Rules

We want to count how many ways an outcome can happen without listing every possibility by hand, and the main decision is when to multiply our choices and when to add them.

1

The Product Rule and Slots

Suppose you have 3\firstrole{3} shirts (A, B, C\firstrole{\text{A, B, C}}) and 4\secondrole{4} pairs of pants (1,2,3,4\secondrole{1, 2, 3, 4}) and want to find how many different outfits you can make, or you have 55 people (A, B, C, D, E\text{A, B, C, D, E}) and want to find how many ways to pick a President and a Vice President when nobody can hold both jobs.

The Product Rule and Slots
3 shirts: A, B, C\htmlClass{lc-blue}{3}\text{ shirts: }\htmlClass{lc-blue}{\text{A, B, C}}
4 pants: 1, 2, 3, 4\htmlClass{lc-pink}{4}\text{ pants: }\htmlClass{lc-pink}{\text{1, 2, 3, 4}}
A\htmlClass{lc-blue}{\text{A}}
B\htmlClass{lc-blue}{\text{B}}
C\htmlClass{lc-blue}{\text{C}}
outfits= ?\text{outfits} = \,?
A\htmlClass{lc-blue}{\text{A}}
B\htmlClass{lc-pink}{\text{B}}
C\htmlClass{lc-pink}{\text{C}}
D\htmlClass{lc-pink}{\text{D}}
E\htmlClass{lc-pink}{\text{E}}
B\htmlClass{lc-blue}{\text{B}}
A\htmlClass{lc-pink}{\text{A}}
C\htmlClass{lc-pink}{\text{C}}
D\htmlClass{lc-pink}{\text{D}}
E\htmlClass{lc-pink}{\text{E}}
C\htmlClass{lc-blue}{\text{C}}
A\htmlClass{lc-pink}{\text{A}}
B\htmlClass{lc-pink}{\text{B}}
D\htmlClass{lc-pink}{\text{D}}
E\htmlClass{lc-pink}{\text{E}}
D\htmlClass{lc-blue}{\text{D}}
A\htmlClass{lc-pink}{\text{A}}
B\htmlClass{lc-pink}{\text{B}}
C\htmlClass{lc-pink}{\text{C}}
E\htmlClass{lc-pink}{\text{E}}
E\htmlClass{lc-blue}{\text{E}}
A\htmlClass{lc-pink}{\text{A}}
B\htmlClass{lc-pink}{\text{B}}
C\htmlClass{lc-pink}{\text{C}}
D\htmlClass{lc-pink}{\text{D}}
5\htmlClass{lc-blue}{5}
Pres\htmlClass{lc-blue}{\text{Pres}}
4\htmlClass{lc-pink}{4}
VP\htmlClass{lc-pink}{\text{VP}}
Text solution
Pair each shirt with each pair of pantsPicking an outfit from a set S\firstrole{S} of 3\firstrole{3} shirts and a set P\secondrole{P} of 4\secondrole{4} pairs of pants means forming an ordered pair (s,p)∈S×P(\firstrole{s}, \secondrole{p}) \in \firstrole{S} \times \secondrole{P}, where each of the 3\firstrole{3} shirt branches splits into 4\secondrole{4} pants branches.
030‾⏟shirt×040‾⏟pants=12 outfits,∣S×P∣=∣S∣⋅∣P∣\displaystyle \begin{aligned}\underbrace{\underline{\phantom{0}\firstrole{3}\phantom{0}}}_{\firstrole{\text{shirt}}} \times \underbrace{\underline{\phantom{0}\secondrole{4}\phantom{0}}}_{\secondrole{\text{pants}}} &= \total{12} \text{ outfits}, \\ |\firstrole{S} \times \secondrole{P}| &= \firstrole{|S|} \cdot \secondrole{|P|}\end{aligned}
Fill the President and Vice President slotsAny of the 5\firstrole{5} people can be chosen as President first, and regardless of who wins, 4\secondrole{4} people remain for Vice President on every branch.
050‾⏟Pres×040‾⏟VP\displaystyle \underbrace{\underline{\phantom{0}\firstrole{5}\phantom{0}}}_{\firstrole{\text{Pres}}} \times \underbrace{\underline{\phantom{0}\secondrole{4}\phantom{0}}}_{\secondrole{\text{VP}}} =20 ways\displaystyle = \total{20} \text{ ways}
2

The Sum Rule and Uneven Trees

When a slot has a restriction, filling slots from left to right can use up some of the allowed options early and leave different numbers of choices on different branches. Let's find how many 33-digit even numbers we can make from {1,2,3,4,5}\{1, 2, 3, 4, 5\} with no repeats allowed.

The Sum Rule and Uneven Trees
{1,2,3,4,5}\{1, 2, 3, 4, 5\}
3-digit even numbers, no repeats\text{3-digit even numbers, no repeats}
1st\text{1st}
2nd\text{2nd}
3rd\text{3rd}
even: 2 or 4\text{even: 2 or 4}
= ?= \,?

We can keep the tree uniform by filling the restricted slot first, or we can split the uneven left-to-right tree into separate cases where each piece is uniform.

Text solution
Method 1: Fill the restricted even slot firstLock one of the two even digits (22 or 44) into the 33rd slot first so that every branch has 44 remaining digits for the 11st slot and 33 for the 22nd slot.
040‾⏟1st×030‾⏟2nd×020‾⏟3rd (even)fill 1st\displaystyle \underbrace{\underline{\phantom{0}4\phantom{0}}}_{\text{1st}} \times \underbrace{\underline{\phantom{0}3\phantom{0}}}_{\text{2nd}} \times \underbrace{\underline{\phantom{0}2\phantom{0}}}_{\substack{\text{3rd (even)} \\ \text{fill 1st}}} =24 even numbers\displaystyle = \total{24} \text{ even numbers}
Method 2: Split by whether the 1st digit is even or oddIf the 11st digit is even (2\firstrole{2} or 4\firstrole{4}), only 11 even digit remains for the 33rd slot; if the 11st digit is odd (1,3,\secondrole{1, 3,} or 5\secondrole{5}), both even digits remain open for the 33rd slot.
020‾⏟1st (even)×030‾⏟2nd×010‾⏟3rd (even)=6,030‾⏟1st (odd)×030‾⏟2nd×020‾⏟3rd (even)=18\displaystyle \begin{aligned}\underbrace{\underline{\phantom{0}\firstrole{2}\phantom{0}}}_{\firstrole{\text{1st (even)}}} \times \underbrace{\underline{\phantom{0}3\phantom{0}}}_{\text{2nd}} \times \underbrace{\underline{\phantom{0}1\phantom{0}}}_{\text{3rd (even)}} &= \firstrole{6}, \\ \underbrace{\underline{\phantom{0}\secondrole{3}\phantom{0}}}_{\secondrole{\text{1st (odd)}}} \times \underbrace{\underline{\phantom{0}3\phantom{0}}}_{\text{2nd}} \times \underbrace{\underline{\phantom{0}2\phantom{0}}}_{\text{3rd (even)}} &= \secondrole{18}\end{aligned}
Add the non-overlapping casesEvery 33-digit even number starts with either an even digit or an odd digit, so the two cases have no overlap.
6+18\displaystyle \firstrole{6} + \secondrole{18} =24 even numbers\displaystyle = \total{24} \text{ even numbers}

See how filling the restricted 33rd digit first keeps the tree uniform, while saving it for last splits the tree unevenly:

Filling the restricted even slot first keeps every step splitting evenly, while saving it for later forces the tree into separate cases.
3

Overlapping Cases

Adding cases directly only works when the cases cannot happen at the same time. Let's find how many 22-digit codes made from {1,2,3,4}\{1, 2, 3, 4\} (with repeats allowed) start with 1\firstrole{1} OR end with 4\secondrole{4}.

Overlapping Cases
{1,2,3,4}\{1, 2, 3, 4\}
2-digit codes, repeats allowed\text{2-digit codes, repeats allowed}
start with 1 OR end with 4\htmlClass{lc-blue}{\text{start with 1}}\text{ OR }\htmlClass{lc-pink}{\text{end with 4}}
Case 1:\htmlClass{lc-blue}{\text{Case 1:}}
starts with 1\htmlClass{lc-blue}{\text{starts with 1}}
1st\text{1st}
2nd\text{2nd}
Case 2:\htmlClass{lc-pink}{\text{Case 2:}}
ends with 4\htmlClass{lc-pink}{\text{ends with 4}}
1st\text{1st}
2nd\text{2nd}
codes= ?\text{codes} = \,?
Text solution
Count each condition on its ownLocking 1\firstrole{1} into the 11st slot leaves 44 choices for the 22nd slot (11,12,13,14\firstrole{11, 12, 13, 14}), and locking 4\secondrole{4} into the 22nd slot leaves 44 choices for the 11st slot (14,24,34,44\secondrole{14, 24, 34, 44}).
010‾×040‾=4⏟starts with 1,040‾×010‾=4⏟ends with 4\displaystyle \underbrace{\underline{\phantom{0}\firstrole{1}\phantom{0}} \times \underline{\phantom{0}4\phantom{0}} = \firstrole{4}}_{\firstrole{\text{starts with } 1}}, \qquad \underbrace{\underline{\phantom{0}4\phantom{0}} \times \underline{\phantom{0}\secondrole{1}\phantom{0}} = \secondrole{4}}_{\secondrole{\text{ends with } 4}}
Subtract the doubly-counted overlap onceBecause the code 14\fails{14} both starts with 1\firstrole{1} and ends with 4\secondrole{4}, adding the two counts includes 14\fails{14} twice.
4⏟starts with 1+4⏟ends with 4−1⏟both (14)\displaystyle \underbrace{\firstrole{4}}_{\firstrole{\text{starts with } 1}} + \underbrace{\secondrole{4}}_{\secondrole{\text{ends with } 4}} - \underbrace{\fails{1}}_{\fails{\text{both } (14)}} =7 codes\displaystyle = \total{7} \text{ codes}

On the 4×44 \times 4 grid of all 1616 two-digit codes, two rules that restrict the same slot highlight separate strips that add to 4+4=8\firstrole{4} + \secondrole{4} = \total{8}, whereas restricting different slots highlights a row and a column that cross at one doubly-counted code, giving 4+4−1=7\firstrole{4} + \secondrole{4} - \fails{1} = \total{7}.

Two rules joined by OR stay separate when they check the same digit, and cross at one shared code when they check different digits.
4

Counting Functions with General mm and nn

The same slot method works when concrete numbers are replaced by general set sizes mm and nn. Given a starting set AA with ∣A∣=m|A| = m elements and a target set BB with ∣B∣=n|B| = n elements, we want to find how many functions f:A→B\fname{f}: A \to B exist in total, and how many of them are one-to-one.

Counting Functions with General m and n
How many f:A→B ?\text{How many } \htmlClass{lc-violet}{f}: A \to B\,?
AA
BB
a1a_1
a2a_2
a3a_3
b1b_1
b2b_2
b3b_3
b4b_4
∣A∣=m|A| = m
∣B∣=n|B| = n
a1a_1
a2a_2
ama_m
b1b_1
b2b_2
b3b_3
bnb_n
nn
a1a_1
nn
a2a_2
⋯\cdots
⋯\cdots
nn
ama_m
m slotsm \text{ slots}
Text solution
Count all functions f:A→B\fname{f}: A \to B (repeats allowed)Each of the mm elements in AA must send out one arrow, creating mm slots, and each arrow can land on any of the nn targets in BB.
0n0‾×0n0‾×⋯×0n0‾⏟m slots (one for each element in A)\displaystyle \underbrace{\underline{\phantom{0}n\phantom{0}} \times \underline{\phantom{0}n\phantom{0}} \times \cdots \times \underline{\phantom{0}n\phantom{0}}}_{m \text{ slots (one for each element in } A\text{)}} =nm functions\displaystyle = \total{n^m} \text{ functions}
Count one-to-one functions f:A→B\fname{f}: A \to B (no shared targets)Each arrow uses up one target in BB, so by the time the mm-th element of AA picks a target, the previous m−1m - 1 elements have taken m−1\fails{m - 1} targets, leaving n−(m−1)=n−m+1n - \fails{(m - 1)} = n - m + 1 choices (and the product is 0\total{0} whenever m>nm > n, because the (n+1)(n + 1)-th slot has 0\fails{0} choices).
0n0‾⏟1st (n−0)×0n−10‾⏟2nd×0n−20‾⏟3rd×⋯×0n−m+10‾⏟m-th (n−(m−1)) one-to-one functions\displaystyle \begin{aligned}&\underbrace{\underline{\phantom{0}n\phantom{0}}}_{\text{1st } (n - \fails{0})} \times \underbrace{\underline{\phantom{0}n - \fails{1}\phantom{0}}}_{\text{2nd}} \times \underbrace{\underline{\phantom{0}n - \fails{2}\phantom{0}}}_{\text{3rd}} \\ &\quad \times \cdots \times \underbrace{\underline{\phantom{0}n - m + 1\phantom{0}}}_{m\text{-th } (n - \fails{(m - 1)})} \\ &\quad \text{ one-to-one functions}\end{aligned}

Watch how the nn target choices in BB stay open in every slot for general functions, and step down by 1\fails{1} after each arrow for one-to-one functions:

Each element in the starting set opens a slot of choices from the target set, and locking out shared targets drops the choices by one at each step no matter which targets were taken earlier.

Key concepts

Every counting problem here comes down to how the choices branch as you build an outcome step by step:

Sequence of decisions with uniform branch counts (Product Rule)

When you make a sequence of choices to build one complete result, draw one slot per decision, fill the most restricted slots first, and multiply the number of choices. For 33-digit even numbers from {1,2,3,4,5}\{1, 2, 3, 4, 5\} without repeats, filling the even 33rd slot first gives 4‾×3‾×2‾=24\underline{4} \times \underline{3} \times \underline{2} = \total{24}. Do not split into cases just because the specific options left over change from branch to branch: as long as the number of remaining options is the same on every branch (like 5‾×4‾=20\underline{\firstrole{5}} \times \underline{\secondrole{4}} = \total{20} for President and Vice President), you can multiply in one step.

Uneven trees where an earlier choice changes later counts (Sum Rule)

When a restriction makes the number of remaining choices depend on which option was picked earlier, split the problem at that choice into separate, non-overlapping cases, multiply the slots inside each case, and add the cases together (for those same 33-digit even numbers split by the 11st digit: 2‾×3‾×1‾+3‾×3‾×2‾=6+18=24\underline{\firstrole{2}} \times \underline{3} \times \underline{1} + \underline{\secondrole{3}} \times \underline{3} \times \underline{2} = \firstrole{6} + \secondrole{18} = \total{24}).

Overlapping "OR" cases

If an outcome can satisfy both cases at the same time, adding the cases counts that overlap twice, so subtract the overlap once (for 22-digit codes from {1,2,3,4}\{1, 2, 3, 4\} starting with 1\firstrole{1} OR ending with 4\secondrole{4}: 1‾×4‾+4‾×1‾−1=7\underline{\firstrole{1}} \times \underline{4} + \underline{4} \times \underline{\secondrole{1}} - \fails{1} = \total{7}, subtracting the code 14\fails{14}).

Functions f:A→B\fname{f}: A \to B with ∣A∣=m|A| = m and ∣B∣=n|B| = n

Draw mm slots (one for each element in AA) and fill them with target choices from BB:

All functions: n×n×⋯×n⏟m slots=nm,One-to-one (m≤n): n(n−1)(n−2)⋯(n−m+1)\displaystyle \begin{aligned}&\text{All functions: } \\ &\quad \underbrace{n \times n \times \cdots \times n}_{m \text{ slots}} = \total{n^m}, \\ &\text{One-to-one } (m \le n)\text{: } \\ &\quad n(n - \fails{1})(n - \fails{2})\cdots(n - m + 1)\end{aligned}
5

Practice

1

A license code consists of 22 letters chosen from {A, B, C, D, E}\{\text{A, B, C, D, E}\} followed by 33 digits chosen from {1,2,3,4,5,6}\{1, 2, 3, 4, 5, 6\}. Letters may be repeated, but no digit may be repeated. How many such license codes are possible?

Draw 55 slots for the 22 letters and 33 digits: which slots keep the same number of choices, and which slots drop by 11 each step?

Draw 55 slots (22 for letters, 33 for digits). The letter slots have 55 and 55 choices because repeats are allowed (dropping the second letter slot to 44 would forbid repeats and give 2,400\fails{2,400}), and the digit slots have 66, 55, and 44 choices because no digit may be repeated. Because choosing the letters and choosing the digits are back-to-back steps to build a single code, multiply the slots rather than adding the 25\total{25} letter pairs and 120\total{120} digit triples (adding gives 145\fails{145}):
5‾×5‾×6‾×5‾×4‾\displaystyle \underline{5} \times \underline{5} \times \underline{6} \times \underline{5} \times \underline{4} =3,000\displaystyle = \total{3,000}
2

How many 44-letter codes can be formed from the letters {A, B, C, D, E, F}\{\text{A, B, C, D, E, F}\} without repeats if the first letter must be a vowel (A\text{A} or E\text{E}) and the last letter must be a consonant (B, C, D,\text{B, C, D,} or F\text{F})?

Fill the 11st and 44th slots before the middle slots: can a vowel chosen for the 11st slot ever use up one of the consonants needed for the 44th slot?

Fill the two restricted slots first: there are 22 choices for the 11st slot (A\text{A} or E\text{E}) and 44 choices for the 44th slot (B, C, D,\text{B, C, D,} or F\text{F}). Because vowels and consonants do not overlap, picking a vowel for the 11st slot never uses up a consonant (reducing the 44th slot to 33 choices gives the wrong answer 72\fails{72}). Locking in those two end slots uses 22 of the 66 letters, leaving 44 choices for the 22nd slot and 33 choices for the 33rd slot:
2‾×4‾×3‾×4‾\displaystyle \underline{2} \times \underline{4} \times \underline{3} \times \underline{4} =96\displaystyle = \total{96}
3

Using only the digits {0,1,2,3,4,5}\{0, 1, 2, 3, 4, 5\} with no repeats allowed, how many 33-digit even numbers can be formed? (A 33-digit number cannot start with 00.)

Both the 11st slot (cannot be 00) and the 33rd slot (must be 0,2,0, 2, or 44) are restricted, and 00 belongs to both rules: how does the number of choices for the 11st slot change depending on whether the 33rd slot is 00 or not?

Because 00 is an even digit (allowed in the 33rd slot) and also forbidden in the 11st slot, the number of choices for the 11st slot depends on whether 00 was used in the 33rd slot, so you cannot multiply in a single step as 4×4×3=484 \times 4 \times 3 = \fails{48} or 5×4×3=605 \times 4 \times 3 = \fails{60}. Split into two non-overlapping cases based on the 33rd digit:
Case 1 (33rd digit is 0\firstrole{0})11 choice for the 33rd slot (0\firstrole{0}), 55 choices for the 11st slot (any of 1,2,3,4,51, 2, 3, 4, 5), and 44 remaining choices for the 22nd slot, giving 5‾×4‾×1‾=20\underline{5} \times \underline{4} \times \underline{\firstrole{1}} = \firstrole{20}.
Case 2 (33rd digit is 2\secondrole{2} or 4\secondrole{4})22 choices for the 33rd slot (2\secondrole{2} or 4\secondrole{4}), and 44 choices for the 11st slot (cannot be 00 or the chosen 33rd digit). For the 22nd slot, 00 is available again, so 44 of the 66 digits remain (forgetting that 00 can go in the middle slot leaves 33 choices and gives 24\fails{24} instead of 32\secondrole{32}): 4‾×4‾×2‾=32\underline{4} \times \underline{4} \times \underline{\secondrole{2}} = \secondrole{32}. By the Sum Rule:
20+32\displaystyle \firstrole{20} + \secondrole{32} =52\displaystyle = \total{52}
4

Using the digits {1,2,3,4,5}\{1, 2, 3, 4, 5\} with no repeats allowed, how many 33-digit numbers either start with an odd digit OR end with an even digit?

Count the numbers that start with an odd digit and the numbers that end with an even digit, then check whether a 33-digit number can do both at the same time.

Starts with an odd digit (1,3,\firstrole{1, 3,} or 5\firstrole{5})3‾×4‾×3‾=36\underline{\firstrole{3}} \times \underline{4} \times \underline{3} = \firstrole{36}.
Ends with an even digit (2\secondrole{2} or 4\secondrole{4})Fill the 33rd slot first with 2\secondrole{2} choices, leaving 44 for the 11st slot and 33 for the 22nd: 4‾×3‾×2‾=24\underline{4} \times \underline{3} \times \underline{\secondrole{2}} = \secondrole{24}.
Overlap (starts with an odd digit AND ends with an even digit)3\firstrole{3} odd choices for the 11st slot, 2\secondrole{2} even choices for the 33rd slot (since no even digit was used first), and 33 remaining digits for the 22nd slot: 3‾×3‾×2‾=18\underline{\firstrole{3}} \times \underline{3} \times \underline{\secondrole{2}} = \fails{18}. Do not stop at 36+24=60\firstrole{36} + \secondrole{24} = \fails{60}, which counts the 18\fails{18} overlapping numbers twice; subtract the overlap once:
36+24−18\displaystyle \firstrole{36} + \secondrole{24} - \fails{18} =42\displaystyle = \total{42}
5

Let A={a1,a2,a3,a4}A = \{a_1, a_2, a_3, a_4\} and B={b1,b2,b3,b4,b5,b6}B = \{b_1, b_2, b_3, b_4, b_5, b_6\}.

(a) How many functions f:A→B\fname{f}: A \to B satisfy f(a1)=b1\fname{f}(a_1) = b_1?

(b) How many one-to-one functions f:A→B\fname{f}: A \to B satisfy f(a1)≠b1\fname{f}(a_1) \neq b_1?

(c) In general, if ∣A∣=m|A| = m and ∣B∣=n|B| = n with 1≤m≤n1 \le m \le n, how many one-to-one functions f:A→B\fname{f}: A \to B satisfy f(a1)=b1\fname{f}(a_1) = b_1?

Draw one slot for each element of AA and fill the restricted slot a1a_1 first; in (b), once a1a_1 picks a target other than b1b_1, is b1b_1 allowed as a target for a2,a3,a_2, a_3, and a4a_4?

(a)Draw 44 slots for a1,a2,a3,a4a_1, a_2, a_3, a_4. The 11st slot (a1a_1) has 11 choice (b1b_1). Because a general function allows repeated targets, a2,a3,a_2, a_3, and a4a_4 still have all 66 choices in BB (dropping b1b_1 to give 1×5×5×5=1251 \times 5 \times 5 \times 5 = \fails{125} or stepping down as 1×5×4×3=601 \times 5 \times 4 \times 3 = \fails{60} wrongly restricts repeats):
1‾×6‾×6‾×6‾\displaystyle \underline{1} \times \underline{6} \times \underline{6} \times \underline{6} =63\displaystyle = 6^3 =216\displaystyle = \total{216}
(b)Fill the restricted slot a1a_1 first: a1a_1 has 55 choices (anything in BB except b1b_1). For a2a_2, b1b_1 is now available again while a1a_1's chosen target is taken, leaving 55 choices for a2a_2, then 44 for a3a_3, and 33 for a4a_4 (stepping straight down from 55 as 5×4×3×2=1205 \times 4 \times 3 \times 2 = \fails{120} forgets that b1b_1 is available again for a2a_2):
5‾×5‾×4‾×3‾\displaystyle \underline{5} \times \underline{5} \times \underline{4} \times \underline{3} =300\displaystyle = \total{300}
(c)Draw mm slots for a1,…,ama_1, \dots, a_m. The 11st slot (a1a_1) has 11 choice (b1b_1), and the remaining m−1m - 1 elements of AA map one-to-one into the remaining n−1n - 1 elements of BB. By the mm-th slot, m−1\fails{m - 1} targets have been taken, so the last factor is n−(m−1)=n−m+1n - \fails{(m - 1)} = n - m + 1 (writing n−m\fails{n - m} subtracts one target too many):
1×(n−1)×(n−2)×⋯×(n−m+1)=(n−1)(n−2)⋯(n−m+1)\displaystyle \begin{aligned}&1 \times (n - \fails{1}) \times (n - \fails{2}) \\ &\quad \times \cdots \times (n - m + 1) \\ &= (n - \fails{1})(n - \fails{2})\cdots(n - m + 1)\end{aligned}