You are on page 1of 99

Discrete

Mathematics

COUNTING
Dr. Zalak A. Patel
Asst. Professor, Mathematics
L. D. College Of Engineering
The Product Rule
Suppose that a Procedure can be broken
down into a sequence of two tasks.

If there are n1 ways to do first task and n2


ways to do the second task after the first
task has been done, then there are n1n2
ways to do the procedure.
Example
The chairs of an auditorium are to be
labelled with an uppercase English
letter followed by a positive integer not
exceeding 100.
What is the largest number of chairs
that can be labelled differently?
Example

• How many different bit strings of


length seven are there?
The Product Rule

Consider the game of tossing a coin, then


rolling a die, then picking a card.

One possible event would be (H, 2, 2clubs).

How many ways are in there to complete the


task?
The Product Rule

One way to visualize this counting


problem is to construct a possibility tree,
where each intermediate leaf branches
out successively according to the type of
task completed at that stage.
Coin - Die - Card (Start)
Possibility Tree
Heads Tail

123 4 5 6 1 2 3 4 56

2c...As 2c...As ... 2c...As


The Product Rule
The total number of ways of generating
output from this is obtained by counting t
he number of leaves at the end of the
tree. Clearly in this case the number is
2652 = 624 events.
Problem : License Plates
How many possible license plates could be
issued without duplication?
If an RTO issued auto license plates using
the following scheme:
Letter Letter Letter Digit Digit Digit

(where Letter = A,B,...,Z and Digit = 0,1,2,...,9).


Problem : License Plates
Answer: 26

How about
Letter Digit Letter Digit Letter Digit?

Answer: 26
Problem : Telephone Numbering Plan
If the telephone numbers of specific city
has format NYX-NNX-XXXX (Area Code –
office code – station code), where N
denotes the digits 2 to 9, X denotes the d
igits 0 to 9,and Y must be either 0 or 1, th
en how many different numbers are pos
sible under the said plan?
Telephone Numbering Plan
Under scheme NYX-NNX-XXXX,
Area code NYX : 8 . 2. 10 =160
Office code NNX : 8. 8. 10 = 800
Station code XXXX : 10. 10. 10 = 1000
Total possible numbers are,
NYX-NNX-XXXX = 160. 800. 1000
= 1,024,000,000 .
Cartesian Products & Strings

If a set A has m elements and a set B


has n elements, number of elements i
n A  B are |A  B| = |A||B| = mn.
The Sum Rule
If a first task can be done in n1 ways and
second task in n2 ways and if these task
can not be done at the same time, then
there are n1+ n2 ways to do one of these
tasks.
Problem : Sum Rule
If either a member of the mathematics
faculty or a student who is mathematics m
ajor to a University committee.
How many different choices are there for
this representative if there are 37 members
of mathematics faculty and 83 mathematics
majors?
Total ways : 37 + 83 = 120 possible ways.
Having following properties how many
possible passwords are there?
 Six to eight characters long
 Each character is an uppercase letter or a
digit
 Each password must contain at least
one digit
Let P be the total number of possible
passwords, and let P6, P7, and P8 denote
the number of possible passwords of
lengths 6, 7, and 8, respectively.

By the sum rule, P = P6 + P7 + P8.


P6 = the number of strings of six characters
is 366, and the number of strings with
no digits is 266
= 366 − 266
= 2,176,782,336 − 308,915,776
=1,867,866,560.
P7 = 367 − 267
= 78,364,164,096 − 8,031,810,176
= 70,332,353,920
and
P8 = 368 − 268
= 2,821,109,907,456 − 208,827,064,576
= 2,612,282,842,880
P = P6 + P7 + P8 = 2,684,483,063,360.
Counting Internet Addresses
The Internet Protocol (IPv4) uses IP address
of 32 bits consisted by netid followed by
hostid, to identify a computer as a member
of particular network.
Three forms of address are used

How many different IPv4 addresses are


available for computers on the Internet?
if
There are several restrictions on addresses
because of special uses:

1111111 is not available as the netid of a


Class A network
The hostids consisting of all 0s and all 1s are
not available for use in any network.
A computer on the Internet has either a Class
A, a Class B, or a Class C address.
Let x be the number of available addresses
for computers on the Internet, and let xA,
xB , and xC denote the number of Class A,
Class B, and Class C addresses available,
respectively.

By the sum rule, x = xA + xB + xC.


• To find xA,
Note that there are 27 − 1 = 127 Class A net
ids, as the netid 1111111 is unavailable.
Also, for each netid,
there are 224 − 2 = 16,777,214 hostids, as th
at the hostids consisting of all 0s and all 1s
are unavailable.
Hence, xA = 127 . 16,777,214 =2,130,706,178
Similarly
xB = (214 = 16,384 ) . (216 − 2 = 65,534)
and
xC = (221 = 2,097,152) . (28 − 2 = 254 )
Hence, xB = 1,073,709,056 and
xC = 532,676,608.
• Finally the total number of IPv4
addresses available is
x = xA + xB + xC
= 2,130,706,178 + 1,073,709,056
+ 532,676,608
= 3,737,091,842.
Counting for partition of set

If a finite set A is partitioned by the co


llection {A1, A2, ..., An}.

Then:

n(A) = n(A1) + n(A2) +...+ n(An).


Example : Let D be set of 3-digit integers
(from 100 to 999) which are divisible by 5.
How big is D?
Solution:
Let a typical 3-digit integer be abc,
where a is one of {1,2,3,4,5,6,7,8,9},
and b is one of {0,1,2,3,4,5,6,7,8,9}.
An integer is divisible by 5 if it ends in
a 0 or 5.

hence the required integers are of the f


orm ab0 and those of the form ab5.

Hence number of elements in D are

910 + 910 = 180 elements.


License Plates
We have already used the addition rule
without realizing it in the last section.
When we are counting the number of l
icense plates with certain properties an
d allow a particular character to be eith
er a digit or a letter, we have applie
d the addition rule:
The slot drawing
(Digit or Letter) (Digit or Letter) ...
gives us the counts

(26 + 10)  (26 + 10)...


The Subtraction Rule
(Inclusion–Exclusion for Two Sets)
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 are common to
the two different ways.
The above rule is also called
Inclusion–Exclusion Rule

Suppose that A1 and A2 are sets.

Then, there are |A1| ways to select an


element from A1 and |A2| ways to select a
n element from A2 .
The number of ways to select an element
from A1 or from A2, that is, the number of
ways to select an element from their
union, is the sum of the number of ways
to select an element from A1 and the
number of ways to select an element
from A2 , minus the number of ways to
select an element that is in both A1 and A2
Because there are |A1 A2 | ways to select
an element in either A1 or in A2, and
|A1 ∩ A2| ways to select an element
common to both sets, we have

|A1 A2| = |A1| + |A2| − |A1 ∩ A2|.


Inclusion - Exclusion Example
• How many 6-character license plates
begin with “A” or end with “9”?
• Effectively,
we want to count all plates of the forms
Axxxxx or xxxxx9, but recognizing that
these individual cases overlap for plates of
the form Axxxx9.
• Now
|{Axxxxx}| = 365, and |{xxxxx9}| = 365,
and |{Axxxx9}| = 364,
hence the total number of plates are
2365 - 364.
Inclusion - Exclusion Rule for 3 Sets

If A, B, and C are sets, then:


|A  B  C|
= |A|+|B|+|C||AB||AC||BC|+|ABC|
What About For 3 Sets?
1 4 2 • Using the labeling in t
6
7
5 he above drawing, we
3 see that

• A = 1  4  6  7, B = 2  4  5  7,
and C = 3  5  6  7.
Thus,
|A  B  C|
= |A| + |B| + |C|  |AB|  |AC|  |BC|
+ |ABC|
= (1+4+6+7+2+4+5+7+3+5+6+7)
(475767) (+7)
= 1+2+3+4+5+6+7
• Example: The CS department teaches
Algol, Basic, and C languages.
Suppose:
– 22 students study Algol; 30 study Basic; 4
2 study C;
– 12 study Algol and Basic;
– 18 study Basic and C;
– 16 study Algol and C;
– 9 study all three.
• How many students study a language?
Answer:
57 = 22+30+42121816+9
Counting Elements in a List
Theorem: If m and n are integers with
m  n, then there are (n  m + 1) integers
from m to n.
Hence number of integers from 1 to 100
is 100  1 + 1 = 100.
Number of integers from 5 to 18 is
18  (5) + 1 = 24.
Counting Things Without a Condition
How many 3-digit integers are not divisible by
5?
Before, we saw that there are 180 3-digit int
egers which are divisible by 5,
hence: {all 3-digit integers not divisible by 5}
= {all 3-digit integers}  {all 3-digit
integers divisible by 5}.
Therefore there are
(999  100 + 1)  180 = 720
3-digit integers which are not di
visible by 5.
Tree Diagramas
• How many bit strings of length four do not
have two consecutive 1s?
• A playoff between two teams consists of at
most five games. The first team that wins
three consecutive games wins the playoff.
In how many different ways can the
playoff occur?
The Division Rule
Theorem:

Suppose a set A has n elements and is

partitioned by the collection {A1, A2, ..., Ap},


where each partition set has m elements.
Then: p = n/m.
• In other words, if a set is partitioned into
equal-sized partition sets, then the number of
partition sets is the quotient of the size of the
set with the size of any partition set.

• For example, if a set has 100 elements and


is partitioned in 20-element subsets, then
there must be 5 subsets.
Example

• How many ways 4 people can sit around a


circular table if one do not have the same
left or right neighbor?
The Pigeonhole Principle
• If k is a positive integer and k + 1 or
more objects are placed into k boxes,
then there is at least one box
containing two or more of the objects.
Examples

• How many students must be in a class


to guarantee that at least two student
s receive the same score on the final
exam, if the exam is graded on a scale
from 0 to 100 points?
• Among any group of 367 people,
there must be at least two with the
same birthday, because there are only
366 possible birthdays.
• In any group of 27 English words,
there must be at least two that begin
with the same letter, because there
are 26 letters in the English alphabet.
The Generalized Pigeonhole Principle
• If N objects are placed into k boxes,
then there is at least one box conta
ining at least objects.
Permutations
A permutation of a collection of objects is a
n ordering of the objects in a row.
A permutation is a one-to-one and onto ma
pping of a set to itself.
List: abcde  acdbe
a a
b
Bijective c
b
c
Function: d
e
d
e
Counting Permutations
To count how many permutations(orderings)
of n things there are, consider it in terms of
filling in slots:

n (n-1) (n-2) ... 3 2 1.

We denote this product as n!.


Counting Permutations
• The number of different orderings of 6
distinct books on a shelf is

6! = 654321 = 720.

• We define 0! = 1 because it makes things


work.
Counting Permutations
• How many orderings of the letters of the
word COMPUTER are there?

COMPUTER

Answer: 8! = 40,320
Counting Permutations
• How many orderings of the letters of the
word COMPUTER are there if the letters C
O must stay together in this order?

CO M P U T E R

Answer: 7! = 5,040
More Counting Permutations
• What is the probability of the CO will
appear in a given permutation of them
letters of COMPUTER?

Answer: 7!/8! = 7!/(87!) = 1/8.


Circular Permutations

Permutations are a linear ordering.

However, we can ask how many ways

can we order things around a circle

(or other closed polygon).


Circular Permutations
In this case, the number of ways to arrange n
things in a circle (square, hexagon, etc.) is
(n1)! as placing the first element does not
matter. Consider ABCDE around a circle:
A E D C B
E B D A C E B D A C

D C C B B A A E E D
Partial Permutations
If we don’t want to list out all n elements in
a linear permutation. Suppose we only wan
t the first r elements, for r < n.
Total = n!/(nr)!
We denote the partial permutation P(n,r).
Partial Permutations
Theorem:
P(n,r) = n(n1)...(nr+1) = n!/(nr)!
How many 5-letter strings can be formed
from the letters of COMPUTER?
Answer: P(8,5) = 8!/(85)! = 8!/3!
= 87654
Evaluating Partial Permutations
How many 6-character license plates can
be made if a character can be a letter or
digit, but no character can repeat?

Answer:

P(36,6) = 36!/30! = 363534333231


Summary
Multiplication Rule: If there are m ways
to do A and n ways to do B, then there ar
e (mn) ways to do A and B.

(order matters & repetition allowed)


Summary
Permutations
– There are n! linear orderings of n things.
– There are n!/n = (n1)! circular orderings
of n things.
– There are P(n,r) = n!/(nr)! orderings of
r things from a total of n things.
(order matters & NO repetition)
• Let abcdefgh denotes 8 people and if we
want to arrange them on round table in a
way that couple ab cannot be sit together.
Then number of possible arrangements
for people Xcdefgh to sit on round table is
7!
• Removing both the ab and ba orderings.
• Answer = 7!  6!  6! = 7!  26!.
Counting Subsets of a Set
• Till now we looked at counting events
with or without repetition, but in either in
stance the order of the elements mattered
• Now, relaxing the order restriction to
allow counting set structures where
events are not distinguished by the order
of elements, but by the mere clustering
of elements together.
Counting Subsets
• How many 3-element subsets of a
4-element set are there:
• Let A = {1,2,3,4} then all 3-permutations
are:
123, 132, 213, 231, 312, 321  {1,2,3}
124, 142, 214, 241, 412, 421  {1,2,4}
134, 143, 314, 341, 413, 431  {1,3,4}
234, 243, 324, 342, 423, 432  {2,3,4}.
• # 3-element subsets
= (# 3-permutations)
(# 3-orderings)
= P(4,3) / 3!
= 4! / (1!3!)
= 4! / 3!
= 4.
Combinations
• What we have just counted is a combination.
of elements taken 3 at a time.
• Hence the number of choices to choose k
objects from n objects are n
(k)= n!
k!(n  k)!
In general, C(n,k) = P(n,k) / k!
More Counting Subsets
• How many subsets of a 10-element set have
3 elements? How many have 7 elements?
• Solution: C(10,3) = 10! / (3!7!)
C(10,7) = 10! / (7!3!), the same!
• Note: Counting subsets containing 3 elements
is the same as counting subsets NOT containi
ng the other 7 elements!
• Theorem: C(n,k) = C(n,nk).

• How many subsets have at least 8 elements?


Solution: C(10,8) + C(10,9) + C(10,10)
Counting Binary Strings
• How many 10-bit strings have three 1’s and
at least three 1’s ?
• Solution: 10-bit strings having three 1’s means
we have to place 1 in three of the ten slots then
the other seven remaining slots by a 0.
Thus the number of 10-bit strings that have
three 1’s is C(10,3) = 10! / (3!7!).
• atleast three 1’s
C(10,3) + C(10,4)+… + C(10,10)
• In general, the number of n-bit binary
strings with density k is C(n,k).
• Here as before, having k 1’s is the same
thing as having (n  k) 0’s.
Counting Teams
• To consist a 5-person team from a group
of 5 men and 7 women how many teams
can they make with 3 men and 2 women?

C(5,3)C(7,2) = [5!/(3!2!)][7!/(5!2!)]
= 7!/(3!2!2!).
• How many teams have at least 1 man?
(All  teams w/no man)
= C(12,5)  C(7,5)
= [12!/(7!5!)]  [7!/(5!2!)]
• How many teams have at most 1 man?
(teams w/no man) + (teams w/1 man)
= C(7,5) + C(5,1)C(7,4)
= 7!/(5!2!) + [5!/4!][7!/(3!4!)]
Generalized Permutations
Example:
we learned how to count the number of orderings
of the letters of COMPUTER.
In this case, we note that not all the letters are
distinct.
What about the number of orderings of the letters
of MISSISSIPPI?
• In particular,
for word MISSISSIPPI, number of linear
arrangements are 11!, Out of which
for letter S the same arrangements are 4!
for letter I the same arrangements are 4!
for letter P the same arrangements are 2!
for letter M the same arrangements are 1!
This leaves us with a total count of 11!/4!4!2!.
Generalized Permutations
• Modelling this problem, purely as a combination
and not a permutation at all, we can reason the
task as:
1. Choose 4 slots from 11 for the I’s;
2. Choose 4 slots from the remaining 7
for the S’s;
3. Choose 2 slots from the remaining 3
for the P’s;
4. Place the M (only 1 way remaining).
with this answer is
C(11,4)C(7,4)C(3,2)C(1,1)
=(11!7!3!)/(7!4!4!3!2!1!)
= 11!/(4!4!2!).
• This leads us to state a theorem…
Generalized Permutation Theorem
• Theorem:
Suppose a collection consists of n objects
of which: n1 are of type 1, indistinguishable
from each other; n2 are of type 2, indistingui
shable from each other; ... nk are of type k,
indistinguishable from each other;
and n1 + n2 + ... + nk = n, then the number
of distinct permutations of the n objects is:
C(n,n1)C(nn1,n2)C(nn1n2,n3)...C(nk,nk)
=n! / (n1!n2!n3!...nk!).
Combinations with Repetition
• In the last section, we saw how to count
combinations, where order does not matter,
based on permutation counts, and we saw
how to count permutations where repetitions
occur.
• Now, we shall consider the case where
we don’t want order to matter, but we will
allow repetitions to occur.
• This will complete the matrix of counting
formulae, indexed by order and repetition.
Counting Generalized Combinations
Theorem:
The number of ways to fill r slots from
n categories with repetition allowed is:
C(r + n  1, r) = C(r + n  1, n  1).

In words, the counts are:


C(#slots + #transitions, #slots)
or C(#slots + #transitions, #transitions).
When to Use Generalized Combinations
• Besides categorizing a problem based on its
order and repetition requirements as a
generalized combination, there are a couple
of other characteristics which help us sort:
In generalized combinations, having all
the slots filled in by only selections from one
category is allowed; It is possible to have
more slots than categories.
Example
• How many ways can I select 15 cans of soda
from a cooler containing large quantities of
Coke, Pepsi, Diet Coke, Root Beer & Sprite?
Solution: The number of ways to select 15
sodas from a collection of 5 types of
soda is
C(15 + 4,15) = C(19,15) = C(19,4)
Example

• How many ways can I fill a box holding 100


pieces of candy from 30 different types of
candy? How many ways if I must have
at least 1 piece of each type?
Example
Solution: Here #slots = 100,
#transitions = 30  1,
so there are C(100+29,100) = 129!/(100!29!)
different ways to fill the box.
Now, we are reducing the #slots to choose
over to (100  30) slots, so there are
C(70+29,70) = 99!/70!29!
Integer Solutions to Equations
• How many non-negative integer solutions are
there to the equation a + b + c + d = 100.
Here, #slots = 100 and we are ranging over 4
categories a, b, c, and d. so, #transitions = 3.
Therefore, there are
C(100+3,100) = 103!/100!3! non-negative
solutions to a + b + c + d = 100.
Integer Solutions with Restrictions
• How many integer solutions are there to:
a + b + c + d = 15,
when a  3, b  0, c  2 and d  1?
Solution: Out of 15 slots,3 slots, 2 slots and 1
slot must be filled by a, c and d respectively.
Hence, the number of slots has effectively been
reduced to 9 after accounting for a total of 6
restrictions,
Thus there are C(9+3,9) = 12!/(9!3!) solutions.
More Integer Solutions & Restrictions
• How many integer solutions are there to:
a + b + c + d = 15,
when a  3, b  0, c  2 and d  1?
• In this case, we alter the restrictions and
equation so that the restrictions “go away.”
To do this, we need each restriction  0 and
balance the number of slots accordingly.
Hence,
a  3+3, b  0, c  2+2 and d  1+1,
converts equation to
a + b + c + d = 15+3+2+1 = 21
So, there are
C(21+3,21) = 24!/(21!3!) solutions.
Summary
• Theorem:

The number of integer solutions to:


a1 + a2 + a3 +...+ an = r,
when a1  b1, a2  b2, a3  b3 , ..., an  bn is
C(r+n1b1b2b3...bn , rb1b2b3...bn).
• Theorem:

The number of ways to select r things from


n categories with b total restrictions on the
r things is C(r + n  1  b , r  b).
• Corollary:

The number of ways to select r things from


n categories with at least 1 thing from each
category is C(r  1 , r  n) (set b = n).
Pascal’s Triangle
Recall the number array we call Pascal’s Triangle:
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
1 6 15 20 15 6 1
Rule of generation: T(n,r) = T(n1,r1) + T(n1,r).
Binomial theorem
For any numbers a and b and non negative
integer (a + b)n = c(n,0)an b0+ c(n,1)an-1 b1 +
c(n,2)an-2 b2 +…+ c(n,n)a0 bn.
• However, the Binomial Theorem tells us each
of these coefficients is of the form C(n,r).
• Thus each term of Pascal’s Triangle is
actually a combination, that is T(n,r) = C(n,r).

You might also like