Transcript lecture04c

Discrete Structures
Chapter 4
Counting and Probability
Nurul 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:
Possible Selection
Representation
AAAO
XXX|X|
AAAA
XXXX | |
AAOP
XX|X|X
PPPP
||XXXX
4
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
 4  3  1

 = 6! / 4!(6-4)! = C(6,4) = 15 ways.
 4 
5
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 n1 |’s and that their number is
(r  n  1)!  r  n  1

 
r!(n  1)!  r 
6
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:
 r  n  1 (r  n  1)!
 
C (r  n  1, r )  
 r  r!(n  1)!
7
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)
15  5  1


 15 
= 19! / 15!(19-15)!
= C(19,15)
= 3876 ways.
9
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).
12  20  1 = C(31, 12) = 141,120,525 ways.


 12 
10
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?
Different ways of choosing k elements from n
Order Relevant
Repetition is Allowed
Repetition is Not Allowed
Order Does Not Relevant
nk
 k  n  1


 k 
P(n, k)
n
 
k 
12
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
Example
Experiment 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
r
P( E ) 
n
• The probability of non-occurrence of the event (called its
failure) is denoted by
nr
r
P( E ) 
 1
n
n
• Thus, P ( E )  P ( E )  1
18
Definition of Probability
using 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
N (E) | E |
P( E ) 

N (S ) | S |
• where
N(E) is the number of outcomes in E
N(S) is the total number of outcomes in S
19
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 is
C(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, then
N(AB) = N(A) + N(B) – N(A  B)
and
N(ABC) = N(A) + N(B) + N(C) –
N(AB) – N(AC) – N(BC) +
N(ABC)
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
20
B: set of freshmen study PASCAL
10
10
N(AB) = N(A)+N(B)-N(AB)
15
= 30 + 25 – 10 = 45
• Not studying either: 50 – 45 =5
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 = 3
b. ?
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.