# 14.5: Counting Subsets

• Eric Lehman, F. Thomson Leighton, & Alberty R. Meyer
• Google and Massachusetts Institute of Technology via MIT OpenCourseWare

$$\newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} }$$

$$\newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}}$$

$$\newcommand{\id}{\mathrm{id}}$$ $$\newcommand{\Span}{\mathrm{span}}$$

( \newcommand{\kernel}{\mathrm{null}\,}\) $$\newcommand{\range}{\mathrm{range}\,}$$

$$\newcommand{\RealPart}{\mathrm{Re}}$$ $$\newcommand{\ImaginaryPart}{\mathrm{Im}}$$

$$\newcommand{\Argument}{\mathrm{Arg}}$$ $$\newcommand{\norm}[1]{\| #1 \|}$$

$$\newcommand{\inner}[2]{\langle #1, #2 \rangle}$$

$$\newcommand{\Span}{\mathrm{span}}$$

$$\newcommand{\id}{\mathrm{id}}$$

$$\newcommand{\Span}{\mathrm{span}}$$

$$\newcommand{\kernel}{\mathrm{null}\,}$$

$$\newcommand{\range}{\mathrm{range}\,}$$

$$\newcommand{\RealPart}{\mathrm{Re}}$$

$$\newcommand{\ImaginaryPart}{\mathrm{Im}}$$

$$\newcommand{\Argument}{\mathrm{Arg}}$$

$$\newcommand{\norm}[1]{\| #1 \|}$$

$$\newcommand{\inner}[2]{\langle #1, #2 \rangle}$$

$$\newcommand{\Span}{\mathrm{span}}$$ $$\newcommand{\AA}{\unicode[.8,0]{x212B}}$$

$$\newcommand{\vectorA}[1]{\vec{#1}} % arrow$$

$$\newcommand{\vectorAt}[1]{\vec{\text{#1}}} % arrow$$

$$\newcommand{\vectorB}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} }$$

$$\newcommand{\vectorC}[1]{\textbf{#1}}$$

$$\newcommand{\vectorD}[1]{\overrightarrow{#1}}$$

$$\newcommand{\vectorDt}[1]{\overrightarrow{\text{#1}}}$$

$$\newcommand{\vectE}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash{\mathbf {#1}}}}$$

$$\newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} }$$

$$\newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}}$$

$$\newcommand{\avec}{\mathbf a}$$ $$\newcommand{\bvec}{\mathbf b}$$ $$\newcommand{\cvec}{\mathbf c}$$ $$\newcommand{\dvec}{\mathbf d}$$ $$\newcommand{\dtil}{\widetilde{\mathbf d}}$$ $$\newcommand{\evec}{\mathbf e}$$ $$\newcommand{\fvec}{\mathbf f}$$ $$\newcommand{\nvec}{\mathbf n}$$ $$\newcommand{\pvec}{\mathbf p}$$ $$\newcommand{\qvec}{\mathbf q}$$ $$\newcommand{\svec}{\mathbf s}$$ $$\newcommand{\tvec}{\mathbf t}$$ $$\newcommand{\uvec}{\mathbf u}$$ $$\newcommand{\vvec}{\mathbf v}$$ $$\newcommand{\wvec}{\mathbf w}$$ $$\newcommand{\xvec}{\mathbf x}$$ $$\newcommand{\yvec}{\mathbf y}$$ $$\newcommand{\zvec}{\mathbf z}$$ $$\newcommand{\rvec}{\mathbf r}$$ $$\newcommand{\mvec}{\mathbf m}$$ $$\newcommand{\zerovec}{\mathbf 0}$$ $$\newcommand{\onevec}{\mathbf 1}$$ $$\newcommand{\real}{\mathbb R}$$ $$\newcommand{\twovec}[2]{\left[\begin{array}{r}#1 \\ #2 \end{array}\right]}$$ $$\newcommand{\ctwovec}[2]{\left[\begin{array}{c}#1 \\ #2 \end{array}\right]}$$ $$\newcommand{\threevec}[3]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \end{array}\right]}$$ $$\newcommand{\cthreevec}[3]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \end{array}\right]}$$ $$\newcommand{\fourvec}[4]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}$$ $$\newcommand{\cfourvec}[4]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \end{array}\right]}$$ $$\newcommand{\fivevec}[5]{\left[\begin{array}{r}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}$$ $$\newcommand{\cfivevec}[5]{\left[\begin{array}{c}#1 \\ #2 \\ #3 \\ #4 \\ #5 \\ \end{array}\right]}$$ $$\newcommand{\mattwo}[4]{\left[\begin{array}{rr}#1 \amp #2 \\ #3 \amp #4 \\ \end{array}\right]}$$ $$\newcommand{\laspan}[1]{\text{Span}\{#1\}}$$ $$\newcommand{\bcal}{\cal B}$$ $$\newcommand{\ccal}{\cal C}$$ $$\newcommand{\scal}{\cal S}$$ $$\newcommand{\wcal}{\cal W}$$ $$\newcommand{\ecal}{\cal E}$$ $$\newcommand{\coords}[2]{\left\{#1\right\}_{#2}}$$ $$\newcommand{\gray}[1]{\color{gray}{#1}}$$ $$\newcommand{\lgray}[1]{\color{lightgray}{#1}}$$ $$\newcommand{\rank}{\operatorname{rank}}$$ $$\newcommand{\row}{\text{Row}}$$ $$\newcommand{\col}{\text{Col}}$$ $$\renewcommand{\row}{\text{Row}}$$ $$\newcommand{\nul}{\text{Nul}}$$ $$\newcommand{\var}{\text{Var}}$$ $$\newcommand{\corr}{\text{corr}}$$ $$\newcommand{\len}[1]{\left|#1\right|}$$ $$\newcommand{\bbar}{\overline{\bvec}}$$ $$\newcommand{\bhat}{\widehat{\bvec}}$$ $$\newcommand{\bperp}{\bvec^\perp}$$ $$\newcommand{\xhat}{\widehat{\xvec}}$$ $$\newcommand{\vhat}{\widehat{\vvec}}$$ $$\newcommand{\uhat}{\widehat{\uvec}}$$ $$\newcommand{\what}{\widehat{\wvec}}$$ $$\newcommand{\Sighat}{\widehat{\Sigma}}$$ $$\newcommand{\lt}{<}$$ $$\newcommand{\gt}{>}$$ $$\newcommand{\amp}{&}$$ $$\definecolor{fillinmathshade}{gray}{0.9}$$

How many $$k$$-element subsets of an $$n$$-element set are there? This question arises all the time in various guises:

• In how many ways can I select 5 books from my collection of 100 to bring on vacation?
• How many different 13-card bridge hands can be dealt from a 52-card deck?
• In how many ways can I select 5 toppings for my pizza if there are 14 available toppings?

This number comes up so often that there is a special notation for it:

$\nonumber {n \choose k} ::= \text{the number of } k \text{-element subsets of an } n \text{-element set.}$

The expression $${n \choose k}$$ is read "$$n$$ choose $$k$$." Now we can immediately express the answers to all three questions above:

I can select 5 books from 100 in $${100 \choose 5}$$ ways.

There are $${52 \choose 13}$$ different bridge hands.

There are $${14 \choose 5}$$ different 5-topping pizzas, if 14 toppings are available.

## The Subset Rule

We can derive a simple formula for the $$n$$ choose $$k$$ number using the Division Rule. We do this by mapping any permutation of an $$n$$-element set $$\{a_1, \ldots, a_n\}$$ into a $$k$$-element subset simply by taking the first k elements of the permutation. That is, the permutation $$a_1 a_2\ldots a_n$$ will map to the set $$\{a_1, a_2, \ldots, a_n\}$$.

Notice that any other permutation with the same first $$k$$ elements $$a_1, \ldots, a_n$$ in any order and the same remaining elements $$n - k$$ elements in any order will also map to this set. What’s more, a permutation can only map to $$\{a_1, a_2, \ldots, a_n\}$$ if its first $$k$$ elements are the elements $$a_1, \ldots, a_n$$ in some order. Since there are $$k!$$ possible permutations of the first $$k$$ elements and $$(n-k)!$$ permutations of the remaining elements, we conclude from the Product Rule that exactly $$k!(n-k)!$$ permutations of the $$n$$-element set map to the particular subset, $$S$$. In other words, the mapping from permutations to $$k$$-element subsets is $$k!(n-k)!$$-to-1.

But we know there are $$n!$$ permutations of an $$n$$-element set, so by the Division Rule, we conclude that

$\nonumber n! = k! (n-k)! {n \choose k}$

which proves:

Rule 14.5.1 (Subset Rule). The number of $$k$$-element subsets of an $$n$$-element set is

$\nonumber {n \choose k} = \dfrac{n!}{k!(n-k)!}.$

Notice that this works even for 0-element subsets: $$n! / 0!n! = 1$$. Here we use the fact that $$0!$$ is a product of 0 terms, which by convention2 equals 1.

## Bit Sequences

How many $$n$$-bit sequences contain exactly $$k$$ ones? We’ve already seen the straightforward bijection between subsets of an n-element set and $$n$$-bit sequences. For example, here is a 3-element subset of $$\{x_1, x_2, \ldots, x_8\}$$ and the associated 8-bit sequence:

$\nonumber \begin{array}{l} \{x_1, \quad x_4, x_5 \quad \quad\} \\ (1, 0, 0, 1, 1, 0, 0, 0) \end{array}$

Notice that this sequence has exactly 3 ones, each corresponding to an element of the 3-element subset. More generally, the $$n$$-bit sequences corresponding to a $$k$$-element subset will have exactly $$k$$ ones. So by the Bijection Rule,

Corollary 14.5.2. The number of $$n$$-bit sequences with exactly $$k$$ ones is $${n \choose k}$$.

Also, the bijection between selections of flavored donuts and bit sequences of Lemma 14.1.1 now implies,

Corollary 14.5.3. The number of ways to select $$n$$ donuts when $$k$$ flavors are available is

$\nonumber {n + (k - 1) \choose n}.$

2We don’t use it here, but a sum of zero terms equals 0.

This page titled 14.5: Counting Subsets is shared under a CC BY-NC-SA license and was authored, remixed, and/or curated by Eric Lehman, F. Thomson Leighton, & Alberty R. Meyer (MIT OpenCourseWare) .