1. University of Benghazi
Faculty of Engineering
Electrical and Electronics Engineering Department
Probability and Stochastic Process
EE277
Counting Methods
Salma Elkawafi
Salma.elkawafi@uob.edu.ly
2. Goals
• Understand some general terminology for the
counting problems
❑ Sampling
❑ With or without replacement
❑ Ordered or unordered
• Inclusion-exclusion principle
• The basic principle of counting (Multiplication)
• Permutations
• Combinations
• Multinomial Coefficients
• Unordered Sampling with Replacement
3. Some general terminology for the counting
problems
• Sampling: sampling from a set means choosing an element from that set.
We often draw a sample at random from a given set in which each element of
the set has equal chance of being chosen.
4. Some general terminology for the counting
problems
• With or without replacement:
If we put each object back after each draw, we call this sampling with
replacement. In this case a single object can be possibly chosen multiple
times. For example, if 𝐴 = {𝑎1, 𝑎2, 𝑎3, 𝑎4} and we pick 3 elements with
replacement, a possible choice might be (𝑎3, 𝑎1, 𝑎3).
“ with replacement “ means “repetition is allowed”
“ without replacement “ means “repetition is not allowed”
5. Some general terminology for the counting
problems
• Ordered or unordered: If ordering matters 𝑖. 𝑒. : 𝑎1, 𝑎2, 𝑎3 ≠ 𝑎2, 𝑎3, 𝑎1 this is
called ordered sampling. Otherwise, it is called unordered.
Thus when we talk about sampling from sets, we can talk about four possibilities.
• ordered sampling with replacement
• ordered sampling without replacement
• unordered sampling without replacement
• unordered sampling with replacement
6. Some general terminology for the counting
problems
• Random experiment: is a
process by which we observe
something uncertain
• Outcome: A result of a random
experiment.
• Sample Space: The set of all
possible outcomes.
• Event: A subset of the sample
space
7. Inclusion-exclusion Principle
• The inclusion-exclusion principle says
|𝐴 ∪ 𝐵| = |𝐴| + |𝐵| − |𝐴 ∩ 𝐵|
𝑆 is all the dots, A is the dots in the blue circle, and B is the dots in
the red circle. |A| is the number of dots in A and likewise for the
other sets. The figure shows that |A|+|B| double-counts |A ∩ B|,
which is why |A ∩ B| is subtracted off in the inclusion-exclusion
formula.
| A | = #A = n(A)
9. Inclusion-exclusion principle
Example:
In a band of singers and pianists, seven people sing, four play the
piano, and two do both. How big is the band?
Solution:
Let S be the set singers and P be the set piano players. The
inclusion exclusion principle says size of band is
|𝑆 ∪ 𝑃| = |𝑆| + |𝑃| − |𝑆 ∩ 𝑃| = 7 + 4 − 2 = 9.
10. Inclusion-exclusion principle
Example:
50 students taking examinations in Mathematics, Physics and
Chemistry, each of the student has passed in at least one of the
subject, 37 passed Mathematics, 24 Physics and 43 Chemistry. At
most 19 passed Mathematics and Physics, at most 29 Mathematics
and Chemistry and at most 20 Physics and Chemistry. What is the
largest possible number that could have passed all three examination?
Solution :
M be the set of students passing in Mathematic
P be the set of students passing in Physics
C be the set of students passing in Chemistry Now,
𝑛 𝑀 ∪ 𝑃 ∪ 𝐶 = 50,
𝑛 𝑀 = 37,
𝑛 𝑃 = 24,
𝑛 𝐶 = 43 ,
𝑛 𝑀 ∩ 𝑃 ≤ 19,
𝑛 𝑀 ∩ 𝐶 ≤ 29,
𝑛(𝑃 ∩ 𝐶) ≤ 20 (Given)
𝑛 𝑀 ∪ 𝑃 ∪ 𝐶 = 𝑛 𝑀 + 𝑛 𝑃 + 𝑛 𝐶 – 𝑛 𝑀 ∩ 𝑃 – 𝑛 𝑀 ∩ 𝐶 – 𝑛 𝑃 ∩ 𝐶 + 𝑛 𝑀 ∩ 𝑃 ∩ 𝐶 ≤ 50
37 + 24 + 43 – 19 – 29 – 20 + 𝑛 𝑀 ∩ 𝑃 ∩ 𝐶 ≤ 50
𝑛 𝑀 ∩ 𝑃 ∩ 𝐶 ≤ 50 – 36
𝑛(𝑀 ∩ 𝑃 ∩ 𝐶) ≤ 14
11. The Basic Principle of Counting (Multiplication)
• If there are 𝑛 ways to perform action 1
and then by m ways to perform action
2, then there are 𝑛 · 𝑚 ways to
perform action 1 followed by action 2.
Or
• It states that if one experiment can
result in any of 𝑚 possible outcomes
and if another experiment can result
in any of 𝑛 possible outcomes, then
there are 𝑚𝑛 possible outcomes of
the two experiments.
12. The Basic Principle of Counting (Multiplication)
• Multiplication Principle
Suppose that we perform 𝑟 experiments such that the 𝑘𝑡ℎ
experiment has 𝑛_𝑘 possible outcomes, for 𝑘=1,2,⋯,𝑟. Then there
are a total of 𝑛1 × 𝑛2 × 𝑛3 × ⋯ × 𝑛𝑟 possible outcomes for the
sequence of 𝑟 experiments.
Multiplication rule or Rule of product
13. The Basic Principle of Counting (Multiplication)
Example:
• How many different 7-place license plates are possible if the first 3
places are to be occupied by letters and the final 4 by numbers?
• How many license plates would be possible if repetition among letters
or numbers were prohibited?
Solution:
The answer is 26 × 26×26×10×10×10×10 = 175,760,000
In the second case, there would be 26 · 25 · 24 · 10 · 9 · 8 · 7 = 78,624,000
possible license plates
14. Ordered Sampling with Replacement
• If we have a set with 𝑛 elements (𝑒. 𝑔. : 𝐴 = {1,2,3, ⋯ . 𝑛}), and we want to draw 𝑘
samples from the set such that ordering matters and repetition is allowed.
• In general, we can argue that there are 𝑘 positions in the chosen list:
(Position 1, Position 2, ..., Position 𝑘).
• There are 𝑛 options for each position.
• Thus, when ordering matters and repetition is allowed, the total number of ways to
choose k objects from a set with 𝑛 elements is
𝑛 × 𝑛 × ⋯ × 𝑛 = 𝑛𝑘
Note that this is a special case of the multiplication principle where there are 𝑘
"experiments" and each experiment has 𝑛 possible outcomes
• For example, if 𝐴 = {1,2,3} and 𝑘 = 2, there are 9 different possibilities:
(𝟏, 𝟏); (𝟏, 𝟐); (𝟏, 𝟑); (𝟐, 𝟏); (𝟐, 𝟐); (𝟐, 𝟑); (𝟑, 𝟏); (𝟑, 𝟐); (𝟑, 𝟑).
15. Permutations: Ordered Sampling without Replacement
• If we have a set with 𝑛 elements (𝑒. 𝑔. : 𝐴 = {1,2,3, ⋯ . 𝑛}), and we want to draw 𝑘
samples from the set such that ordering matters and repetition is not allowed.
• In general, we can argue that there are 𝑘 positions in the chosen list:
(Position 1, Position 2, ……………...., Position 𝑘)
• There are 𝑛 options for the first position,
• (𝑛 − 1) options for the second position (since one element has already been
allocated to the first position and cannot be chosen here)
• (𝑛 − 2) options for the third position
• (𝑛 − 𝑘 + 1) options for the 𝑘𝑡ℎ position.
• Thus, the total number of ways to choose 𝑘 objects from a set with 𝑛 elements is
𝑛 × (𝑛 − 1) × ⋯ × (𝑛 − 𝑘 + 1).
• For example if 𝐴 = {1,2,3} and 𝑘 = 2, there are 6 different possibilities:
(𝟏, 𝟐); (𝟏, 𝟑); (𝟐, 𝟏); (𝟐, 𝟑); (𝟑, 𝟏); (𝟑, 𝟐).
16. Permutations: Ordered Sampling without Replacement
• Simply, a permutation is an arrangement in a definite order of a
number of objects taken some or all at a time.
• Counting permutations is merely counting the number of ways in
which some or all objects at a time are rearranged.
• When we are counting the number of subgroups of size 𝑘 from a
larger group of size 𝑛 considering ORDER, we use permutations.
• We define permutations as
𝑃𝑘
𝑛
=
𝑛!
𝑛 − 𝑘 !
𝑓𝑜𝑟 0 ≤ 𝑘 ≤ 𝑛
Numerical Example: if 𝑛 = 5 and 𝑘 = 3
𝑃3
5
=
5 × 4 × 3 × 2 × 1
2 × 1
17. Permutations: Ordered Sampling without Replacement
Example:
• How many different ordered arrangements of the letters a, b, and c
are possible?
Solution
• By direct enumeration we have
abc, acb, bac, bca, cab, and cba
• There are 6 possible permutations of a set of 3 objects. This result
could also have been obtained from the basic principle, since the first
object in the permutation can be any of the 3, the second object can
then be chosen from any of the remaining 2, and the third object is
then the remaining 1.
• Thus, there are 3 × 2 × 1 = 6 possible
18. Permutations: Ordered Sampling without Replacement
Example:
A class in probability theory consists of 6 men and 4 women. An examination is given, and the
students are ranked according to their performance. Assume that no two students obtain the
same score.
1. How many different rankings are possible?
2. If the men are ranked just among themselves and the women just among themselves, how many different
rankings are possible?
3. How many different top-three rankings are possible?
Solution:
a)There are 𝑃10
10
possible rankings = 10 × 9 × 8 × ⋯ × 2 × 1
b)There are 𝑃6
6
possible rankings among men and 𝑃4
4
possible rankings among
women, so there are a 𝑃6
6
× 𝑃4
4
= 720 × 24 of possible rankings in total (basic
principle of counting)
c) There are 𝑃3
10
possible rankings =
10!
10−3 !
=
10×9×8×7×6×5×4×3×2×1
7×6×5×4×3×2×1
= 10 × 9 × 8 = 720
19. Combinations: Unordered Sampling without Replacement
Here we have a set with 𝑛 elements, e.g., 𝐴 = {1,2,3, … . 𝑛} and we want to
draw 𝑘 samples from the set such that ordering does not matter and
repetition is not allowed. Thus, we basically want to choose a 𝑘-element
subset of 𝐴, which we also call a 𝑘-combination of the set 𝐴.
For example,
if 𝐴 = {1,2,3} and 𝑘 = 2, there are 3 different possibilities:
{𝟏, 𝟐}; {𝟏, 𝟑}; {𝟐, 𝟑}.
Simply, when we are counting the number of subgroups of size 𝑘 from a
larger group of size 𝑛 considering NO ORDER, we use combinations.
𝑛
𝑘
.
20. Combinations: Unordered Sampling without Replacement
We define combinations as
𝐶𝑘
𝑛
=
𝑛
𝑘
=
𝑛!
𝑘! 𝑛 − 𝑘 !
This is read "n choose k.“
Numerical Example: if 𝑛 = 5 and 𝑘 = 3
𝐶3
5
=
5!
3! 5 − 3 !
=
5 × 4 × 3 × 2 × 1
3 × 2 × 1 × 2 × 1
21. Combinations: Unordered Sampling without Replacement
Example:
A committee of 3 is to be formed from a group of 20 people. How
many different committees are possible?
Solution
There are 𝐶3
20
= 20
3
=
20!
3! 20−3 !
=
20×19×18
3×2×1
= 1140 possible
committees can be formed
22. Multinomial Coefficients
• When we are counting the number
of different arrangements of a
group of size n, where 𝑛 has 𝑛1, 𝑛2,
…, and 𝑛𝑟 of similar subgroups, we
use the multinomial coefficients
method.
• So, if 𝑛1 + 𝑛2 + ⋯ + 𝑛𝑟 = 𝑛,
then the possible arrangements
are
𝑛
𝑛1 , 𝑛2, ⋯ , 𝑛𝑟
=
𝑛!
𝑛1! 𝑛2! … . 𝑛𝑟!
23. Multinomial Coefficients
Example:
How many different letter arrangements can be formed from the letters
PEPPER?
Solution
There are 6
3 ,2,1
=
6!
3!2!1!
= 60 possible letter arrangements can be
formed
24. Unordered Sampling with Replacement
Suppose that we want to sample from the set 𝐴 = {𝑎1, 𝑎2, … , 𝑎𝑛} 𝑘 times
such that repetition is allowed and ordering does not matter.
For example, if 𝐴 = {1,2,3} and 𝑘 = 2, then there are 6 different ways of doing
this
(1,1); (1,2); (1,3); (2,2); (2,3); (3,3);
The number of different ways of picking 𝑘 objects from a set of 𝑛 distinct
objects with replacement and without ordering is given by= 𝑛+𝑘−1
𝑘
.
Self-Study
27. Exercise
Small community consists of 10 women, each of whom has 3
children. If one woman and one of her children are to be chosen as
mother and child of the year, how many different choices are
possible?
Answer:
we see from the basic principle that there are 10 * 3 = 30
possible choices.
.
.
28. Exercise
A college planning committee consists of 3 freshmen, 4 sophomores,
5 juniors, and 2 seniors. A subcommittee of 4, consisting of 1 person
from each class, is to be chosen. How many different subcommittees
are possible?
Answer:
There are 3 × 4 × 5 × 2 = 120 possible subcommittees
29. Exercise
How many functions defined on n points are possible if
each functional value is either 0 or 1?
Answer:
Let the points be 1, 2, . . . , 𝑛. Since 𝑓(𝑖) must be either 0 or
1 for each i = 1, 2, . . . , n, it follows that there are 2𝑛
possible functions.
30. Exercise
There are 5 competitors in the 100m final at the
Olympics. In how many ways can the gold, silver, and
bronze medals be awarded?
Answer:
There are 5 ways to award the gold. Once that is awarded
there are 4 ways to award the silver and then 3 ways to
award the bronze: answer 5 · 4 · 3 = 60 ways.
31. Exercise
Ms Jones has 4 math, 3 physics, 2 chemistry and 1 language books. She
wants to arrange these books on a bookshelf so that all books of the same
subject are kept together. How many different arrangements are possible?
Answer:
There are 𝑃4
4
possible arrangements for math books , 𝑃3
3
possible
arrangements for physics books, 𝑃2
2
possible arrangements for physics
books, and 𝑃1
1
possible arrangements for language book. Also, we have 4
subjects that can have 𝑃4
4
possible arrangements . So, there are 𝑃4
4
×𝑃4
4
×
𝑃3
3
× 𝑃2
2
× 𝑃1
1
= 6912 possible arrangements in total ( generalized basic
principle of counting)
32. Exercise
From a group of 5 women and 7 men
a)How many different committees consisting of 2 women and 3 men can be formed?
b)What if 2 of the men are refusing to work together in one committee?
Answer
a) There are 𝐶2
5
of possible groups of women and 𝐶3
7
of possible groups of men. So, the total
number of possible committees is
𝐶2
5
× 𝐶3
7
= (
5 × 4
2 × 1
)(
7 × 6 × 5
3 × 2 × 1
) = 350
b) Now, for two men to be together, there are 𝐶2
2
× 𝐶1
5
= 1 × 5 ways.
We remove these 5 ways from 𝐶3
7
of total possible groups of men, so there are now 35-5=30
of possible groups of men and by considering the number of women groups, we have a total
of 𝐶2
5
× 30 = 10 × 30 or 300 different possible committees.
33. Exercise
What is the number of ways of choosing 4 cards from a pack of 52 playing cards? In
how many of these
(i) four cards are of the same suit, (ii) four cards belong to four different suits,
Answer
• There will be as many ways of choosing 4 cards from 52 cards as there are
combinations of 52 different things, taken 4 at a time. Therefore The required
number of ways = 𝐶4
52
= 270725
(i) There are four suits: diamond, club, spade, heart and there are 13 cards of each suit.
Therefore, The required number of ways = 𝐶4
13
+ 𝐶4
13
+ 𝐶4
13
+ 𝐶4
13
= 2860
(ii) There are13 cards in each suit. Therefore, there are 𝐶1
13
ways of choosing 1 card
from 13 cards of diamond, 𝐶1
13
ways of choosing 1 card from 13 cards of hearts, 𝐶1
13
ways of choosing 1 card from 13 cards of clubs, 𝐶1
13
ways of choosing 1 card from 13
cards of spades. Hence, by multiplication principle, the required number of ways = 𝐶1
13
× 𝐶1
13
× 𝐶1
13
× 𝐶1
13
= 134
34. Exercise
How many numbers lying between 100 and 1000 can be formed with the digits 0, 1,
2, 3, 4, 5, if the repetition of the digits is not allowed?
Answer:
Every number between 100 and 1000 is a 3-digit number. We, first, have to count
the permutations of 6 digits taken 3 at a time 𝑃3
6
. But, these permutations
will include those also where 0 is at the 100’s place. For example, 092,
042, . . ., etc are such numbers which are actually 2-digit numbers and
hence the number of such numbers has to be subtracted from 𝑃3
6
to get
the required number.
To get the number of such numbers, we fix 0 at the 100’s place and
rearrange the remaining 5 digits taking 2 at a time.
So The required number 𝑃3
6
− 𝑃2
5
=
6!
3!
−
5!
3!
= 100
35. Exercise
Count the following:
(i) The number of ways to choose 2 out of 4 things (order does not matter).
(ii) The number of ways to list 2 out of 4 things.
(iii) The number of ways to choose 3 out of 10 things.
Answer:
(i)This is asking for combinations: C2
4
=
4!
2! 4−2 !
=
4!
2!×2!
= 6
(ii)This is asking for permutations: 𝑃2
4
=
4!
4−2 !
=
4!
2!
= 12
(iii)This is asking for combinations: C3
10
=
10!
3! 10−3 !
=
10!
3! × 7!
=
10×9×8
3×2×1
= 120
36. Exercise
Count the number of ways to get 3 heads in a sequence of 10 flips of a
coin.
Answer:
This asks for the number sequences of 10 flips (heads or tails) with
exactly 3 heads. That is, we have to choose exactly 3 out of 10 flips to
be heads. This is the same question as in the previous example:
C3
10
=
10!
3! 10−3 !
=
10!
3! × 7!
=
10×9×8
3×2×1
= 120
37. Exercise
Twenty workers are to be assigned to 20 different jobs, one to each
job. How many different assignments are possible?
Answer:
There are 20! different possible assignments
38. Exercise
A child has 12 blocks, of which 6 are black, 4 are red, 1 is white, and 1
is blue. If the child puts the blocks in a line, how many arrangements
are possible?
Answer:
There are
12!
6!4!
= 27720 arrangements
.
39. Exercise
A maths debating team consists of 4 speakers
a) In how many ways can all 4 speakers be arranged in a row for a
photo?
b) How many ways can the captain and vice-captain be chosen?
Answer:
a)4 × 3 × 2 × 1 = 4! 𝑜𝑟 𝑃4
4
b)4 × 3 = 12 or 𝑃2
4
40. Exercise
Consider the following data among 110 students in a college dormitory: 30 students are
on a list A (taking Accounting), 35 students are on a list B (taking Biology), 20 students
are on both lists. Find the number of students:
(a) on list or B,
( b) on exactly one of the two lists,
( c) on neither list.
Answer:
(a) 𝑛(𝐴 𝑈 𝐵) = 𝑛(𝐴) + 𝑛(𝐵) − 𝑛(𝐴 𝑛 𝐵) = 30 + 35 − 20 = 45
(b) 𝑛(𝐴B) = 𝑛(𝐴) − 𝑛(𝐴 𝑈 𝐵) = 30 − 20 = 10
𝑛(𝐵A) = 𝑛(𝐵) − 𝑛(𝐴 𝑈 𝐵) = 35 − 20 = 15
Thus there are 10 + 15 = 25 students on exactly one of the two lists.
(c) 𝐴𝑐 ∩ 𝐵𝑐 = 𝐴 ∪ 𝐵 𝑐 = 𝑛(𝑆) − 𝑛(𝐴 𝑈 𝐵) = 110 − 45 = 65
41. Exercise
In how many ways can 8 people be seated in a row if
(a) there are no restrictions on the seating arrangement?
(b) persons A and B must sit next to each other?
Answer:
(𝑎) 8! = 40,320
(𝑏) 2 ⋅ 7! = 10,080
42. Exercise
In how many ways can 5 boys and 4 girls be arranged on a bench if:
(a) boys and girls alternate?
(b) boys and girls are in separate groups?
Answer:
(a) 𝐵𝐺𝐵𝐺𝐵𝐺𝐵𝐺𝐵 = 5 × 4 × 4 × 3 × 3 × 2 × 2 × 1 × 1 = 5! × 4!
(b) Boys & Girls or Girls & Boys
= 5! × 4! + 4! × 5! = 5! × 4! × 2
43. Exercise
A police department consists of 10 officers, 5 of them work in streets, 3 in
cars, and 2 in the building. How many different divisions of the 10 officers into
the three groups are possible?
Answer:
There are 10
5 ,3,2
=
10!
5!3!2!
= 2520 possible divisions