Discrete Structures Chapter 4 Counting and Probability
description
Transcript of Discrete Structures Chapter 4 Counting and Probability
Discrete StructuresChapter 4
Counting and ProbabilityNurul Amelina Nasharuddin
Multimedia Department
Outline
• Rules of Sum and Product• Permutations• Combinations: The Binomial Theorem• Combinations with Repetition: Distribution• Probability
2
Combinations with Repetition
Example:
How many ways are there to select 4 pieces of fruits from a bowl containing apples, oranges, and pears if the order does not matter, only the type of fruit matters, and there are at least 4 pieces of each type of fruit in the bowl
3
Answer• Some of the results:
4
Possible Selection Representation
A A A O X X X | X |
A A A A X X X X | |
A A O P X X | X | X
P P P P | | X X X X
Answer
The number of ways to select 4 pieces of fruit = The number of ways to arrange 4 X’s and 2 |’s, which is given by
= 6! / 4!(6-4)! = C(6,4) = 15 ways.
5
4
134
Combinations with Repetition
• In general, when we wish to select, with repetition, r of n distinct elements, we are considering all arrangements of r X’s and n-1 |’s and that their number is
6
r
nr
nr
nr 1
)!1(!
)!1(
Combinations with Repetition
• An r-combination of a set of n elements is an unordered selection of r elements from the set, with repetition is:
7
)!1(!
)!1(1),1(
nr
nr
r
nrrnrC
Example (1)
A person throwing a party wants to set out 15 assorted cans of drinks for his guests. He shops at a store that sells five different types of soft drinks. How many different selections of 15 cans can he make?
(Here n = 5, r = 15)
8
Example (1)
• 4 |’s (to separate the categories of soft drinks)• 15 X’s (to represent the cans selected)
= 19! / 15!(19-15)!
= C(19,15)
= 3876 ways.
9
15
1515
Example (2)
A donut shop offers 20 kinds of donuts. Assuming
that there are at least a dozen of each kind when we
enter the shop, we can select a dozen donuts in
(Here n = 20, r = 12).
= C(31, 12) = 141,120,525 ways.
10
12
12012
Example (3)
A restaurant offers 4 kinds of food. In how many ways can we choose six of the food?
C(6 + 4 - 1, 6) = C(9, 6)
= C(9, 3)
= 9! = 84 ways.
3! 6!
11
Which formula to use?
Order Relevant Order Does Not Relevant
Repetition is Allowed nk
Repetition is Not Allowed
P(n, k)
12
Different ways of choosing k elements from n
k
nk 1
k
n
Counting and Probability
Discrete Probability
• The probability of an event is the likelihood that event will occur.
• “Probability 1” means that it must happen while “probability 0” means that it cannot happen
• Eg: The probability of… – “Manchester United defeat Liverpool this season” is 1– “Liverpool win the Premier League this season” is 0
• Events which may or may not occur are assigned a number between 0 and 1.
Discrete Probability
Consider the following problems:• What’s the probability of tossing a coin 3
times and getting all heads or all tails?
• What’s the probability that a list consisting of n distinct numbers will not be sorted?
Discrete Probability
• An experiment is a process that yields an outcome• A sample space is the set of all possible outcomes
of a random process• An event is an outcome or combination of
outcomes from an experiment• An event is a subset of a sample space• Examples of experiments: - Rolling a six-sided die - Tossing a coin
ExampleExperiment 1: Tossing a coin.• Sample space: S = {Head or Tail} or we could write: S =
{0, 1} where 0 represents a tail and 1 represents a head.
Experiment 2: Tossing a coin twice• S = {HH, TT, HT, TH} where some events:
– E1 = {Head},
– E2 = {Tail},
– E3 = {All heads}
17
Definition of Probability• Suppose an event E can happen in r ways out of a total of n
possible equally likely ways.• Then the probability of occurrence of the event (called its
success) is denoted by
• The probability of non-occurrence of the event (called its failure) is denoted by
• Thus,
18
n
rEP )(
n
r
n
rnEP
1)(
1)()( EPEP
Definition of Probabilityusing Sample Spaces
• If S is a finite sample space in which all outcomes are equally likely and E is an event in S, then the probability of E, P(E), is
• where
N(E) is the number of outcomes in E
N(S) is the total number of outcomes in S
19
||
||
)(
)()(
S
E
SN
ENEP
Example (1)
What’s the probability of tossing a coin 3 times and getting all heads or all tails?Can consider set of ways of tossing coin 3 times: Sample space, S = {HHH, HHT, HTH, HTT, THH, THT, TTH, TTT}Next, consider set of ways of tossing all heads or all tails: Event, E = {HHH, TTT}
Assuming all outcomes equally likely to occur P(E) = 2/8 = 0.25
Example (2)
• Five microprocessors are randomly selected from a lot of 1000 microprocessors among which 20 are defective. Find the probability of obtaining no defective microprocessors.
There are C(1000,5) ways to select 5 micros.There are C(980,5) ways to select 5 good micros.The prob. of obtaining no defective micros isC(980,5)/C(1000,5) = 0.904
Probability of Combinations of Events
• Theorem: Let E1 and E2 be events in the sample space S. Then
P(E1 E2) = P(E1) + P(E2) – P(E1 E2)
• Eg: What is the probability that a positive integer selected at random from the set of positive integers not greater than 100 is divisible by either 2 or 5
E1: Event that the integer selected is divisible by 2
E2: Event that the integer selected is divisible by 5
P(E1 E2) = 50/100 + 20/100 – 10/100 = 3/5
Exercise
a) If any seven digits could be used to form a telephone number, how many seven-digits telephone numbers would not have repeated digits?
b) How many seven-digit telephone numbers would have at least one repeated digit?
c) What is the probability that a randomly chosen seven-digit telephone number would have at least one repeated digit?
23
Answer
a) 10 x 9 x 8 x 7 x 6 x 5 x 4 = 604800
b) [no of PN with at least one digit] = [total no of PN] – [no of PN with no repeated digit] = 107 – 604800 = 9395200
c) 9395200 / 107 = 0.93952
24
Counting Elements of Sets
The Principle of Inclusion/Exclusion Rule for Two or Three Sets
If A, B, and C are finite sets, thenN(AB) = N(A) + N(B) – N(A B)
and N(ABC) = N(A) + N(B) + N(C) – N(AB) – N(AC) – N(BC) +
N(ABC)
Example (1)
• In a class of 50 college freshmen, 30 are studying BASIC, 25 studying PASCAL, and 10 are studying both.
How many freshmen are not studying either computer language?
A: set of freshmen study BASIC B: set of freshmen study PASCAL N(AB) = N(A)+N(B)-N(AB) = 30 + 25 – 10 = 45 Not studying either: 50 – 45 =5
10
20
10
15
Example (2)
• A professor takes a survey to determine how many students know certain computer languages. The finding is that out of a total of 50 students in the class,
30 know Java;18 know C++;26 know SQL;
9 know both Java and C++;16 know both Java and SQL;
8 know both C++ and SQL;47 know at least one of the 3 languages.
Example (2)
a. How many students know none of the three languages?
b. How many students know all three languages?c. How many students know Java and C++ but not
SQL? How many students know Java but neither C++ nor SQL
Answer:a. 50 – 47 = 3b. ?c. ?
Example (2)
• J = the set of students who know Java
• C = the set of students who know C++
• S = the set of students who know SQL
• Use Inclusion/Exclusion rule.