0% found this document useful (0 votes)
55 views25 pages

Counting Principles-Sum &product Rules

This document covers basic counting principles in combinatorics, including the product and sum rules, and their applications in counting functions, one-to-one functions, and variable names. It also introduces the inclusion-exclusion principle for accurately counting overlapping sets and provides examples of its application in various counting problems. Additionally, it discusses tree diagrams for visualizing counting problems and concludes with the concept of derangements and their formula.

Uploaded by

srp.ch12
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)
55 views25 pages

Counting Principles-Sum &product Rules

This document covers basic counting principles in combinatorics, including the product and sum rules, and their applications in counting functions, one-to-one functions, and variable names. It also introduces the inclusion-exclusion principle for accurately counting overlapping sets and provides examples of its application in various counting problems. Additionally, it discusses tree diagrams for visualizing counting problems and concludes with the concept of derangements and their formula.

Uploaded by

srp.ch12
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/ 25

Unit-4

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 applies when a procedure is made up of separate tasks.

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.

An extended version of the product rule is often useful.


Suppose that a procedure is carried out by performing the tasks in
sequence. If each task , , can be done is ways, (regardless of
how the previous tasks were done), then there are ways to carry out
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

different bit strings of length seven.

Example: Counting Functions

How many functions are there from a set with elements to another set with
elements.

Solution: A function corresponds to a choice of one of the elements in the


codomain for each of the elements in the domain. By product rule there are
functions from a set with elements to a set with elements.

Example 2: Counting one-to-one Functions

How many one-to-one functions are there from a set with elements to
another set with elements?

Solution: First note that there are no one-to-one functions when .


Let . Let the elements of the domain be . There are ways to
choose the value of the function at . Since the function is one-to-one, the value
of the function at can be chosen in ways. In general, the value of the
function at , having chosen the values of , can be chosen in
ways. By the product rule, there are

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,

We now introduce the sum 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.

The following is the extended version of the sum rule:


Suppose that a task can be done in one of ways, in one of ways,…,or in one
of ways, where none of the set of ways of doing the task is the same as any
of the set of ways, for all and with . Then the number of ways
to do the task is
.

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.

Note: The sum rule is often phrased in terms of sets.


If are pairwise disjoint finite sets, then the number of elements in
the union of the sets is the sum of the number of elements in the sets. To relate
this to the sum rule, note that there are ways to choose an element from
. Because the sets are disjoint, when we select an element from
one of the sets , we do not also select an element from a different set . By
sum rule (because we cannot select an element from two of these sets at the
same time) the number of ways to choose an element from one of the sets, which
is the number of elements in the union, is
.
Many counting problems can be solved using both of the above rules in
combination.

Example 4: In a version of the computer language BASIC, the name of a variable


is a string of one or two alphanumeric characters, where uppercase and
lowercase letters are not distinguished. Moreover, a variable name must begin
with a letter and must be different from five strings of two characters that are
reserves for programming use. How many different variable names are there in
this version of BASIC?

(An alphanumeric character is either one of 26 English letters or one of 10 digits)

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, .

Note that , because a one character variable name must be a letter.

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 .

Therefore, there are different names of variables


in this version of BASIC.

The Inclusion-Exclusion Principle

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, .

By the principle of inclusion- exclusion

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.

Example 8: How many positive integers not exceeding are divisible


by or

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

Note that the positive integers divisible by 7 and 11 are divisible by ,


because 7 and 11 are relatively prime. Therefore,

By the principle of inclusion-exclusion

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 .

The principle of inclusion-exclusion for three finite sets is given below:


Theorem 1: If and are three finite sets, then

Proof:

(By the principle of inclusion- exclusion and distributive law)

Now,

(By the principle of inclusion- exclusion)

Thus,

Hence the result.

Example 9: A total of students who have taken a course in Spanish,


have taken a course in French, and have taken a course in Russian. Further,
have taken courses in both Spanish and French, have taken courses in
both Spanish and Russian, and have taken courses in both French and
Russian. If students have taken at least one of Spanish, French and
Russian, then how many students have taken a course in all three languages?

Solution: Let and be the sets of students who have taken Spanish, French
and Russian. Then, . Further,

and .

By the principle of inclusion- exclusion,

i.e.,
and so .

Therefore, there are seven students who have taken courses in all the three
languages.

Theorem 2: The principle of inclusion-exclusion for finite sets

If be finite sets then

(The result follows by mathematical induction)

An alternate form of the principle of inclusion - exclusion

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
.

The number of elements of with all the properties is denoted by


. That is,

If the number of elements with none of the properties is denoted by


and the number of elements in by then
Thus,

Application 1: The principle of inclusion – exclusion can be used to find the


number of primes not exceeding a specified positive integer.

Example 10: Find the number primes not exceeding


Recall that a composite number is divisible by a prime not exceeding its square
root. Therefore, to find the number of primes not exceeding , first note the
composite integers not exceeding must have a prime factor not
exceeding .

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.

Thus, the number of primes not exceeding 100 is given by .


By the principle of inclusion – exclusion

Thus, there are primes not exceeding 100.

Note: The Sieve of Eratosthenes is used to find all primes not exceeding a
specified positive integer.

Application 2: The principle of inclusion-exclusion can also be used to determine


the number of onto functions from a set with elements to a set with
elements.

We first consider the following example:

Example 11: How many onto functions are there from a set with six elements
to a set with four elements.

Solution: Let . Let be the set of all function from to .


Clearly, .

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 .

Theorem 3: Let and be positive integers with .The number of onto


functions from a set with elements to a set with elements is

n n n
C1 C2 Cn1
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.

Application 3: The principle of inclusion-exclusion can be used to count the


permutations of objects that leave no objects in their original positions.

Derangements

A derangement is a permutation of objects that leaves no object in its original


position.

The permutation is a derangement of , because no number is


left in its original position. The permutation is not a derangement of
, because this permutation leaves fixed.
Let be the number of derangement of objects.

For example, , because the derangements of are and .

We will now derive a formula for using the principle of inclusion-exclusion.

Theorem 4: The number of derangements of a set with elements is

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

By the principle of inclusion-exclusion


Note that is the number of permutations that fix the element . If the
element is left in its original position, the remaining positions can be filled
is ways. Therefore, . Similarly . In
general .

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:

Number of strings of length 4

There are 26 choices for each of four places

26 26

26 26

By product rule there are strings of length 4.

Similarly, there are

strings of length three

strings of length two

strings of length one

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

How many positive integers between and inclusive

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.

a. The set is the set of positive integers divisible by 3 or 4.


By the principle of inclusion- exclusion

b. The set of positive integers which are not divisible by either 3 or 4 is .


We have

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:

The following are four types of license plates:

(i) Two letters followed by two digits

26 10

26 10
By product rule,

(ii) Two letters followed by three digits

26 10 10
10

26 10

By product rule,

(iii) Three letters followed by two digits

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,

The required number of license plates is

(By sum rule)

Note that
P5:

How many functions are there from the set , where is a positive
integer, to the set

a. that are one-to-one


b. that assign 0 to both 1 and
c. that assign 1 to exactly one of the positive integers less than

Solution:

The number of one-to-one function from a set with elements to a set with -
elements is

if

if

(a) The number of one-to-one function from the set to a set is

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:

Palindrome: A palindrome is a string whose reversal is identical to the string.

Example: How many bit strings of length are palindromes.

Solution:

A palindrome is a string whose reversal is identical to the string.

For example, the bit string 0110110 of length 7 is a palindrome. The bit string
101101 of length 6 is a palindrome

Consider bit strings of length .

We have two cases (i) is even (ii) is odd.

Case (i) Suppose that is even say , for some positive integer .

A string of length can be seen as two strings of length arranged side by


side. If a (bit) string of length in the left part is written in reverse order in the
right part then we get a palindrome of length . Thus, the number of
palindromes of length is equal to the number of bit strings of length ,
that ,where is even.

Case (ii) Suppose that is odd, say , for some positive integer .

entry

A string of length can be seen as two strings of length arranged on


th
either side of entry, if the string of length on the left side of
th th
entry is written in the reverse order on the right side of the
entry then we get a palindrome of length . Thus,

The palindromes of length

(the number of bit strings of length )

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:

How many positive integers not exceeding are divisible either by or by ?

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

The set of positive integers not exceeding divisible by and is . Then

By the principle of inclusion-exclusion, we have

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.

You might also like