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

Lecture Notes 11, Simple Counting

Uploaded by

qny8n272y7
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views

Lecture Notes 11, Simple Counting

Uploaded by

qny8n272y7
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 61

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
Counting Principles … 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 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
other worker.
Counting Principles … Generalized 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.
Counting Principles … The Sum Rule … Exercise
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.
Solution:
Counting Principles … The Sum Rule … Exercise
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:
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

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?

(78 + 32 + 57 – 13 – 21 – 16 + 5) + 14 = Total Students


PIE … Exercise … Do it yourself
How many positive integers under 500 are not divisible by either of
the numbers 2, 3, 5, 11?
Self-assessment Quiz:
1. XinHua Chinese Cuisine offers an early-bird dinner special, which includes one
of four entrees, either a soup (two kinds) or a salad (four choices), and a
dessert (three choices). In how many different ways can one order all three
courses from the special menu?
2. How many functions are there from a 5-element set A to a 6-element set B?
How many are one-to-one?
3. How many subsets of {1,2,...,8} contain more than one element?
4. How many bit strings of length eight either start with 01 or end with 01?
Try it at your own:
Self-assessment Quiz:
XinHua Chinese Cuisine offers an early bird dinner special, which includes one
of four entrees, either a soup (two kinds) or a salad (four choices), and a
dessert (three choices). In how many different ways can one order all three
courses from the special menu?

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:

• 3. How many subsets of {1,2,...,8} contain more than one element?

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?

Solution: There are that start with 01,


that end with 01,
and with both properties,
so the number in question is .
PIE … Exercise … Do it yourself
In a mathematics contest with three problems, 80% of the participants solved
the first problem, 75% solved the second and 70% solved the third.
Prove that at least 25% of the participants solved all three problems.
Exercise: Inclusion Exclusion Principle:
In a mathematics contest with three problems, 80% of the participants solved the
first problem, 75% solved the second and 70% solved the third.
Prove that at least 25% of the participants solved all three problems.
===============================================
Solution: Let the total number of participants be n > 0 (if n = 0, the proof is
trivial).
Denote the set of people who missed the first problem by A, the set of people who
missed the second by B, and the set who missed the third by C.
We know that |A| = n −0.8n = 0.2n, |B| = n −0.75n = 0.25n and |C|= n−0.7n =
0.3n.
We also know, that |A∪B∪C|≤|A|+|B|+|C|= 0.2n +0.25n +0.3n = 0.75n
The set of people who solved all three problems is the complement of A∪B ∪C (the
set who missed at least one problem), so it has size
n−|A∪B∪C|≥ n−0.75n = 0.25n
Therefore at least 25% of the participants solved all three problems.
PIE … Exercise … Do it yourself
Count the number of bit-strings of length 8 with 3 consecutive zeros or 4
consecutive ones.
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.

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
Maths Course Choices: 3
Number of ways to pick one CS course and one Maths 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 worker takes a bus from a nearby bus stop and goes to Lahori bus stop. From
Lahori stop he takes a train and goes to Gulberg (situated next to his office). How
many different ways are available for him to go to the office?
Solution:
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
How many bit strings of length 10:
 Start with ‘1’
 Start and end with ‘0’
 Does not contain ‘00’
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 Principles … The Product Rule … Exercise
The password in a computer system can consist of digits (0-9), letters (a-z, A-Z)
and special characters (_, $, #, @).
1. How many different passwords are possible with length 8?
2. If a user has used two different special characters in his password of length 8,
how many different combinations are possible for this setting?
3. If a user uses a digit, a special character, a capital letter and the rest of the
characters from small letters, how many different combinations are possible
for this setting?
Counting Triangles

How many triangles are there?

Same graph but different visual


arrangement
Counting Triangles

• How many triangles are there?

Note: every corner is connected with every other corner.


Counting Problems … Shaking Hands ... 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?
Counting Problems … Shaking Hands ... Exercise

How many handshakes?


21, for 7 people
A general formula

𝐍 ( 𝐍 −𝟏 )
𝟐
Counting Problems … Shaking Hands ... Exercise

• How many handshakes?

21, for 7 people.


• A general formula

• Let’s make a graph of it.

• Complete graph:
Counting Problems … Seating Arrangement ... Exercise
All guests in birthday party want to sit around a round table.

1. How many different arrangements are possible?


2. Bob and Diane are not on speaking terms (they don’t want to sit next to each other),
how many different arrangements are possible?
Counting Problems … Lottery Tickets... Exercise
Cash 5 is a famous lottery system. Every ticket has five numbers (numbering 0 - 99).
You have 5 numbers. If your five numbers are matched with the five numbers of
winning ticket, you win the jackpot.

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.

1. How many unique hands are possible (unique combinations


of 13 cards)?
2. How many unique combinations are possible when a player
has only red cards?
3. How many unique combinations are possible when a player
has received all four queens?
4. How many unique combinations are possible when a player
receives all unique value cards (one ace card, one king card,
one queen card, …)?
Counting Problems … Play Chess ... Exercise

There are three chess boards and six players to play against each other.

How many different ways can the matches can be played?


How many different ways can the matches be played when a player chooses to play
on table1 with white chess pieces?
Counting Problems … Choose Office ... Exercise
A new company with just two employees, Saeed and Raees, rents a floor of a
building with 12 offices. How many different ways the both employees be
seated?
Counting Problems … Car Labels ... Exercise
In Pakistan, the registration of Car tags the car with 3 English Letters followed by 4
digits. There are how many possible ways to tag a car?
Counting Problems … Ports Combinations ... Exercise
There are 32 microcomputers in a computer center. Each microcomputer has 24
ports. How many different ports to a microcomputer in the center are there?
Counting Problems … Count Initials ... Exercise
How many different three letters initials can people have?
How many matches played so far?

Be careful of over-counting
Counting Problems … Counting Strings ... Exercise
Counting Problems … Counting Strings ... Exercise

You might also like