Counting Principles-Sum &product Rules
Counting Principles-Sum &product Rules
Counting
4.1
Counting Principles
Combinatorics, the study of arrangements of objects, is an important part of
discrete structures. Enumeration, the counting of objects with certain properties,
is an important part of Combinatorics. Counting is used to determine the
complexity of algorithms and it is also required whether there are enough
internet protocol addresses to meet the demand. Further, counting techniques
are extensively used when probabilities of events are computed.
In this module we introduce the basic methods of counting. These methods serve
as the foundation for almost all counting techniques.
Basic counting principles: There are two basic counting principles: (i) the product
rule and (ii) the sum rule.
The Product Rule: Suppose that a procedure can be broken down into a sequence
of two tasks. If there are ways to do the first task and for each of these ways of
doing the first task, there are ways to do the second task, then there are
ways to do the procedure.
This can be proved by mathematical induction from the product rule of two tasks.
Example 1: How many bit strings of length seven are there?
Solution: Each of the seven bits can be chosen in two ways, because each bit is
either or . Therefore, by the product rule there are
How many functions are there from a set with elements to another set with
elements.
How many one-to-one functions are there from a set with elements to
another set with elements?
one-to-one functions from a set with elements to another set with elements.
Note: The product rule is often phrased in terms of sets as given below:
If 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. To
relate this to the product rule, note that the task of choosing an element in the
Cartesian product is done by choosing an element in , an
element in , …, and an element in . By the product rule,
Sum Rule: If a task can be done in either in one of ways or in one of ways,
where none of the set of ways is the same as any of the set of ways, then
there are ways to do the task.
Example 3: 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 list. How many possible projects are there to choose from?
Solution: The student can choose a project by selecting from the first list, the
second list, or the third list. Because no project is on more than one list, by sum
rule there are 23+15+19=57 ways to choose a project.
Solution: Let be the number of variable names in this version of BASIC. Let
and be number of variable names of one character long and two characters
long respectively. By the sum rule, .
Further, by the product rule there are strings of length two that begin
with a letter and end with an alphanumeric character. However, five of these are
excluded, so .
Suppose that a task can be done in or ways, but that some of the set of
ways to do the task are the same as some of ways to do the task. In this
situation, we cannot use the sum rule to count the number of ways to do the task.
Adding the number of ways to do the tasks in these two ways leads to an
overcount, because the ways to do the task in the two ways that are common are
counted twice. To correctly count the number of ways to do the task, we add the
number of ways to do it in one way and the number of ways to do it in the other
way, and then subtract the number ways to do the task in both among the set of
ways and the set of ways. This technique is called the principle of
inclusion -exclusion or subtraction principle for counting.
We can phrase this principle in terms of sets.
Let and be finite sets. There are and ways to select an element from
and respectively. The number of ways to select an element from is the
sum of the number of ways to select an element from and , minus the number
of ways to select an element from . That is
Example 5: How many bit strings of length eight either start with a bit or end
with the two bits ?
Solution: Let and be the set of bit strings of length eight that start with and
end with respectively. Then consists of all bit strings that start with
and end with . Required to find .
Note that, we can construct a bit string of length eight that starts with in
ways. This follows by the product rule, because the first bit can be
chosen in one way and each of the other seven bits can be choosen in two ways.
Thus, .
We can construct a bit string of length eight that ends with in ways.
This follows by the product rule, because each of the first six bits can be chosen in
two ways and the last two bits in only one way. Thus, .
We can construct a bit string of length eight that begins with 1 and ends with
in ways. This follows by the product rule, because the first bit, the last
two bits can be chosen in only one way and each of the five bits in between first
bit and last two bits can be chosen in two ways. Thus, .
Thus, the number of bit strings of length eight that begin with or that end with
is .
Tree Diagrams
Counting problems can be solved using tree diagrams. A tree consists of a root, a
number of branches leaving the root, and possible additional branches leaving the
end points of other branches. To use trees in counting, we use a branch to
represent each possible choice. We represent the possible outcomes by the
leaves.
Example 6: How many bit strings of length four do not have two consecutive 1s?
Solution:
The tree diagram displays all bit strings of length four without two consecutive 1s.
There are eight bit strings of length four without two consecutive 1s.
Example 7: Suppose that I love India T-shirts come in five different sizes:
and . Suppose that each size comes in four colors, white, red,
green and black, except for which comes only in red, green and black, and
which comes only in green and black. How many different T shirts does a
souvenir shop have to stock to have at least one of each available size and color
of the T-shirt?
Solution:
The tree diagram displays all possible size and color pairs. The shop owner need
to stock 17 different T-shirts.
Solution: Let be the set of positive integers not exceeding 1000 that are divisible
by 7 and let be the set of positive integers not exceeding 1000 that are divisible
by 11. Then is the set of positive integers not exceeding 1000 that are
divisible by 7 or 11, and is the set that are divisible by 7 and 11. Then
There are positive integers not exceeding 1000 that are divisible by or .
Note: The number of positive integers not exceeding 1000 that are not divisible
and not divisible are .
Proof:
Now,
Thus,
Solution: Let and be the sets of students who have taken Spanish, French
and Russian. Then, . Further,
and .
i.e.,
and so .
Therefore, there are seven students who have taken courses in all the three
languages.
This form can be used to solve problems that ask for the number of elements in a
set that have none of properties .
Let be the subset of containing the elements that have the property
.
Because the only primes less than 10 are 2,3,5, and 7; the primes not exceeding
100 are: these four primes and the number of those primes greater 1 and not
exceeding 100 that are divisible by none of 2,3,5,7. Now, we have to consider
, since 1 is neither prime nor composite and .
Let be the property that an integer is divisible by 2 let be the property that
an integer is divisible by 3 ,let be the property that an integer is divisible by 5 ,
and let be the property that an integer is divisible by 7.
Note: The Sieve of Eratosthenes is used to find all primes not exceeding a
specified positive integer.
Example 11: How many onto functions are there from a set with six elements
to a set with four elements.
Let and be the properties that and are not in the range of
the function, respectively. Now, a function is onto iff it has none of the properties
or . The number of onto functions is given by and by
the principle of inclusion-exclusion.
Note that is the number of functions that do not have in their range, for
.
4
Therefore, for all and there are C1 terms of this kind.
4
Further, for and there are C2 terms of this kind.
4
Similarly, for and there are C3 terms of this
kind and because this term is the number of functions that
have none of in their range. Clearly there are no such functions.
Therefore, the number of onto functions from a set with six elements to a set
with four elements is given by
4 4 4 4
C1 C2 C3 C4
The following is the general result related to the number of onto functions from a
set with elements to the set with elements, where .
n n n
C1 C2 Cn1
Example 12: How many ways are there to assign five different jobs to four
different employees if every employee is assigned at least one job?
Solution: Consider the assignment of jobs as a function from the set of five jobs to
the set of four employees. An assignment where every employee gets at least one
job is the same as an onto function from the set of jobs to the set of employees.
By Theorem 3 there are
4 4 4
C1 C2 C3
ways to assign the jobs so that each employee is assigned at least one job.
Derangements
Proof: Let be the set of all permutations of the set with elements.Clearly
. Let be the property of fixing an element in a permutation of ,
. The number of derangements is the number of permutations of
having none of the properties , for . That is
n
Because there are Cm ways to choose elements from elements,
n
C1
n
C2
n
In general Cm . Thus,
n n n
C1 . C2 . Cn .
P1:
How many strings are there of lowercase English letters of length four or less?
Solution:
26 26
26 26
Note that there is one string of length zero called empty string:
It is customary to take this empty string in the counting when we want to find
the number of strings of length or less.
The number of strings of length four or less of lower case English letters
.
P2:
Each user on a computer system has a password, which is six to eight character
long, where each character is an uppercase English letter (A – Z) or a digit
(0 – 9). Each password must contain at least one digit. How many possible
passwords are there?
Solution:
Let be the total number of possible passwords, and let and denote the
number of passwords of length 6, 7, and 8 respectively. By the sum rule
To find , find the number of strings of uppercase letters and digits that are six
characters long and subtract from this, the number of strings with no digits. By
the product rule we see and . Thus, .
Similarly, and .
Therefore
P3
a. are divisible by or
b. are not divisible by either or
c. are divisible by exactly one of and
Solution:
Let . Then .
Let be the set of positive integers between 100 and 999 (both inclusive),
which are divisible by , respectively.
The set is the set of positive integers divisible by 3 and 4. Since 3 and 4 are
relatively prime.
c. The set of positive integers which are divisible by exactly one of 3 and 4 is
given by
Now
P4:
How many license plates can be made using either two or three letters followed
by either two or three digits?
Solution:
26 10
26 10
By product rule,
26 10 10
10
26 10
By product rule,
26 26 10
10
26 10
By product rule,
(iv) Three letters followed by three digits
26 26 10
10
26 10 10
By product rule,
Note that
P5:
How many functions are there from the set , where is a positive
integer, to the set
Solution:
The number of one-to-one function from a set with elements to a set with -
elements is
if
if
if , .,
if
(b) The number of functions that map and to 0 is equal to the number
functions from the set to the set is if .
If then the number functions that map to is 1.
(c) Notice that there are positive integers less in . Suppose
that we select one of positive integer less than , say . If only is mapped
to and no others less than then must be
mapped to 0 and can be mapped either to 0 or 1.
Thus, we have two such functions. Since can chosen in ways, the
number of such functions is , (by product rule).
P6:
Solution:
For example, the bit string 0110110 of length 7 is a palindrome. The bit string
101101 of length 6 is a palindrome
Case (i) Suppose that is even say , for some positive integer .
Case (ii) Suppose that is odd, say , for some positive integer .
entry
Note: In the case of bit strings, the alphabet is . If the alphabet is of order
then the number of palindromes of length is
if is even
if is odd
P7:
Solution:
Let be the set of positive integers not exceeding which are divisible by .
Let be the set of positive integers not exceeding which are divisible by .
Then
Thus, the number of positive integers not exceeding are divisible either by
or by is .
P8:
Use a tree diagram to fine the number of ways to arrange the letters and
such that is not followed immediately by .
Solution:
The tree diagram displays arrangements of the letters and such that is
not followed immediately by . There are such arrangements.