Counting: Mukulika Ghosh Fall 2018
Counting: Mukulika Ghosh Fall 2018
Mukulika Ghosh
Fall 2018
Counting
The basic principles are extremely simple, but counting is a nontrivial task.
Product Rule
Suppose that a task can be broken down into a sequence of two subtasks.
If there are n1 ways to solve subtask 1 and n2 ways to solve subtask 2,
then there must be n1 n2 ways to solve the task.
Let S1 and S2 be sets describing the ways of the first and second subtasks,
so n1 = |S1 | and n2 = |S2 |. Then |S1 × S2 | = n1 n2
Example How many rows are there in a truth table for a statement with
n variables?
Each variable can have 2 possible truth value. Hence for n variables, there
can be 2 × 2 × ...(ntimes) = 2n
Exercise
How many possible SSN numbers can there be? (Remember ssn number
is denoted as XXX-XX-XXXX)
How many functions are there from a set with m elements to a set with n
elements?
For each of the m elements in the domain, we can choose any element
from the codomain as a function value. Hence, by the product rule, we
get n × n × ... × n = nm different functions
How many injective functions are there from a set with m elements to a
set with n elements?
If m ≤ n, then there are n ways to choose the value for the first element
in the domain, n − 1 ways to choose the value for the second element (as
one has to avoid the previously chosen value), n − 2 for the third element
of the domain and so forth. Thus, we have n(n − 1)...(n − m + 1) injective
functions in this case.
Sum Rule
If a task can be done either in one of n1 ways or in one of n2 ways, where
none of the set of n1 ways is the same as any of the set of n2 ways, then
there are n1 + n2 ways to do the task.
Example
How many sequences of 1s and 2s sum to n?
So for sn contains sn−1 sequences that starts with 1 and sn−2 sequences
starting with 2.
Exercise
How many 5 letters word can be created that starts with a vowel?
IPv4
Class C = 22 1(2˙ 8 − 2)
In total, 3, 737, 091, 842 (3.7 billion IP addresses)
Subtraction Rule
Example:
How many bit strings of length 8 either start with a 1 bit or end with the
last two bits equal to 00 ?
1. a letter [a-z],
2. a digit [0-9], or
Exercise
How many strings of two ASCII characters contain the character “@” at
least once? (Note: There 128 different ASCII characters)
Pigeonhole Principle
Proof
So there are fewer than N objects in total which contradicts the assumption
that there are N objects.
Example
1. Among 90 students, there are at least d90/12e = 8 who have birthdays
in same month.
2. Ten points are given within a square of unit size. Then there are two
points that are closer to each other than 0.48.
Exercise
What is the minimum number of students, each of whom comes from one
of the 50 states, who must be enrolled in a university to guarantee that
there are at least 10 who come from the same state?
When two different formulas enumerate the same set, then they must be
the same.
In other words, you count the elements of the set in two different ways.
Example: S = {1, 2, 3, 4}. Then (2, 4, 3) and (4, 3, 2) are two distinct
3−permutations of S.
Number of r-Permutations
Proof:
Let S be a set with n elements. The first element of the permutation can
be chosen in n ways, the second in n − 1 ways, ..., the r−th element can
be chosen in (n − r + 1) ways. By the product rule, the total number
becomes n(n − 1)...(n − r + 1)
Example
Combinations
Number of Combinations
The number of r−combinations of a set with n elements is given by
!
n n!
=
r (n − r)!r!
Exercise
There are six different candidates for governor of a state. In how many
different orders can the names of candidates be printed on a ballot?
Binomial Theorem
Proof:
Let us expand the left hand side. The terms of the product in expanded
form are xk y n−k for 0 ≤ k ≤ n. To obtain the term xk y n−k one must
choose k x’s from the n(x + y) terms. There are nk ways to do that.
Proof: We have 0 = 0n = (−1 + 1)n . Expanding the right hand side with
the help of the binomial theorem, we obtain the claim.
This implies that the number of subsets with an even number of elements
is equal to the number of subsets with an odd number of elements.
Pascal’s Identity
Let n and k be positive integers with n ≥ k. Then
! ! !
n+1 n n
= +
k k−1 k
Proof: We are going to prove this by counting the number of subsets with
k elements of a set T with n + 1 elements in two different ways:
k elements from the set T − {t} with n elements. Since the two cases are
exhaustive, C(n + 1, k) = C(n, k − 1) + C(n, k)
Vandermonde’s Identity
Let m, n, and r be non-negative integers, r ≤ min(n, m). Then
r
! ! !
m+n X m n
=
r k=0
r−k k
Proof: We will prove this by counting in two different ways. Let S and T
be two disjoint sets with m = |S| and n = |T |.
Counting in the first way: We can choose r elements from S ∪ T in n+m
r
ways.
Counting in the second way: We can pick r elements from S ∪T by picking
r − k elements from S and k elements from T , where 0 ≤ k ≤ r. By the
m n
product rule, this can be done in r−k k ways. Hence the total number
of ways to pick r elements from S ∪ T is
r
! !
X m n
k=0
r−k k