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.
Generating all combinations of available settings plays an
important role while studying different systems and it is
extensively used in computer based simulations.
Basic Counting Principles
Two basic principles are:
1. Sum Rule
2. Product Rule
The Sum Rule … The Simple Sum Rule
If one event can occur in n1 different ways and a second event can
occur in n2 different ways, there are n1 + n2 ways in which exactly
one of two events can occur.
The Simple Sum Rule … Example
If a supervisor has two workers each of which can work on the task
and complete it. How many different ways are available to finish the
task?
Solution:
There are two ways to finish the task one through first worker and
the second through the other worker.
The Simple Sum Rule … Example1
A student has to pick an optional course. The course can be
picked from CS major or a Humanities major. CS department has
offered 3 courses (to be picked as optional) and Humanities
department has offered 4 courses (to be picked as optional). How
many ways can the student pick an optional course?
Solution:
There are two ways to finish the task one through first worker and
the second through the other worker.
The Sum Rule … The General Sum Rule
If one event can occur in n1 ways, a second event can occur in n2
ways, a third event can occur in n3 ways,
…………………………………….. , then there are n1 + n2 + n3 + … ways
in which exactly one of the events can occur.
The Sum Rule … Exercises
A CS student can choose a computer project from one of the three
lists. The three lists contain 23, 15 and 19 possible projects,
respectively.
Counting Principles … The Sum Rule … Exercise 2
A worker can go to his work place either by train or by bus. There
are three different trains and four different busses that can take
him to his office in time. How many different ways are available for
him to go to the office?
Solution:
Counting Principles … The Sum Rule … Exercise 3
Stark Inc. hires a new employee. They have five vacant cabins on
ground floor and three vacant offices on second floor. How many
different ways are available for office management to assign one
office / cabin for him?
Solution:
Counting Principles … The Sum Rule … Avoid
Recounting
Counting Principles … The Sum Rule … Recounting
To avoid recounting of overlapping values, we use the principle of
inclusion-exclusion:
Principle of Inclusion – Exclusion
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 1
If A = {a, e, i, o, u} and B={a, b, c, d, e} then |
A B| = ? A B = ?
Solution:
A = {a, e, i, o, u} |A| = 5
B={a, b, c, d, e} |B| = 5
A B = {a, e} |A B| = 2
|A B| = |A| + |B| - |A B| = 5 + 5 – 2 = 8
Principle of Inclusion – Exclusion … Example 2
If A = {a, e, i, o, u} and B={1, 2, 3, 4, 5} then |A B| = ? A B = ?
Solution:
A = {a, e, i, o, u}
B = {1, 2, 3, 4, 5}
A B = {}
|AB|=?
|A B| = |A| + |B| - |A B| = 5 + 5 – 0
= 10
Principle of Inclusion – Exclusion … Solve yourself
Let A = {1,2,3,4,5} and B = {3,4,5,6,7}. |A∪B| = ?
PIE … Exercise … Do it yourself
How many bit-strings of length eight either begin with 00 or end with
101?
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 … Do yourself
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
PIE… Three Overlapping Sets … 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.
PIE… Three Overlapping Sets … Example
40 students
Babar Azam – 18
Shadab Khan – 16
Emad Wasim – 12
PIE… Three Overlapping Sets … Example
40 students
Babar Azam – 18
Shadab Khan – 16
Emad Wasim – 12
BS = 7
BE = 5
SE = 3
BSE = 2
PIE… Three Overlapping Sets … 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 =
PIE… Three Overlapping Sets … Example
PIE… Three Overlapping Sets … Exercises
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?
PIE … Exercise … Do it yourself
How many positive integers under 500 are not divisible
by either of the numbers 2, 3, 5?
Bit String Problems…
1 0 0 1 1 0 1 1 0 0
Bit String Problems…
How many unique bit-strings of length 2 are possible?
How many unique bit-strings of length 5 are possible?
How many unique bit-strings of length 10 are possible?
….
….
….
How many unique bit-strings of length N are possible?
Bit String Problems… Exercise1
How many unique bit-strings of length 10 that start with
00 are possible?
Bit String Problems… Exercise2
How many unique bit-strings of length 10 that end on 111
are possible?
Bit String Problems… Exercise3
How many unique bit-strings of length 10 are possible
that start on 00 and end on 11?
Bit String Problems… Exercise3
How many unique bit-strings of length 10 are possible
that start on 00 or end on 11?
Bit String Problems… Exercise3
How many unique bit-strings of length 10 must contain
substring 111?
Bit String Problems… Exercise3
How many unique bit-strings of length 10 do not contain
substring 111?
Simple Counting… Password Problems
* * * * * * * * * *
Simple Counting… Password Problems
Each user on a computer system has a password, which is six
characters long. Each character in the password is an
uppercase letter or a digit. How many unique passwords are
possible?
Simple Counting… Password Problems
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?
Simple Counting… The Product Rule
Counting Principles … The Simple Product Rule
If one event can occur in n1 different ways and a second
event can occur in n2 different ways, there are n1n2 ways
in which both events can occur.
Counting Principles … The Product Rule
The Product Rule … Example:
There are 7 different optional courses in Computer
Science and 3 different optional courses in
Mathematics. In how many different ways can a
student pick one optional course from each of CS
Courses and Mathematics Courses?
Solution:
CS Course Choices: 7
Mathematics Course Choices: 3
Number of ways to pick one CS course AND one
Mathematics course: 7 x 3 = 21
Counting Principles … Generalized Product Rule
If one event can occur in n1 ways, a second event can occur in n2
ways, a third event can occur in n3 ways, ……………………………………..
, then there are n1n2n3… ways in which all of the events can occur.
Counting Principles … The Product Rule … Exercise
A student has to choose a computer project and a humanities
project. The computer science project list contains 23 possible
projects and humanities project list contains 11 possible projects.
In how many different ways can the student pick one project each
from both lists?
Solution:
Counting Principles … The Product Rule … Exercise
The chairs in auditorium are labelled using a letter (A to Z) and a
digit (0 to 9). How many unique labels are possible?
Solution:
The Product Rule and Sets
If A and B are two sets with |A|=4 and |B|=5 then the number of
elements in the cartesian product of A and B are:
|A X B| = |A|.|B|
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
Ways to elect a president, a treasurer and a secretary: 15 X 14 X 13
= 2730
Counting Principles … The Product Rule … Exercise
There are four bus lines between A and B; and three bus lines
between B and C. Find the number of ways a person can travel:
1. By bus from A to C by way of B;
2. Round trip by bus from A to C by way of B;
3. Round trip by bus from A to C by way of B, if the person does not
want to use a bus line more than once.
Solution:
Counting Principles … The Product Rule … Exercise
Suppose that an automobile license plate has three letters followed
by three digits.
How many number plates (overall) are possible?
How many number plates do not contain any vowel?
How many number plates do not end on even digit?
Solution:
Counting Problems … Product Rule ... Exercise
Alice invites her friends Bob, Carl, Dian, Eve, Fred and George on her
birthday party. Every participant is supposed to shake every other
participant’s hand. How many handshakes?