Lecture Note - Counting and Combinatorics1
Lecture Note - Counting and Combinatorics1
Discrete Mathematics II
Course Instructors:
Dr. Victor T. Odumuyiwa
Dr. Ufuoma C. Ogude
•Lectures:
– E 304, Wednesday 10:00 am to 11:00 am
– Lab 203, Thursday 10:00 am to 12:00 am
Course Outline
We study topics in such areas as:
Sets and logic
proof techniques
discrete probability,
NP-Completeness.
Course Material
Textbook
Discrete Mathematics
and Its Applications
by Kenneth H. Rosen
Product Principle
Inclusion-Exclusion
Pigeonhole Principle
permutations
combinations
Pascal’s Triangle
Binomial coefficients
Introduction
Counting = Determining the number of elements of a finite set
toes—and may be the only approach for extremely complicated things with
no identifiable structure.
Introduction
Discreet (simple, developed, advanced) methods can help in
solving Counting problems such as:
“How many different 8-letter passwords are there?”
“How many possible ways are there to pick 11 soccer players out of a 20-
player team?”
“How many different orders may 9 people be arranged in a line?“
“How many different ways can we chose from 4 colors and paint 6
rooms?“
Most importantly, counting is the basis for computing probabilities of
discrete events.
•(“What is the probability of winning the lottery?”)
Counting
Counting are important techniques in computer science,
especially in the analysis of algorithm.
Sorting and searching
combinatorial algorithms
•Sum Principle
•Product Principle
•Pigeonhole Principle
The sum rule:
If a first task can be done in n1 ways and a second task in n2 ways, and if
these tasks cannot be done at the same time. then there are n1+n2 ways
to do either task.
n1 n2
n1 + n2 ways
Example1:
The department will award a free computer to either a CS student or a
CS professor. How many different choices are there, if there are 530
students and 15 professors?
Solution:
There are 530 + 15 = 545 choices.
Example2:
You have five novels, four magazines, and three devotional books. How many
options do you have for taking one for your wait in the bank line?
Solution:
You have 3 subtasks - pick a novel, pick a magazine, or pick a devotional book.
The first can be done 5 ways, the second, 4 ways, and the third 3 ways.
Thus: 5 + 4 + 3 = 12 ways to perform.
Example3:
Suppose that either a member of the mathematics faculty or a student who is
a mathematics major is chosen as a representative to a university committee.
How many different choices are there for this representative if there are 37
members of the mathematics faculty and 83 mathematics majors and no one is
both a faculty member and a student?
Solution:
There are 37 ways to choose a member of the mathematics faculty and there are
83 ways to choose a student who is a mathematics major. Choosing a member of the
mathematics faculty is never the same as choosing a student who is a mathematics
major because no one is both a faculty member and a student.
By the sum rule it follows that there are 37 + 83 = 120
possible ways to pick this representative.
Example4
A student can choose a computer project from one of three lists. The
three lists contain 23, 15 and 19 possible projects respectively. How many
possible projects are there to choose from?
Solution:
23+15+19=57 projects
Exercise
–Suppose either a CS faculty or a CS student must be chosen for a
committee, and there are 4 CS faculty and 16 CS students. How many
possible choices are there?
n1
n1 × n 2
ways
n2
Example1:
How many different license plates are there that containing exactly
three English letters?
Solution:
There are 26 possibilities to pick the first letter, then 26 possibilities
for the second one, and 26 for the last one.
So there are 262626 = 17576 different license plates.
Example2
How many different ways can we chose from 4 colors and paint 3 rooms?
Solution:
Tasks:
• 1 - paint room 1 - 4 ways to perform (4 colors)
• 2 - paint room 2 - 4 ways to perform (4 colors)
• 3 - paint room 3 - 4 ways to perform (4 colors)
Thus t1 = 4, t2 = 4, t3 = 4, and 4 . 4 . 4 = 64 ways to paint the rooms
Example3
How many different ways can we chose from 4 colors and paint 3 rooms, if
no room is to be the same color?
Solution:
tasks:
• 1 - paint room 1 - 4 ways to perform (4 colors)
• 2 - paint room 2 - 3 ways to perform (3 colors left)
• 3 - paint room 3 - 2 ways to perform (2 colors left)
Thus t1 = 4, t2 = 3, t3 = 2, and 4 . 3 . 2 = 24 ways to paint the rooms
Example4
How many different orders may 9 people be arranged in?
Solution:
There are nine tasks - picking the first person, picking the second, …
The first task has 9 choices, the second 8, ... and finally the ninth task
has 1 choice: 9 . 8 . 7 . 6 . 5 . 4 . 3 . 2 . 1 = 362880
Example5
The chair of an auditorium is to be labeled with a letter and a positive
integer not exceeding 100. What is the largest number of chairs that can
be labeled differently?
Solution:
26 × 100 = 2600 ways to label chairs.
letter 1 x 100
x Ν
Exercise
3. How many functions are there from a set with m elements to one with n
elements?
4. How many one-to-one functions are there from a set with m elements
to one with n element? Hints: (m n)
Generalized product rule:
The product rule:
Suppose that a procedure can be broken down into two successive
tasks. If there are n1 ways to do the first task and n2 ways to do the
second task after the first task has been done, then there are n 1n2
ways to do the procedure.
For 3 sets
A ∪ B ∪ C| = |A| + |B| + |C| − |A ∩ B| − |A ∩ C| − |B ∩ C| + |A ∩ B ∩ C|
Example
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?
Solution:
|S ∩ F ∩ R| = 7
The Pigeonhole Principle
If k + 1 or more objects are placed in k boxes, then there
is at least one box containing two or more objects.
The Pigeonhole Principle
If k + 1 or more objects are placed in k boxes, then there
is at least one box containing two or more objects.
The Pigeonhole Principle
If k + 1 or more objects are placed in k boxes, then there
is at least one box containing two or more objects.
The Pigeonhole Principle
If k + 1 or more objects are placed in k boxes, then there
is at least one box containing two or more objects.
Proof: Suppose that none of the k boxes contains more
then one object. Then the maximum number of objects
would be k. This is a contradiction, since there is at least k
+ 1 objects.
The Pigeonhole Principle
If there are 11 players in a soccer team that wins 12-0, there must
be at least one player in the team who scored at least twice.
If you have 6 classes from Monday to Friday, there must be at
least one day on which you have at least two classes.
Among 367 people, there must be at least 2 with the same
birthday, since there is only 366 possible birthdays.
In a collection of 10 numbers, at least 2 must have the same most
significant digit.
significant digit.
The Pigeonhole Principle
How many people must we have in the same room to be
sure that at least two have the same birthday?
Are there two people in Computer Sciences dept. with the
same number of hairs?
Are there two people at Computer Sciences dept. the
same birthday?
Are there two people at Computer Sciences dept. with
birthdays on July 14?
The Pigeonhole Principle
Example
In our 60-student class, at least 12 students will get the same letter
grade (A, B, C, D, or F).
Assume you have a drawer containing a random distribution of a dozen
brown socks and a dozen black socks. It is dark, so how many socks do you
have to pick to be sure that among them there is a matching pair?
There are two types of socks, so if you pick at least 3 socks, there must be
either at least two brown socks or at least two black socks.
Among 100 people there are at least 100/12 = 9 people with the same
birthday month.
Exercise
1. Let n be a positive integer. Show that in any set of n consecutive
integers there is exactly one divisible by n.
3. Show that if seven integers are selected from the first eight
positive integers, there must be pair of these integers with a
sum equal to to 9.
Is this still true if four integers are chosen instead of five?
Basic Counting Principles
The sum and product rules can also be phrased in
terms of set theory.
Sum rule:
Let A1, A2, …, Am be disjoint sets.
Then the number of ways to choose any element from one of
these sets is |A1 A2 … Am | = |A1| + |A2| + … + |Am|.
Product rule:
Let A1, A2, …, Am be finite sets. Then the number of ways to
choose one element from each set in the order A1, A2, …, Am
is |A1 A2 … Am | = |A1| |A2| … |Am|.
Permutations
To find the number of Permutations of n items, we can use the
Fundamental Counting Principle or factorial notation.
Definition
Definition
Given a collection of n distinct objects, any (linear) arrangement of
these objects is called a permutation of the collection
The number of permutations of size r from a collection of n distinct
objects is P(n, r)=n!/(n-r)!.
Calculating factorial and division
8! 8 7 6!
8 7 56
6! 6!
We can divide above and below by 6!, which simplifies the calculation.
Example
Suppose that a saleswoman has to visit 8 different cities. She must begin
her trip in a specified city, but she can visit the other cities in any order
she wishes. How many possible orders can the saleswoman use when visiting
these cities ?
Solution
7! 5040
A permutation of a set of distinct objects is an ordered
arrangement of these objects in a particular order. An ordered
arrangement of r elements of a set is called an r-permutation, i.e. r
objects chosen from n objects.
n!
p
n r ( n r )! where 0 r n .
5! 5!
5 p3 5 * 4 * 3 60
(5 3)! 2!
4! 4 3 2 1
4
P4 24
4 4 ! 0!
0! = 1
Example1
If you have 10 people racing and only 1st, 2nd and 3rd place
how many possible outcomes are there?
10! 10 9 8 7!
10
P3 720
10 3 ! 7!
Example2
A combination lock will open when the right choice of three
numbers (from 1 to 30, inclusive) is selected. How many different
lock combinations are possible assuming no number is repeated?
30! 30!
30 p3 30 * 29 * 28 24360
( 30 3)! 27!
Example3
From a club of 24 members, a President, Vice President,
Secretary, Treasurer and Historian are to be elected. In how
many ways can the offices be filled?
24! 24!
24 p5
( 24 5)! 19!
24 * 23 * 22 * 21 * 20 5,100,480