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

Module8-Adv Counting II

The document outlines topics from a course on Discrete Mathematics, focusing on advanced counting techniques including generating functions and the principle of inclusion-exclusion. It provides definitions, examples, and applications of these concepts, emphasizing their utility in solving various counting problems. Additionally, it includes exercises and references for further reading and learning.

Uploaded by

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

Module8-Adv Counting II

The document outlines topics from a course on Discrete Mathematics, focusing on advanced counting techniques including generating functions and the principle of inclusion-exclusion. It provides definitions, examples, and applications of these concepts, emphasizing their utility in solving various counting problems. Additionally, it includes exercises and references for further reading and learning.

Uploaded by

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

‫الجامعة السعودية االلكترونية‬

‫الجامعة السعودية االلكترونية‬

‫‪26/12/2021‬‬
College of Computing and
Informatics
BS in Computer Science
CS243
Discrete Mathematics in Computer Science
Discrete Mathematics in Computer Science
Week 9
Chapter 8: Advanced Counting
Techniques II
Contents

8.4 Generating Functions


8.5 Inclusion–Exclusion
8.6 Applications of Inclusion–Exclusion
Weekly Learning
Outcomes
1. Study and analyze the generation functions.
2. Learn the concept of inclusion-exclusion and its
applications.
Required Reading
1. Chapter 8, 8.4 - 8.6 “Discrete Mathematics and Its Application”
2. Chapter 8 Key Terms and Results

Recommended Reading
Generating functions
https://math.mit.edu/~goemans/18310S15/generating-function-notes.pdf

Recommended videos
Inclusion-Exclusion Principle-Discrete Mathematics
https://www.youtube.com/watch?v=GS7dIWA6Hpo

This Presentation is mainly dependent on the textbook: Discrete Mathematics and Its Application by Kenneth H. Rosen
8.4 Generating Functions

• Generating functions are used to represent sequences efficiently by


coding the terms of a sequence as coefficients of powers of a variable x in
a formal power series.

• Generating functions can be used to solve many types of counting


problems, such as the number of ways to select or distribute objects of
different kinds, subject to a variety of constraints, and the number of ways
to make change for a dollar using coins of different denominations.
Introduction
Definition 1

The generating function for the sequence , ,…, ,… of real


numbers is the infinite series
G(x) = x0 + x1 +⋯+ +⋯ =

Remark: The generating function for {} given in Definition 1 is sometimes called


the ordinary generating function of {} to distinguish it from other types of
generating functions for this sequence.
Generating Function
Example 1: The generating functions for the sequences {} with

= 3, = k + 1, and = 2k are =0, and , respectively.

Example 2: What is the generating function for the sequence 1, 1, 1, 1, 1, 1?

1 + x + + + + = ( − 1)∕( − 1) when x ≠1 [By Theorem 1 of Section 2.4]


• Solution: The generating function of 1, 1, 1, 1, 1, 1 [geometric series] is
Generating Function
Example 3: Let m be a positive integer. Let ak = C(m, k), for k = 0, 1, 2,…, m.
What is the generating function for the sequence a0, a1,…, am?

Solution: The generating function for this sequence is


G(x) = C(m, 0) + C(m, 1)x + C(m, 2)x2 +⋯+ C(m,m)xm.

The binomial theorem shows that G(x) = (1 + x)m.


8.4.2 Useful Facts About Power Series
• When generating functions are used to solve counting problems, they are usually considered to be formal power series (A
formal power series is a special kind of formal series, whose terms are of the form ax n, where n is a non-negative integer,
and a is called the coefficient).

Example 4: The function f (x) = 1 ∕ (1 − ) is the generating function of


the sequence 1, 1, 1, 1,… because 1 ∕ (1 − ) = 1 + x + +⋯ for ||<
1.

EXAMPLE 5 The function f (x) = 1∕(1 − ax) is the generating function of the sequence
1, a, , ,… because 1∕(1 − ax) = 1 + ax + +⋯ when |ax| < 1, or equivalently, for |x| <
1∕|a| for a ≠ 0.
We also will need some results on how to add and multiply two
generating functions.
Exercises
1. Find the generating function for the finite sequence 2, 2, 2, 2, 2, 2.

2. Find the generating function for the finite sequence 1, 4, 16, 64, 256.
3. Find the coefficient of x 9 in the power series of each of (1 + x 3 + x 6 + x 9 +⋯)3, by using
(1 + x)n = 1 + C (n, 1)x + C (n, 2)x 2 +⋯+ x n // r-combinations: Page 448

Table 1 presents a useful summary of some generating functions that arise frequently. // Page 568
8.5 Inclusion–Exclusion
 A discrete mathematics class contains 30 women and 50 sophomores (A student in his second year of study).
How many students in the class are either women or sophomores?
• This question cannot be answered unless more information is provided. Adding the
number of women in the class and the number of sophomores probably does not give
the correct answer, because women sophomores are counted twice.
• This observation shows that the number of students in the class that are either
sophomores or women is the sum of the number of women and the number of
sophomores in the class minus the number of women sophomores.
• A technique for solving such counting problems was introduced in Section 6.1.
• In this section we will generalize the ideas introduced in that section to solve
problems that require us to count the number of elements in the union of more than
two sets.
The Principle of Inclusion-Exclusion

• The number of elements in the union of the two sets A and B is the
sum of the numbers of elements in the sets minus the number of
elements in their intersection. That is,
The Principle of Inclusion–Exclusion
Example 1: In a discrete mathematics class every student is a major in computer science
or mathematics or both. The number of students having computer science as a major
(possibly along with mathematics) is 25; the number of students having mathematics as
a major (possibly along with computer science) is 13, and the number of students
majoring in both computer science and mathematics is 8. How many students are in this
class?

Solution: Let A be the set of students in the class majoring in computer science and B be
the set of students in the class majoring in mathematics.
• Then A ∩ B is the set of students in the class who are joint mathematics and computer
science majors.
• Because every student in the class is majoring in either computer science or
mathematics (or both), it follows that the number of students in the class is |A ∪ B|.
Therefore,

= 25 + 13 − 8 = 30.

• Therefore, there are 30 students in the class. This computation is illustrated as follows
(next slide).
The Principle of Inclusion–Exclusion
The Principle of Inclusion–Exclusion
 Example 3: Suppose that there are 1807 freshmen at your school. Of these, 453 are taking a course in
computer science, 567 are taking a course in mathematics, and 299 are taking courses in both computer
science and mathematics.

How many are not taking a course either in computer science or in mathematics?

• Solution: To find the number of freshmen who are not taking a course in either mathematics or computer
science, subtract the number of freshmen who are taking a course in either of these subjects from the total
number of freshmen.

• Let A be the set of all freshmen taking a course in computer science, and let B be the set of all freshmen taking
a course in mathematics. It follows that

|A| = 453, |B| = 567, and |A ∩ B| = 299.

• The number of freshmen taking a course in either computer science or mathematics is

|A ∪ B| = |A| + |B| − |A ∩ B| = 453 + 567 − 299 = 721.

• Consequently, there are 1807 − 721 = 1086 freshmen who are not taking a course in computer science or
mathematics.
The Principle of Inclusion–Exclusion
• We will now begin our development of a formula for the number of elements in the union
of a finite number of sets. The formula we will develop is called the principle of
inclusion–exclusion.
• For concreteness, before we consider unions of n sets, where n is any positive integer, we
will derive a formula for the number of elements in the union of three sets A, B, and C. To
construct this formula, we note that |A| + |B| + |C| counts each element that is in exactly
one of the three sets once, elements that are in exactly two of the sets twice, and
elements in all three sets three times. This is illustrated in the first panel in Figure 3.
• To remove the overcount of elements in more than one of the sets, we subtract the
number of elements in the intersections of all pairs of the three sets. We obtain |A| + |B|
+ |C| − |A ∩ B| − |A ∩ C| − |B ∩ C|.
• This expression still counts elements that occur in exactly one of the sets once. An
element that occurs in exactly two of the sets is also counted exactly once, because this
element will occur in one of the three intersections of sets taken two at a time.
• However, those elements that occur in all three sets will be counted zero times by this
expression, because they occur in all three intersections of sets taken two at a time. This is
illustrated in the second panel in Figure 3.
The Principle of Inclusion–Exclusion
• EXAMPLE 4

A total of 1232 students have taken a course in


Spanish, 879 have taken a course in French, and
114 have taken a course in Russian.

Further, 103 have taken courses in both Spanish


and French, 23 have taken courses in both
Spanish and Russian, and 14 have taken courses
in both French and Russian.

If 2092 students have taken at least one of


Spanish, French, and Russian, how many
students have taken a course in all three
languages?
The Principle of Inclusion–Exclusion
Solution: Let S be the set of students who have taken a course in Spanish, F the set of
students who have taken a course in French, and R the set of students who have taken a
course in Russian. Then

|S| = 1232, |F| = 879, |R| = 114,

|S ∩ F| = 103, |S ∩ R| = 23, |F ∩ R| = 14, and |S ∪ F ∪ R| = 2092.

When we insert these quantities into the equation

|S ∪F ∪ R| = |S| + |F| + |R| − |S ∩ F| − |S ∩ R| − |F ∩ R| + |S ∩ F ∩ R|

we obtain 2092 = 1232 + 879 + 114 − 103 − 23 − 14 + |S ∩ F ∩ R| |S ∩ F ∩ R| = 7.

Therefore, there are seven students who have taken courses in Spanish, French, and Russian.

This is illustrated in Figure 4.


Theorem 1: The Principle Of Inclusion–exclusion

This principle tells us that we can count the elements in a union of n sets (where n
is a positive integer) by adding the number of elements in the sets, then
subtracting the sum of the number of elements in all intersections of two of these
sets, then adding the number of elements in all intersections of three of these sets,
and so on, until we reach the number of elements in the intersection of all the sets.
The Principle Of Inclusion–exclusion
8.6 Applications of Inclusion–Exclusion
Many counting problems can be solved using the principle of inclusion-exclusion.

• For instance, we can use this principle to find the number of primes less than a positive integer.

• Many problems can be solved by counting the number of onto functions from one finite set to another. The
inclusion-exclusion principle can be used to find the number of such functions.

• The well-known hatcheck problem can be solved using the principle of inclusion-exclusion. This problem asks for
the probability that no person is given the correct hat back by a hatcheck person who gives these hats back
randomly.
 An onto function from a set with m elements to a set with n elements corresponds to a way to
distribute m elements in the domain to n indistinguishable boxes so that no box is empty, and then to
associate each of the n elements of the codomain to a box.
 This means that the number of onto functions from a set with m elements to a set with n elements is
the number of ways to distribute m distinguishable objects to n indistinguishable boxes so that no box
is empty multiplied by the number of permutations of a set with n elements.
• There is an alternative form of the principle of inclusion-exclusion that is useful in
counting problems. In particular, this form can be used to solve problems that ask for the
number of elements in a set that have none of n properties P1, P2,…, Pn.

• Let Ai be the subset containing the elements that have property Pi. The number of

elements with all the properties Pi1 , Pi2 ,…, Pik will be denoted by N (Pi1 ,Pi2 …Pik). Writing

these quantities in terms of sets, we have

|Ai1 ∩ Ai2 ∩⋯∩ Aik | = N (Pi1 ,Pi2 …Pik ).

• If the number of elements in the set is denoted by N and the number of elements with
none of the properties P1, P2,…, Pn is denoted by N (P ′1P ′ 2…P ′n), it follows that

N (P ′1P ′2…P ′n) = N − |A1 ∪ A2 ∪⋯∪ An|.


Example 1 shows how the principle of inclusion-exclusion can be used
to determine the number of solutions in integers of an equation with
constraints.

• Example 1 : How many solutions does “x1 + x2 + x3 = 11” have, where

x1, x2, and x3 are nonnegative integers with x1 ≤ 3, x2 ≤ 4, and x3 ≤ 6?

1+4+6 3+2+6
2+3+6 3+3+5
2+4+5 3+4+4
P(n,r)=n!/
8.6.4 The Number of Onto Functions
• The principle of inclusion-exclusion can also be used to determine the number of onto
functions from a set with m elements to a set with n elements.
 An onto function from a set with m elements to a set with n elements corresponds to a way to distribute m
elements in the domain to n indistinguishable boxes so that no box is empty, and then to associate each of the
n elements of the codomain to a box.
 This means that the number of onto functions from a set with m elements to a set with n elements is the
number of ways to distribute m distinguishable objects to n indistinguishable boxes so that no box is empty
multiplied by the number of permutations of a set with n elements.

• EXAMPLE 2 How many onto functions are there from


a set with six elements to a set with three elements?
The general result that tells us how many onto functions there are
from a set with m elements to one with n elements will now be stated.

m n
Thank
You

You might also like