Lecture Notes 11, Simple Counting
Lecture Notes 11, Simple Counting
Simple Counting
Imran Shafi
Email: [email protected]
Combinatorics
Combinatorics is the mathematics of counting and arranging objects.
In combinatorics we generally solved counting problems. Following are few
examples of counting related problems:
How many courses have you taken in current semester?
If a course can consist of three or four credits hours, what is the maximum credit hours
one can clear by passing ten courses.
If Ali has invited five of his friends on his birthday and every guest shakes hands with
every other guest and the host, how many shake hands will take place?
If we have a bit string consisting of ten bits, how many different ways the string can be
formed with last bit as ‘1’?
Counting problems can be both easy and hard depending upon different
factors.
In counting problem the important step is to realize which constraints are
applied while we are counting, keep that in control will enable you to solve
the actual problem easily.
Enumeration
Many times we need to enumerate (one by one generating different
combinations) available collection for being able to count them.
If a task can be done in either ways or ways, then the number of ways to do the
task is minus the number of ways to do the task that are common to the two
different ways.
Principle of Inclusion – Exclusion … Example
Example:
If A = {a, e, i, o, u} and B={a, b, c, d, e} then |A B| = ? A B = ?
Solution:
A B = {a, b, c, d, e, i, o, u}
|A B| = |A| + |B| - |A B| = 5 + 5 – 2 = 8
Principle of Inclusion – Exclusion … Example
If A = {a, e, i, o, u} and B={1, 2, 3, 4, 5} then |A B| = ? A B = ?
Solution:
A B = {a, b, c, d, e, 1, 2, 3, 4, 5}
|A B| = |A| + |B| - |A B| = 5 + 5 – 0 = 10
Principle of Inclusion – Exclusion … Exercise
Let A = {1,2,3,4,5} and B = {3,4,5,6,7}. |A∪B| = ?
Principle of Inclusion – Exclusion … Example
There are a total of 40 students in a class. 18 of the students have Babar Azam’s
pictures, 16 of the students have Shadab Khan’s pictures and 12 of them have Emad
Wasim’s pictures. 7 of them have both Babar Azam and Shadab Khan’s pictures. 5 of
them have Babar Azam and Emad Wasim’s pictures. 3 of them have both Shadab
Khan and Emad Wasim’s pictures. 2 of the students have all three players’ pictures.
How many of the students have no pictures of these players at all.
Principle of Inclusion – Exclusion … Example
40 students
Babar Azam – 18
Shadab Khan – 16
Emad Wasim – 12
Principle of Inclusion – Exclusion … Example
40 students
Babar Azam – 18
Shadab Khan – 16
Emad Wasim – 12
BS = 7
BE = 5
SE = 3
BSE = 2
Principle of Inclusion – Exclusion … Example
40 students
Babar Azam – 18
Shadab Khan – 16
Emad Wasim – 12
BS = 7
BE = 5
SE = 3
BSE = 2
Students having pics = 18 + 16 + 12 – 7 – 5 – 3 + 2 = 33
Students not having any pic =
Principle of Inclusion – Exclusion … Exercise
Each user on a computer system has a password, which is six characters
long, where each character is an uppercase letter or a digit. Each password
must contain at least one digit. How many unique passwords are possible?
Principle of Inclusion – Exclusion … Exercise
Each user on a computer system has a password, which is six characters long, where
each character is an uppercase letter or a digit. Each password must contain at least
one digit. How many possible passwords are there?
Solution:
All combinations =
Illegal password (passwords having alphabets only) =
Legal passwords = All pwds – illegal pwds =
Principle of Inclusion – Exclusion … Exercise
How many positive integers not bigger than 20 are divisible by either 2 or 3?
Solution:
Set of all positive integers not greater than 20 = A = {1, 2, 3, …, 20}
Numbers divisible by 2 = B = {2, 4, 6, …, 20}
Numbers divisible by 3 = C = {3, 6, 9, …, 18}
Numbers divisible by both 2 and 3 = B C = {6, 12, 18}
Required Elements = R = |B∪C| = ?
| B∪C| = |B| + |C| - |B C|
Total numbers = 10+6 -3 = 13
Principle of Inclusion – Exclusion … Exercise
Principle of Inclusion – Exclusion … Exercise
How many positive integers up to 1000 are divisible by 7 or 11?
Solution:
Numbers divisible by 7 = 1000/7 = 142
Numbers divisible by 11 = 1000/11 = 90
Numbers divisible by both 7 and 11 = 1000/(7x11) = 12
Total number = 142 + 90 – 12 = 220
Principle of Inclusion – Exclusion … Exercise
How many positive integers up to 1000 are NOT divisible by 7 or 11?
Solution:
1000 – previous answer = 1000 – 220 = 780.
PIE … Exercise … Do it yourself
How many bit-strings of length eight either begin with 00 or end with
101?
Problem: Application of PIE
Principle of Inclusion-Exclusion
In a survey on the college students, the following data was obtained:
78 like Vanilla Ice-cream
32 like Chocolate
57 like Mango Ice-cream
13 like both Vanilla Ice-cream and Chocolate
21 like both Chocolate and Mango Ice-cream
16 like both Mango Ice-cream and Vanilla Ice-cream
5 like all three flavors above
14 like none of these three flavors
How many students were surveyed?
Solution: A hypothetical diner can order an entree in four ways, one of six first
courses, and one of three desserts. By the product rule, there are 4·6·3 = 72
ways to order.
Try it at your own:
Self-assessment Quiz:
• 2. How many functions are there from a 5-element set A to a 6-element set B?
How many are one-to-one?
Solution: Let A = {a1,a2,...,a5}. In the first case, there are 6 choices for the image
of each element ai ∈ A, so by the product rule there are 6^5 = 7776 such
functions.
If the function must be one-to-one, there are six choices for the image of a1,
then five choices for the image of a2, etc. So there are 6·5·4·3·2 = 6! = 720 one-
to-one functions from A to B
Try it at your own:
Self-assessment Quiz:
Solution: All except the empty set and the eight singletons, so altogether
subsets contain more than one element.
Try it at your own:
Self-assessment Quiz:
How many bit strings of length 8 either start with 01 or end with 01?
Example:
If A = {a, e, o} and B={1, 2, 3, 4} then |A X B| = ? A X B = ?
Solution:
A X B = {(a, 1), (a, 2), (a, 3), (a, 4), (e, 1), (e, 2), (e, 3), (e, 4), (o, 1), (o, 2), (o, 3),
(o, 4)}
|A X B| = |A|.|B| = 3 X 4 = 12
Counting Principles … The Product Rule … 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 ways: 15
The treasurer can be elected in ways: 14
The secretary can be elected in ways: 13
𝐍 ( 𝐍 −𝟏 )
𝟐
Counting Problems … Shaking Hands ... Exercise
• Complete graph:
Counting Problems … Seating Arrangement ... Exercise
All guests in birthday party want to sit around a round table.
1. If you want to guarantee that you win a jackpot, how many tickets do you have to buy?
2. If the winning ticket can repeat a number in its jackpot combination, how many tickets do you
have to buy to guarantee that you win the jackpot?
Counting Problems … Play Cards ... Exercise
Say four players play a card game. Each player gets 13 cards. The
game is played under certain rules.
There are three chess boards and six players to play against each other.
Be careful of over-counting
Counting Problems … Counting Strings ... Exercise
Counting Problems … Counting Strings ... Exercise
•