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

Counting

The document discusses various counting techniques in discrete mathematics, including the sum rule, product rule, permutations, and combinations. It provides examples of how to use these techniques to count the number of possible outcomes in different scenarios. For instance, it explains that the number of permutations of a set with n elements is n factorial, and the number of r-combinations of a set with n elements is the binomial coefficient n choose r.

Uploaded by

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

Counting

The document discusses various counting techniques in discrete mathematics, including the sum rule, product rule, permutations, and combinations. It provides examples of how to use these techniques to count the number of possible outcomes in different scenarios. For instance, it explains that the number of permutations of a set with n elements is n factorial, and the number of r-combinations of a set with n elements is the binomial coefficient n choose r.

Uploaded by

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

Discrete Mathematics

Combinatorics and Finite Probability


Reading

• Barnier and Chan


• Chapter 4
• Epp
• Chapter 9
Outline

• Combinatorics
• Basic counting techniques
• Sum Rule
• Product Rule
• The Pigeonhole Principle
• Permutations
• Combinations
• Binomial Theorem
• Introduction to Finite Probability
• Properties of the Probability function
???Question???

???Do you Know how to count???


Basic Counting Techniques

• Counting is essential in solving many problems in Computer Science

• Counting is not always easy

• Recall that if A is a set then Card(A) or the cardinality of the set A


denotes the number of elements in the set A
Elements in a list

• Example
• How many integers are in the set A = {5, 6, .., 21}?
• Solution
• The elements can be rewritten as

{4 + 1, 4 + 2, .., 4 + 17}

• So there are as many numbers in the list as there is in the list {1, 2, ..,
17}

•  are 17 elements.
Elements in a list

• Theorem
• If m and n are integers and m  n, then there are n – m + 1 integers from m
and n inclusive

• Example
• How many three digit numbers are divisible by 5?

• Solution
• Let A = {100, 101, .., 999}
• Then the numbers in A which are divisible by 5 are
• B = {20.5, 21.5, .., 199.5} Since the highest number is 995 = 199.5
• So f:B → {20,21,..,199} is a bijection
Example cont’d

• From the previous assertion


• |B| = |{20,21,..,199}|
• By theorem
|{20,21,..,199}| = 199 – 20 + 1
= 200 – 20
=180
The Product Rule

• Card(A x B) = Card(A)*Card(B)
• This rule holds whether A and B are pairwise disjoint or not.
• The product rule can also be extended to an arbitrary finite number
of sets
Card(A1xA2x…xAn) = Card(A1)*Card(A2)*..*Card(An)
Example

• How many four-digit binary numbers are there?


• Soln
• Each number has four positions in which each one could be a 0 or a 1. Take A
= {0,1}
• The four-digit numbers are represented by AxAxAxA.
• By the Product rule
• Card(AxAxAxA ) = 2*2*2*2 = 24 = 16 combinations
Example

• Suppose a pin number is set to have four digits beginning with a non-
zero digit. How many four-digit pin numbers are there?
• Soln
• Each pin has four positions with the first position having possibilities of 1 to 9
and the other positions taking 0 to 9
• The four-digit numbers are represented by AxAxAxA.
• By the Product rule
• Card(AxAxAxA ) = 9*10*10*10 = 9*103 combinations
Example

• How many three digit numbers end with 0?

Note:
Let A = {0, 1, 2 .., 9} and A’ = A –{0}
Then all three-digit numbers belong to A’xAxA
Three-digit numbers ending with 0 belong to A’xAx{0}

|A’xAx{0}| = 9 x 10 x 1
= 90
Exercise

• How many 4 character alphanumeric strings are there? {Hint: 26


alphabetical letters and 10 decimal digits}

• Suppose a four bits are reserved to represent different colours. How


many distinct colours can be represented in this system?
The Addition Rule

• The Sum Rule, also called the law of inclusions and exclusion simply
states that

• If A and B are sets then Card(AB) = Card(A)+Card(B) –Card(AB)

• A special case when A and B are pairwise disjoint then Card(A  B) =


Card(A)+Card(B)
Example

• A car manufacturer finds that the most common production defects


are faulty brakes and broken headlights. In testing a sample of 80 cars
the manufacturer recorded the following data:
• 20 cars had faulty brakes
• 15 cars had broken headlights
• 10 cars have both
• How many cars have at least one of the problems?
• How many cars have neither?
• How many cars Have only the brake problem?
Example

• In the Basic programming language, a variable is either a single digit


or a letter followed by a decimal digit. How many variables are
available in Basic?
Solution

• Let A be the set of alphabetical letters


• Let B be the set of binary digits. Then the set of all combinations of
letter followed by digit is C = A x B
• The set of all variables in Basic then is
• AC=AAxB
• Note that A  A x B = 
• By the Addition and product rule
|A  A x B|= |A| + |A x B|
= 26 + 26 x 10
= 26(1 + 10)
= 26x11
= 286
Example

How many three digit numbers are divisible by 5?

Solution
One method was shown earlier. Here, we use the Addition rule.
Numbers divisible by 5 end with 5 or 0
Let A1 be three-digit numbers ending with 5
Let A2 be three-digit numbers ending with 0
Three-digit numbers divisible by 5 = A1A2
 |A1A2| = |A1| + |A2| (Since A1A2 = )
= 90 + 90
= 180
The Sum Rule

• The sum rule can be extended to more than two sets


• Card(A1A2 ..  An) = Card(A1)+Card(A2)+..+Card(An) when the sets
A1, A2,..,An, are pairwise disjoint
• If the sets A1, A2,..,An are not pairwise disjoint, the sum rule can be
developed for n > 2
Example
• Suppose a passcord can have one to three letters with a possibility of
repetition of latters in the code. How many different passcodes are
possible?
• Solution
• Let A be the set of one-letter codes
• Let B be the set of two-letter codes = AxA
• Let C be the set of three-letter codes = AxAxA
• A, B and C are pairwise disjoint.
• Set of passcords is ABC
Example cont’d

|ABC| = |A| + |A x A| + |A x A x A|
= 26 +26x26 + 26x26x26
= 26(1 + 26(1 + 26))
= 26(1 + 26x27)
= 26(1 + 702)
= 26 x 703
= 18,278 possible passcords
Permutations
• Definition
• Let A be a finite set. A permutation is a bijection f:A → A
• This is basically the different ways in which elements of A can be arranged
without repetition.
• If |A| = n, How many such permutations exists?
• Let A = {a, b, c}. How many arrangements are there of the elements in
the set A?
• {a, b, c}, {a, c, b}, {b, a, c}, {b, c, a}, {c, a, b}, {c, b, a}
• We see that there are 6 permutations
• Each of these arrangements is an example of a permutation of the set A.
Permutations

• To find all permutations you can use a tree diagram.


• The example on the previous page has 6 permutations.
• It is always possible to use a tree diagram to find all permutations of
finite a set A, but the process get tedious as the Card(A) grows to
greater than 4
Fundamental Counting Principle
• If an arrangement can be constructed in k successive steps, and if first
step can be performed in n1 ways, the second step in n2 ways, .., and the
kth step in nk ways, then the total number of arrangements is the
product n1*n2*..*nk
Example

• A student is enrolled in CSC2000, CSC2901, CSC2111 and CSC2101. In


how many different orders can her final examinations in these four
courses be scheduled? Assume there are no conflicts
• Solution
• Consider the case where there are four different slots for the four
courses
• Slot 1 has a possibility of being taken by any of the four courses
• Slot 2 has a possibility of being taken by any of the remaining three courses
• Slot 3 has a possibility of being taken by any of the remaining 2 courses
• Slot 3 has a possibility of being taken by any of the remaining 1 course
• By the product rule, there are 4x3x2x1 = 24 possible arrangements.
Examples

• How many four letter words can be constructed


• Even with repetitions
• Without repetition

• How many four letter strings have repeated symbols


Exercise

• Let A = {a, b, c, d, e}
• How may 3 letter strings of A can you get
• Without repetitions?
• Have repetitions?
Factorial notation

• The product of the first n consecutive integers is


n! = n*(n-1)*(n-2)*..*3*2*1
• Where n! is read n factorial
• The special case of 0! Is defined by 0! = 1
• Theorem
• if A has n elements, then the number of possible permutations of A is n!

• Ex: How many permutations can be formed from the letters in the
word NUMBER?
r-Permutations

• Definition
• Let A be a set with n elements, and let 0𝑟𝑛. An r-permutation of A is an
arrangement of r elements of A
• Example
• Consider set A = {a, b, c, d}. How many 2-permutations of A are there?
• Soln
• Use the tree diagram
r-Permutations

• Theorem
• The number of r-permutations of a set with n elements is
• P(n,r) = n(n-1)..[n-r+1] where 0 < r  n
Combinations

• In a permutation of a set the order of arrangements count.


• E.g. abc and acb are different permutations
• In combinations the order does not count
• All that’s required are r elements
• E.g. a 3 member committee
• Definition
• Let A be a set with n elements and 0rn. An r-combination of A is a subset
of A that contains r elements.
• The number of r-combinations in A is denoted by C(n,r), read ‘n choose r’.
Example

• Let A = {a, b, c}
• a. Find all 3-combinations
• b. Find all 2-combinations
• Soln
• a. I 3-combination
• b. 3 2-combinations
r-Combinations

• Theorem
• C(n, r) = P(n,r)/r!
• Proof
• Note that for every r-combination of a set A, there are r! r-permutations
since there are r! arrangements of r elements.
• By the fundamental principle of counting, the number of r-permutations of A
is
• P(n,r) = C(n,r).r!
r-Combinations

• Example
• A Discrete Mathematics class has 13 sophomores and 7 juniors
• a. How many 5-person committees can be formed from this class?
• b. How many 5-person committees with 3 sophomores and 2 juniors can be formed in
this class
• Soln
• a. C(20,5)
• b. C(13,3) x C(7,2)
Exercise

• If you are in a class of n students and a group of m  n members is to


be constituted. How many of such groups would you be member of?
r-Combinations

• Ex: a Computer Software company employs 25 women and 20 men.


An executive board of 5-directors is to be composed of 3 women and
2 men. In how many ways can such a board be selected?
• Corollary
• Let A be a set of n elements and 0rn. Then
C(n,r) = C(n, n-r)
•Proof: Exercise
r-Combinations

• Example:
• Suppose a group of 12 members has 5 man and 7 women
• How many 5-person teams can be chosen that consist of 3 man and 2
women?
• How many five person team contain at least 1 man?
• How many five person team contain at most 1 man?
r-Combinations

• Example:
• Suppose two members of a group insist on working together. Both
picked or not both picked. How many teams possible?
R-Combinations

• Theorem
• C(n, r) = C(n-1, r-1) +C(n-1, r), 0<rn
• Proof: Show that rhs = lhs
The Binomial Theorem

• Theorem
𝑛
𝑛 𝑛
• 𝑥+𝑎 =෍ 𝑘
𝑥 𝑘 𝑎𝑛−𝑘
𝑘=0
• Proof: Exercise
• The Binomial coefficients are displayed in the well-known Pascal’s
Triangle.
• Ex:
• In the expansion (x + y)7, what is the coefficient of the term that has y4?
Introduction to Finite
Probability
Introduction

• Probability theory is one of the most important areas of mathematics


from the point of view of applications.
• Defn
• An experiment is a measurement or observation of some process
• We assume an experiment results in exactly one outcome from several possible
outcomes
• Defn
• A sample point is an outcome of the experiment
• Defn
• A sample space is a set of all sample points.
Example: Rolling a dice

• Consider an experiment of rolling a dice and observing the upper


face value

• There are six possible outcomes of this experiment i.e. an integer


between 1 and 6 inclusive

• Therefore each of these outcomes is a sample point and S =


{1,2,3,4,5,6} is the sample space for this experiment.
Example: Tossing a coin

• What are the sample points of this experiment?


• H, for heads and
• T, for tails

• What is the sample space:


• S = {H,T}
Probability Function

• Defn
• An event is a subset of the sample space S
• Defn
• A simple event is a singleton set.
• E.g. {1} for the dice experiment is the event in which 1 is the upper face value
of rolling a dice.
• Defn
• An impossible event is an event with an empty set.
• For an event E, the sample points are called favourable outcomes
• An event E is said to occur whenever the outcome is in an element of
event E
• Two events A and B in a sample space are mutually exclusive if A  B
=
Probability Function cont’d

• In a dice experiment the event


• A = {2} is a simple event of observing a 2
• B = {1,3,5} is the event of observing an odd number
• C = {1,2,3,4} is the event of observing a number less than 5
• D = {2,4,6} is an event of observing an even number

• Note that events B and C are not mutually exclusive while B and D
are.

• In a balanced dice, what is the chance of observing a 3?


Probability Function cont’d

• If we roll a dice 6 million times we expect to observe a 3 1 million


times, which is 1/6
• Assume the sample space S has n points and each simple event Si = {i}
is equally likely for 1  i  n, we assign a probability of 1/n to each Si ,
denoted by P(Si)
• Defn
• Let P(S) be the power set of S, we can now define a probability function
Pr:P(S) → [0,1], using Pr(Si ) = 1/n
• If E is an event, then Pr(E) is equal to the sum of Pr(Si ) for each Si  E
• Pr(S) = 1
Defining a Probability Function

• Algorithm to define a Probability function


• Define the sample space S
• Assign probabilities to the simple events Si for 1  i  n, so that
σ𝑛𝑖=1 Pr Si = 1
• For each event E  S, define Pr(E) to be the sum of the probabilities for the
simple events corresponding to the sample points of E
• Note that the first two points above will always make assumptions
about the experiment
• Defn
• An equiprobale space is a sample space in which equal probabilities are
assigned to all simple events.
Defining the Probability Function

• Theorem
|𝐸|
• Let S be a finite equiprobable sample space. For a given event E, Pr 𝐸 = |𝑆|

• Proof: Use algorithm


• Suppose S has n sample points and E has m sample points
• S is an equiprobale space, Pr(Si) = 1/n for each simple event Si.
• Hence P(E) = m(1/n) = m/n = |E|/|S|
• Example
• If we rolled two balanced dice, the sum of the upper face values yields one
number. An integer between 2 to 12
• Is this the sample space? NO
• S = D x D, where D = {1,2,3,4,5,6} and |S| = 36, which is now an
equiprobable sample space.
Example cont’d

• What is the probability of hitting a 7


• |E| = 6
• |S| = 36 + 1 2 3 4 5 6

• Pr(E) = 6/36 = 1/6


1 2 3 4 5 6 7

2 3 4 5 6 7 8

3 4 5 6 7 8 9

4 5 6 7 8 9 10

5 6 7 8 9 10 11

6 7 8 9 10 11 12
Properties of the Probability Function

• Pr:P(S) → [0,1]
1. Pr(S) = 1
2. 0 Pr(E) 1 for any event E in S
3. If A and B are mutually exclusive events, then Pr(A  B) = Pr(A) + Pr(B)
• Property 3 is referred to as the additive law for mutually exclusive
events
• Theorem
• Pr(A’) = 1 – Pr(A)
• Proof
• S = A  A’
• P(S) = P(A  B) =P(A) + P(A’) = 1
• P(A’) = 1 - P(A)
• Ex: Show that Pr() = 0
Example

• Consider tossing a fair coin three times. What is the probability of


obtaining at least one head.
• Soln
• Let E be the event in which there’s at least a head
• Then E’ is the event in which there is no head at al, which is having three
tails, and occurs only once.
• |S| = 23
• Pr(E’) = 1/8
• P(E) = 1 – Pr(E’) = 1 – 1/8
• P(E) = 7/8
• Ex: What is the probability of getting at least a tail in the last two
tosses
Additive Law of Probability

• Theorem
• Pr(A  B) = Pr(A) + Pr(B) – Pr(A  B)
• Proof
• Note that A  B = (A – B)  (A  B)  (B – A) and the events A – B, A  B and
B – A are mutually exclusive
• Pr(A B) = Pr((A – B)  (A  B)  (B – A) )
=Pr(A – B) + Pr((A  B)  (B – A) )
=Pr(A – B) + Pr(A  B) + Pr(B – A) ………(i)
• Let A = (A – B)  (A  B) and B = (B – A)  (A  B)
• So Pr(A) = Pr((A – B)  (A  B) ) and Pr(B) = Pr((B – A)  (A  B))
• Pr(A) = Pr(A – B) + Pr(A  B) and Pr(B) = Pr(B – A) + Pr (A  B)
• Thus Pr(A – B) = Pr(A) – Pr(A  B) and Pr(B – A) = Pr(B) – Pr(A  B)
• Substituting in (i) completes the proof
Example

• Consider the experiment of tossing a coin three times. What is the


probability of tossing exactly 2 heads?
• Soln
• There are C(3, 2) ways of getting two heads from three tosses.
• C(3, 2) = 3 and |S| = 8
• Probability is 3/8
• Ex: What if the coin is tossed 7 times?
Example

• Example
• Suppose you belong to a class of 23 students. A team of 5 is to be
constituted. What is the probability the you will be included in the
team?
Solution

|S| = 9
|E| = 2
+ 1 2 3 4 5 6
P(E) = 2/9
1 2 3 4 5 6 7

2 3 4 5 6 7 8

3 4 5 6 7 8 9

4 5 6 7 8 9 10

5 6 7 8 9 10 11

6 7 8 9 10 11 12
Example

•You roll a fair die. Let A be the event that the


outcome is an odd number, i.e., A={1,3,5}.
Also let B be the event that the outcome is
less than or equal to 3, i.e., B={1,2,3}. What
is the probability of A, P(A)? What is the
probability of A given B, P(A|B)?
Solution

• This is a finite sample space, so


• P(A)=|A|/|S|=|{1,3,5}|/6=1/2.
• Now, let's find the conditional probability of A given that B occurred.
If we know B has occurred, the outcome must be among {1,2,3}. For
A to also happen the outcome must be in A∩B={1,3}. Since all die
rolls are equally likely, we argue that P(A|B) must be equal to
• P(A|B)=|A∩B|/|B|=2/3.
Conditional Probability

• Let A and B be events in S. Conditional probability denoted by P(A|B)


read probability of A given B is a measure of the probability of an
event A given that another event B has occurred

• Example
• A pair of fair dice, one blue and the other gray, are rolled. What is the
probability that the sum of the numbers showing face up is 8, given that both
of the numbers are even?
Conditional Probability

• Example
• In a bag with 5 red marbles and 7 blue marbles. Two marbles are picked one
after the other, without replacing. Let R = picking a red marble
• B = picking a blue marble
• What is P(B|R)?

• Solution
• If the first ball that was picked was red then there will be 11 marbles
remaining of which 7 will be blue.
• P(B|R) = 7/11
Conditional Probability

• Defn
• Let A and B be events in a sample space S. If P(A)  0, then the conditional
probability of B given A , denoted by P(B|A) is

Pr(𝐴 ∩ 𝐵)
𝑃𝑟 𝐵 𝐴 =
𝑃𝑟(𝐴)
Example

• An urn contains 5 blue and 7 gray marbles. Let us say that 2 are
chosen at random, one after the other, without replacement. Find
the following probabilities:
• the probability that both marbles are blue
• the probability that the first ball is blue and the second is not blue
• the probability that the first ball is not blue and the second ball is blue, and
the probability that neither ball is blue.
• What is the probability that the second ball is blue?
• What is the probability that at least one of the balls is blue?
• If the experiment of choosing two balls from the urn were repeated many
times over, what would be the expected value of the number of blue balls?
• Example in the book
Summary

• Counting

• Probability
• End!

You might also like