Lecture # 21
Lecture # 21
Lecture # 21
1
COUNTING
In combinatorics we generally solved counting problems.
4
BASIC COUNTING PRINCIPLES
The two basic counting principles are:
Product Rule
Sum Rule
5
EXAMPLE
Your institute is offering 7 courses in computer science
and 3 courses in mathematics. You are asked to choose
only one course.
How many choices you have?
n 1 + n 2.
7
EXAMPLE
A student can choose a computer project from one of the
three lists. The three lists contain 23, 15 and 19 possible
projects, respectively.
9
SUM RULE IN TERMS OF SETS
If A1, A2, …, Am are finite disjoint sets, then the number of
elements in the union of these sets is the sum of the
number of elements in them.
10
EXAMPLE
Suppose
There are 7 different optional courses in Computer
Science and
3 different optional courses in Mathematics.
7 3 = 21 choices.
11
THE PRODUCT RULE
If one event can occur in n1 ways and if for each of these
n1 ways, a second event can occur in n2 ways.
12
EXAMPLE
The chairs of an auditorium are to be labeled with two
characters, a letter followed by a digit.
13
SOLUTION
The procedure of labeling a chair consists of two events,
namely,
14
GENERALIZED PRODUCT RULE
If some event can occur in n1 different ways, and if,
following this event, a second event can occur in n2
different ways, and following this second event, a third
event can occur in n3 different ways, …, then the number
of ways all the events can occur in the order indicated is
n 1· n 2· n 3· …
15
PRODUCT RULE IN TERMS OF SETS
If A1, A2, …, Am are finite sets, then the number of
elements in the Cartesian product of these sets is the
product of the number of elements in each set.
16
EXERCISE
Find the number n of ways that an organization consisting of
15 members can elect a president, treasurer, and secretary.
(assuming no person is elected to more than one position)
SOLUTION:
The president can be elected in 15 different ways;
The treasurer can be elected in 14 different ways;
The secretary can be elected in 13 different ways.
Thus, by product rule, there are
n = 15 x 14 x 13 = 2730
different ways in which the organization can elect the
officers.
17
EXERCISE
There are four bus lines between A and B; and three bus
lines between B and C.
18
SOLUTION
(a) There are 4 ways to go from A to B and 3 ways to go from B
to C;
hence there are
4 x 3 = 12 ways to go from A to C by way of B.
4 3 2 3
i.e., A B C B A
20
EXERCISE
How many bit strings of length 8
21
SOLUTION
(i) If the first bit (left most bit) is a 1, then it can be filled in
only one way.
Hence,
there are 1 x 2 x 2 x 2 x 2 x 2 x 2 x 2 = 27 = 128 different
bit strings of length 8 that begin with a 1.
22
(ii) If the first and last bit in an 8 bit string is a 1, then only
the intermediate six bits can be filled in 2 ways, i.e. by a 0
or 1.
23
EXERCISE
Suppose that an automobile license plate has three letters
followed by three digits.
24
SOLUTION
Each of the three letters can be written in 26 different
ways, and each of the three digits can be written in 10
different ways.
letters digits
25
(b) How many license plates could begin with A and end on
0?
SOLUTION:
The first and last place can be filled in one way only, while
each of second and third place can be filled in 26 ways and
each of fourth and fifth place can be filled in 10 ways.
letters digits
A 0
27
SOLUTION
First consider variable names one character in length.
Since such names consist of a single letter, there are 26 variable
names of length 1.
29
SOLUTION
Number of code words of length 1 = 261
Number of code words of length 2 = 262
Number of code words of length 3 = 263
30
NUMBER OF ITERATIONS OF A
NESTED LOOP
Determine how many times the inner loop will be iterated
when the following algorithm is implemented and run
for i: = 1 to 4
for j : = 1 to 3
[number of statements]
next j
next i
31
SOLUTION
The outer loop is iterated four times, and during each
iteration of the outer loop, there are three iterations of the
inner loop.
32
EXERCISE
Determine how many times the inner loop will be iterated
when the following algorithm is implemented and run.
for i = 5 to 50
for j: = 10 to 20
[number of statements]
next j
next i
33
SOLUTION
The outer loop is iterated 50 - 5 + 1 = 46 times and
34
EXERCISE
Determine how many times the inner loop will be iterated
when the following algorithm is implemented and run.
for i = 1 to 4
for j: = 1 to i
[number of statements]
next j
next i
35
The outer loop is iterated 4 times, but during each iteration of
the outer loop, the inner loop iterates different number of times.
36
THE PIGEONHOLE PRINCIPLE
37
THE PIGEONHOLE PRINCIPLE
Its very useful principle for many counting problems.
38
This illustrates a general principle called the pigeonhole
principle, which states that if there are more pigeons
than pigeonholes, then there must be at least one
pigeonhole with at least two pigeons in it.
39
40
REVISION OF FUNCTIONS
42
PIGEONHOLE PRINCIPLE
We define a function from A to B. If A has more elements
then B. B must have element which is image of more than
one element of A.
43
The following is a function.
44
PIGEONHOLE PRINCIPLE
A function from a set of k + 1 or more elements to a set of
k elements must have at least two elements in the domain
that have the same image in the co-domain.
45
EXAMPLES
1. Among any group of 367 people, there must be at least
two with the same birthday, because there are only 366
possible birthdays.
46
EXERCISE
What is the minimum number of students in a class to be
sure that two of them are born in the same month?
SOLUTION:
There are 12 (= n) months in a year.
The pigeonhole principle shows that among
any 13 (= n + 1) or more students there must be
at least two students who are born in the same month.
47
EXERCISE
Given any set of seven integers, must there be two that have
the same remainder when divided by 6?
SOLUTION:
The set of possible remainders that can be obtained when
an integer is divided by six is {0, 1, 2, 3, 4, 5}.
SOLUTION:
There are 20 integers from 1 through 100 that are
divisible by 5.
Hence there are 80 integers from 1 through 100 that are
not divisible by 5.
Thus by the pigeonhole principle 81 = 80 + 1 integers
from 1 though 100 must be picked in order to be sure of
getting one that is divisible by 5.
49
EXERCISE
Let A = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}. Suppose six integers are chosen
from A. Must there be two integers whose sum is 11.
SOLUTION:
The set A can be partitioned into five subsets:
{1, 10}, {2, 9}, {3, 8}, {4, 7}, and {5, 6} each consisting
of two integers whose sum is 11.
These 5 subsets can be considered as 5 pigeonholes.
If you pick six elements. Then you have to pick one set from above sets.
50
GENERALIZED PIGEONHOLE
PRINCIPLE
Imagine we have 10 pigeonholes, and we want to ensure
that at least one pigeonhole have more than 2 pigeons in
it.
51
GENERALIZED PIGEONHOLE
PRINCIPLE
A function from a set of nk + 1 or more elements to a set
of n elements must have at least k + 1 elements in the
domain that have the same image in the co-domain.
52
EXERCISE
Suppose a laundry bag contains many red, white, and blue
socks.
53
SOLUTION
Here there are n = 3 colors (pigeonholes)
and k + 1 = 4 or k = 3.
54
FLOOR & CEILING FUNCTIONS
Given any real number x, the floor of x, denoted x, is the
largest integer smaller than or equal to x.
55
EXAMPLE
Compute x and x for each of the following values of x.
a. 25/4 b. 0.999 c. –2.01
SOLUTION:
a. 25/4 = 6 + ¼ = 6
25/4 = 6 + ¼ = 6 + 1 = 7
b. 0.999 = 0 + 0.999 = 0
0.999 = 0 + 0.999 = 0 + 1 = 1
57
EXAMPLE
We have 100 people and we want to know how many of
them are born in same month?
Solution:
n = 12 months (pigeonholes)
The required no. is 100/12 = 8 + 1/3 = 9 who were
born in the same month.
58
EXERCISE
What is the minimum number of students required in a
Discrete Mathematics class to be sure that at least six will
receive the same grade, if there are five possible grades,
A, B, C, D, and F.
59
SOLUTION
We want to ensure that there are 6 students who have the
same grade that is
N/5 = 6 (given)
60