0% found this document useful (0 votes)
45 views

Counting: Mukulika Ghosh Fall 2018

The document discusses various counting principles including the product rule, sum rule, subtraction rule, and pigeonhole principle. It provides examples and exercises demonstrating how to use these principles to count the number of elements or possible outcomes in different sets and scenarios. The key ideas are that the product rule is used to count outcomes when tasks can be completed independently, the sum rule is used when tasks can be completed through separate means, and the subtraction rule accounts for outcomes that overlap between different tasks.

Uploaded by

Thuy Nguyen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views

Counting: Mukulika Ghosh Fall 2018

The document discusses various counting principles including the product rule, sum rule, subtraction rule, and pigeonhole principle. It provides examples and exercises demonstrating how to use these principles to count the number of elements or possible outcomes in different sets and scenarios. The key ideas are that the product rule is used to count outcomes when tasks can be completed independently, the sum rule is used when tasks can be completed through separate means, and the subtraction rule accounts for outcomes that overlap between different tasks.

Uploaded by

Thuy Nguyen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 41

Counting

Mukulika Ghosh

Fall 2018

Based on slides by Dr. Hyunyoung Lee


Counting

Counting

The art of counting is known as enumerative combinatorics. One tries to


count the number of elements in a set (or, typically, simultaneously count
the number of elements in a series of sets).

Example Count the number of successful outcomes of an experiments

The basic principles are extremely simple, but counting is a nontrivial task.

Mukulika Ghosh | Parasol Lab - Texas A&M University 2/41


Product Rule

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

Mukulika Ghosh | Parasol Lab - Texas A&M University 3/41


Exercise

Exercise

How many possible SSN numbers can there be? (Remember ssn number
is denoted as XXX-XX-XXXX)

Mukulika Ghosh | Parasol Lab - Texas A&M University 4/41


Product rule in Functions

Product rule in Functions

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

Mukulika Ghosh | Parasol Lab - Texas A&M University 5/41


Product rule in 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 0 injective functions.

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.

Mukulika Ghosh | Parasol Lab - Texas A&M University 6/41


Sum Rule

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.

Let S1 and S2 be disjoint sets (i.e, S1 ∩ S2 = ∅ with n1 = |S1 | and


n2 = |S2 |. Then |S1 ∪ S2 | = n1 + n2 .

Example: A student can choose a computer project from one of three


lists. The three lists contain 23, 15, and 19 possible projects, respectively.
No project is on more than one lists. How many possible projects are there
to choose from?

There are 23 + 15 + 19 = 57 projects to choose from.

Mukulika Ghosh | Parasol Lab - Texas A&M University 7/41


Example

Example
How many sequences of 1s and 2s sum to n?

Let sn denotes such sequence.


s0 = 1 = empty
s1 = 1 = {(1)}
s2 = 2 = {(1, 1), (2)}
s3 = 3 = {(1, 1, 1), (1, 2), (2, 1)}
s4 = 5 = {(1, 1, 1, 1), (1, 1, 2), (1, 2, 1), (2, 1, 1), (2, 2)}

So for sn contains sn−1 sequences that starts with 1 and sn−2 sequences
starting with 2.

Mukulika Ghosh | Parasol Lab - Texas A&M University 8/41


Example

sn = sn−1 + sn−2 which is same as definition of Fibonacci numbers

Mukulika Ghosh | Parasol Lab - Texas A&M University 9/41


Exercise

Exercise

How many 5 letters word can be created that starts with a vowel?

Mukulika Ghosh | Parasol Lab - Texas A&M University 10/41


IPv4

IPv4

Computer addresses belong to one of the following 3 types:

• Class A: address contains a 7-bit “netid” 6= 17 , and a 24-bit “hostid”

• Class B: address has a 14-bit netid and a 16-bit hostid.

• Class C: address has 21-bit netid and an 8-bit hostid.

Mukulika Ghosh | Parasol Lab - Texas A&M University 11/41


IPv4

Hostids that are all 0s or all 1s are not allowed

How many valid computer addresses are there?

Number of address = (Class A) + (Class B) + (Class C) By sum rule,


Class A = (valid netids) (valid hostids) by Product rule
= (27 − 1).(22 4 − 2)
˙ 1 6 − 2)
Class B = 21 4(2

Mukulika Ghosh | Parasol Lab - Texas A&M University 12/41


IPv4

Class C = 22 1(2˙ 8 − 2)
In total, 3, 737, 091, 842 (3.7 billion IP addresses)

Mukulika Ghosh | Parasol Lab - Texas A&M University 13/41


Subtraction Rule

Subtraction Rule

If a task can be done in either n1 ways or n2 ways, then the number of


ways to do the task is n1 + n2 minus the number of ways to do the task
that is common to the two different ways.

Principle of Inclusion-and-Exclusion: Let S1 and S2 be sets. Then |S1 ∪


S2 | = |S1 | + |S2 | − |S1 ∩ S2 |

Mukulika Ghosh | Parasol Lab - Texas A&M University 14/41


Example:

Example:

How many bit strings of length 8 either start with a 1 bit or end with the
last two bits equal to 00 ?

Let S1 be the number of strings that start with a 1 bit = 27 .


Let S2 be the number of strings that end with 00 = 26 .
The number of strings that start with 1 and end with 00 = 25 .
Hence, in total = 27 + 26 − 25 = 160

Mukulika Ghosh | Parasol Lab - Texas A&M University 15/41


Example:

Consider simple rules for passwords. Passwords must be 2 characters long.


Each character must be

1. a letter [a-z],

2. a digit [0-9], or

3. one of the 10 special characters

Mukulika Ghosh | Parasol Lab - Texas A&M University 16/41


Example:

Each password must contain at least 1 digit or special character.

Number of password with 1 digit or special character in first character


= (10 + 10)(10 + 10 + 26) = 20 × 46
Number of password with 1 digit or special character in second character
= 20 × 46
Number of password with either a digit or special character in both places
= 20 × 20
Total = 2(20 × 46) − 20 × 20 = 1440

Mukulika Ghosh | Parasol Lab - Texas A&M University 17/41


Exercise

Exercise

How many strings of two ASCII characters contain the character “@” at
least once? (Note: There 128 different ASCII characters)

Mukulika Ghosh | Parasol Lab - Texas A&M University 18/41


Pigeonhole Principle

Pigeonhole Principle

If k + 1 objects are assigned to k


places, then at least one place must
be assigned at least two objects.

Mukulika Ghosh | Parasol Lab - Texas A&M University 19/41


Generalized Pigeonhole Principle

Generalized Pigeonhole Principle


If N > k objects are assigned to k places, then at least one place must be
assigned at least d Nk e objects.

Proof

Suppose every place has less than d Nk e objects; so at most d Nk e − 1 objects


per place.

Total number of objects = k(d Nk e − 1)


k(d Nk e − 1) < k(( Nk + 1) − 1) = k( Nk ) = N

Mukulika Ghosh | Parasol Lab - Texas A&M University 20/41


Generalized Pigeonhole Principle

So there are fewer than N objects in total which contradicts the assumption
that there are N objects.

Mukulika Ghosh | Parasol Lab - Texas A&M University 21/41


Example

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.

Partition the square in 3 × 3 grid of 9 cells.


By Pigeonhole principle, one grid must contain atleast d10/9e = 2 points.
The points are far apart when they are at theqopposite corners of the
12 12
diagonal. Therefore, the points can be at most 3 + 3 < 0.48 apart.

Mukulika Ghosh | Parasol Lab - Texas A&M University 22/41


Exercise

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?

Mukulika Ghosh | Parasol Lab - Texas A&M University 23/41


Counting in Two Different Ways

Counting in Two Different Ways

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.

Mukulika Ghosh | Parasol Lab - Texas A&M University 24/41


Counting in Two Different Ways

Example: Consider a grid of (n+1)×(n+1) = (n + 1)2 points. Similarly,


we can count the number of points as total of points in all the diagonals
(main, upper and lower):
n n
(n + 1)2 = (n + 1) +
X X
i+ i
i=1 i=1
n
⇒ (n + 1)2 − (n + 1) = 2
X
i
i=1
n
n(n + 1) X
⇒ = i
2 i=1

Mukulika Ghosh | Parasol Lab - Texas A&M University 25/41


Permutation

Permutations and Combination


Permutation
Let S be a set with n elements. An ordered arrangement of r elements of S
is called an r−permutation of S. A permutation of S is an n−permutation.
The number of r−permutations of a set with n elements is denoted by
P (n, r).

Example: S = {1, 2, 3, 4}. Then (2, 4, 3) and (4, 3, 2) are two distinct
3−permutations of S.

Note: Order is important.

Mukulika Ghosh | Parasol Lab - Texas A&M University 26/41


Number of r-Permutations

Number of r-Permutations

Let n and r be positive integers, r ≤ n. Then P (n, r) = n(n − 1)...(n −


r + 1).

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)

Mukulika Ghosh | Parasol Lab - Texas A&M University 27/41


Number of r-Permutations

Let n be a positive integer, and r an integer in the range 0 ≤ r ≤ n. Then


n!
P (n, r) = (n−r)!

Proof: For r in the range 1 ≤ r ≤ n,


n!
(n−r)! = n(n − 1)...(n − r + 1)

For r = 0, we have P (n, 0) = 1, which equals n!/(n − 0)! = n!/n! = 1

Mukulika Ghosh | Parasol Lab - Texas A&M University 28/41


Number of r-Permutations

Example

How many permutations of the letters ABCDEFGH contain the string


ABC?

Let us regard ABC, D, E, F, G, and H as blocks. Any permutation of


these 6 blocks will yield a valid permutation containing ABC. Therefore,
we have 6! = 720 permutations of the letters ABCDEFGH that contain
ABC as a block.

Mukulika Ghosh | Parasol Lab - Texas A&M University 29/41


Combinations

Combinations

Let S be a set of n elements. An r−combination of S is a subset of r


elements from S.

Note: Order does NOT matter here

The number of r−combinations of a set S with n elements is denoted by


C(n, r) or nk


Mukulika Ghosh | Parasol Lab - Texas A&M University 30/41


Number of Combinations

Number of Combinations
The number of r−combinations of a set with n elements is given by
!
n n!
=
r (n − r)!r!

Proof. We can form all r−permutations of a set with n elements by


first choosing an r−combination and then ordering the r elements in all
possible ways.

Thus, P (n, r) = C(n, r)P (r, r)


Hence, C(n, r) = PP (n,r) n!/(n−r)!
(r,r) = r!/(r−r)!
n!
Since (r − r)! = 0! = 1, this yields C(n, r) = (n−r)!r!

Mukulika Ghosh | Parasol Lab - Texas A&M University 31/41


Exercise

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?

Mukulika Ghosh | Parasol Lab - Texas A&M University 32/41


Binomial Coefficient Identity

Binomial Coefficient Identity


n n 
It can be proved that r = n−r

Proof: Let S be a set with n elements. Each subset A of S has its


corresponding complement Ac , which contains the elements of S that are
not contained in A.

By double counting: The number C(n, r) of subsets of cardinality r of


S corresponds to the number of “complements of subsets of cardinality
r in S”. Since |A| = r iff |Ac | = n − r, the complements of subsets of
cardinality r of S correspond to subsets of cardinality n − r of S. Thus,
C(n, r) = Number of r−subsets of S = Number of complements of
r−subsets of S = C(n, n − r), as claimed

Mukulika Ghosh | Parasol Lab - Texas A&M University 33/41


Counting Subset Identity

Counting Subset Identity

For any non-negative integer n, we have


n
!
X n
= 2n
k=0
k

Proof: Let S be a set with n elements. The number of subsets of S is


2n . The number of subsets with 0, 1, 2, ..., n elements is given by
! ! ! !
n n n n
...
0 1 2 n

Mukulika Ghosh | Parasol Lab - Texas A&M University 34/41


Counting Subset Identity

Since subsets of S need to have between 0 and n elements, the claim


follows

Mukulika Ghosh | Parasol Lab - Texas A&M University 35/41


Binomial Theorem

Binomial Theorem

Let x and y be variables. Let n be a non-negative integer. Then (x+y)n =


n
P n k n−k
k x y
k=0

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.


Mukulika Ghosh | Parasol Lab - Texas A&M University 36/41


Binomial Coefficient Identity

Binomial Coefficient Identity


Let n be a positive integer. Then
n
!
X n
(−1)k =0
k=0
k

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.

Mukulika Ghosh | Parasol Lab - Texas A&M University 37/41


Pascal’s Identity

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:

First way of counting:


n+1
The set T clearly contains k subsets of size k

Mukulika Ghosh | Parasol Lab - Texas A&M University 38/41


Pascal’s Identity

Second way of counting:


Recall that T is a set with n + 1 elements. Let us consider an element
t of T . We will count the subsets of T of size k that : (a) contain the
element t, and (b) do not contain the element t.
n 
(a) There are k−1 subsets of T that contain t, since t is already chosen,
but the remaining k − 1 elements need to be chosen from T − {t}, a set
of size n.
(b) There are nk subset of T not containing t, since one can choose any


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)

Mukulika Ghosh | Parasol Lab - Texas A&M University 39/41


Vandermonde’s Identity

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

In particular, when choosing m = n = r, we get


! n
!2
2n X n
=
n k=0
k

Mukulika Ghosh | Parasol Lab - Texas A&M University 40/41


Vandermonde’s Identity

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

Mukulika Ghosh | Parasol Lab - Texas A&M University 41/41

You might also like