* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Download 1 - NEMCC Math/Science Division
		                    
		                    
								Survey							
                            
		                
		                
                            
                            
								Document related concepts							
                        
                        
                    
						
						
							Transcript						
					
					Counting
Chapter 4
The Basics of Counting
4.1
Sum Rule
If a task can be done n1 ways
 Or the task can be done n2 ways
there are n1 + n2 ways to do the task
NOTE: Only one task is performed;
it is performed via n1 OR n2
Sum Rule Examples
You may pick one committee member
 The member may be from the faculty OR
from the computer science student body
There are 12 CS instructors
 There are 322 CS students
There are 12 + 322 = 334 possible choices
Sum Rule Examples
You may pick a project from one of three
lists:
– 23 on the first
– 15 on second
– 19 on third
There are 23 + 15 + 19 = 57 possible
choices
The sum rule is analogous to
sequential for loops
k=0;
 for (int i=0; i<n; i++)
k = k +1;
for (int i=0; i<m; i++)
k = k +1;
for (int i=0; i<p; i++)
k = k +1;
Final k value:
k==n+m+p
Product Rule
A procedure can be broken down into 2 tasks
The first task can be done n1 ways
 The second task can be done n2 ways
there are n1 · n2 ways to do the procedure
NOTE: both tasks are required to do the procedure
n1 AND n2
Product Rule Examples
A
student brings 5 shirts and 4 pairs of
pants to campus.
 How many outfits can he wear?
5
· 4 = 20 outfits
Product Rule Examples
A Chinese restaurant serves
– 3 soups
– 5 meat entrees
– 6 vegetables
A regular priced meal consists of one soup, one meat, and
one vegetable.
How many different regular meals could one order?
There are 3 · 5 · 6 = 90 possible meals
Product Rule Examples
How many bit strings of length seven exist?
_ _ _ _ _ _ _
2 · 2 · 2 · 2 · 2 · 2 · 2 = 27
7 “holes” to be filled; 2 ways to fill each hole
Product Rule Examples
How many license plates are available if
each plate consists of
– 3 letters
– 3 digits
26 · 26 · 26 · 10 · 10 · 10
 17,576,000
The product rule is analogous to
nested for loops
k=0;
 for (int i=0; i<n; i++)
for (int j=0; j<m; j++)
for (int q=0; q<p; q++)
k = k +1;
Final k value:
k==n·m·p
Inclusion-Exclusion Principle
To count the number of distinct elements in two sets
–
1.
2.
3.
where it it possible for some elements to be in both sets
Add the number in the first set
To the number in the second set
Subtract number in both sets
Same problem: count the ways of performing two tasks
where performing the two tasks simultaneously is possible
NOTE: The sum rule assumes sets are distinct
(tasks may NOT be done at the simultaneously)
Inclusion-Exclusion Example
Of all CS students
• 25 take C++ programming
• 18 take discrete math
• 6 take both
How many CS students are there?
• 25 + 18 is too many
25 + 18 - 6 = 37 CS students
Inclusion-Exclusion
|AB| = |A|+|B|- |AB|
C++
19
25
Discrete
6
12
18
Pigeonhole Principle
4.2
Pigeonhole Principle
If k+1 or more objects
 are placed into k boxes
– there is at least one box
– containing two or more objects
Pigeonhole Principle Examples
In a group of 367 people
– at least 2 people have the same birthday.
(366 boxes, 367 objects)
Given 27 English words
– at least two begin with the same letter.
(26 boxes, 27 objects)
How many students must be in a class to
– guarantee at least two score the same on a final
– scored 0 to 100?
102
Generalized Pigeonhole Principle
If n objects
 are placed in k boxes
 there is at least one box containing at least
n/k objects
Generalized Pigeonhole Examples
A number 21 digits long
– must have at least 3 digits which are the same
n = 21 objects (digits) k = 10 boxes (0-9)
n/k21/102.13
Of 100 people, at least 9 born same month
n = 100 objects
k = 12 boxes (months)
n/k100/128.339
Generalized Pigeonhole Examples
How many discrete students in a class of 11 are
guaranteed to make the same grade?
n = 11 objects k = 5 boxes
n/k11/52.23
How many area codes guarantee a state with 25
million phones with have distinct # s?
720-7408; 10 million # s per area code
n/k25M/10M2.53
Permutations and Combinations
4.3
Permutation
An ordered arrangement of a set of distinct
objects.
List the permutations of {R,G,B}
– {B,G,R}
– {G,B,R}
– {R,B,G}
{B,R,G}
{G,R,B}
{R,G,B}
r-Permutation
An ordered arrangement of r elements of a set
–
–
–
–
Select r objects from a set of n elements
Do not select the same object twice
Permute the r objects
ORDER MATTERS
Perform a 2-permutation on {R,G,B}
{B,G}
{B,R}
{G,R}
{G,B}
{R,B}
{R,G}
Number of r-Permutations
The number of r-Permutations in a set with
n elements:
P(n,r) = n(n-1)(n-2) … (n - r + 1)
=
n!
(n  r )!
Note:
P(n,n) = n!
P(n,1) = n
Permutation Examples
How many possible arrangements exist of the
letters: ABCEILNRSTU?
P(n,n) = P(11,11) = n!
= 11!
= 11  10  9 8 7  6 5 4 3 2  1
 3,628,800
Find the word, get three bonus points. (16/class)
Permutation Examples
10 students compete for gold, silver, and
bronze programming medals.
 How many different ways might the
programmers finish?
P(n,r) = P(10,3) = 10! / (10-3)!
 = 10  9 8720
Permutation Examples
How many ‘words’ of 4 letters can be
obtained from the letters: NORTHEAS
P(n,r) = P(8,4) = 8! / (8-4)!
 = 8  7 6 5
 1680
r-Combination
A selection of r elements of a set
–
–
–
–
Select r objects from a set of n elements
Do not select the same object twice
Equate lists with the same elements: {B,R}={R,B}
ORDER DOES NOT MATTER
List all 2-combinations on {R,G,B}
– {B,G}
– {B,R}
– {G,R}
Number of r-Combinations
The number of r-Combinations in a set with
n elements:
n!
 C(n,r) =
(n  r )! r !
Note:
C(n,n) = C(n,0) = 1
C(n,1) = C(n, n-1) = n
Combination Examples
What 3-combinations exist of the set
{1,2,3,4}?
{2,3,4}
{1,3,4}
{1,2,4}
{1,2,3}
Combination Examples
What 2-combinations exist of the set
{1,2,3,4}?
{1,2}
{1,3}
{1,4}
{2,3}
{2,4}
{3,4}
Combination Examples
A Chinese restaurant allows one to order 2
of 8 main dishes. How many different
combinations of 2 dishes are available?
C(n,r) = n! / ((n-r)! r!)
 = 8! / ((8-2)! 2!)
 = 8 7/2
 28
Combination Examples
How many programming teams (4 members)
can be selected from 10 CS students?
C(10,4) = 10! / ((10-4)! 4!)
 = (10  9  8  7)/(4 3 2)
 210
Combinations Example
How many poker hands are there?
C(52,5) = 52! / ((52-5)! 5!)
 = (52  51  50  49  48) /(5 43 2)
 2,598,960
What is the Probability of
drawing a flush in a poker game?
How many diamond flush hands?
C(13,5) = 13! / ( (13-5)! 5! )
= (13  12  11  10  9) /(5 4 3 2)
1287
Hands of any flush? |E| = 4  12875148
|S| = C(52,5) = 2,598,960
p(E) = |E| / |S| = 5,148 / 2,598,960
= 0.0019807 = 0.2% or 2 out of 1000
Binomial Coefficients
4.4
Binomial Coefficients
C(n, r) “n CHOOSE r”
 n
 
 r
is called a binomial coefficient
The value of C(n, r) occurs as coefficients
in the expansion of powers of binomial
expressions such as (a + b)n
Pascal’s Triangle
Binomial Theorem
Given variables, x and y and positive integer n
n
( x  y )   C ( n, j ) x
n
n j
y
j
j 0
 n n  n n 1  n n  2 2
 n  n 1  n n
   x    x y    x y  ...  
 xy    y
 0
 1
 2
 n  1
 n
Binomial Examples
Expand (x+y)4.
4
( x  y )   C ( 4, j ) x
4
4 j
y
j
j 0
 4 4  4 3
 4 2 2  4
 4 4
3
  x  x y x y  x y   y
 0
 1
 2
 3
 4
= 1x4 + 4x3y + 6x2y2 + 4xy3 + 1y4
Binomial Examples
What is the coefficient of x12y13 in the
expansion of (x+y)25?
C(25,13)
= 25! / (13! 12!)
= 5,200,300
Binomial Examples
What is the coefficient of x12y13 in the expansion
of (2x-3y)25?
25
(2 x  3 y )   C(25, j ) (2 x )
25
25 j
j 0
C(25,13) 212 (-3)13
= - ( 25! 212 313) / (13! 12!)
( 3 y )
j
Discrete Probability
5.1
Finite Probability
Experiment
– a procedure that yields one of a given set of
possible outcomes
Sample Space
– the set of possible outcomes of an experiment
Event
– a subset of the sample space
Probability of event E
The probability of event E
– a subset of sample space S
– of equally likely outcomes
p(E) = |E| / |S|
Probability Example
An urn contains 4 blue and five red legos.
 What is probability a blue lego is chosen?
S is the set of all possible outcomes
|S| = 9
E is a subset of S which results in blue choices
|E| = 4
p(E) = |E| / |S| = 4/9
Probability Example
What is the probability that when two dice
are rolled, the sum of the numbers is 7?
S is the set of all possible outcomes
|S| = 6  636
E is a subset of S which results in total of 7
(1,6), (2,5), (3,4), (4,3), (5,2), (6,1)
|E| = 6
p(E) = |E| / |S| = 6 / 36 = 1/6
Probability Example
How many poker hands are there?
C(52,5) = 52! / ((52-5)! 5!)
 = (52  51  50  49  48) /(5 43 2)
 2,598,960
What is the Probability of
drawing a flush in a poker game?
How many diamond flush hands?
C(13,5) = 13!/((13-5)! 5!)
= (13  12  11  10  9) /(5 4 3 2)
1287
Hands of any flush? |E| = 4  12875148
|S| = C(52,5) = 2,598,960
p(E) = |E| / |S| = 5,148 / 2,598,960
= 0.0019807 = 0.2% or 2 out of 1000
Lottery Example
Win a big prize if you pick a correct 4 digit #.
 Win a smaller prize if you pick any 3 of the 4
digits corrects.
S is the set of all possible outcomes
|S| = 9999 + 1
The winner of the big prize must choose all 4 correctly
|E| = 1
p(E) = |E| / |S| = 1/10000
Lottery Example
Win a smaller prize if you pick any 3 of the 4
digits corrects.
The winner of the smaller prize must choose 3 correctly
1  1  1  9 (Rule out correct # in last digit)
1191
1911
9111
p(E) = |E| / |S| = 9  4/10000 = .36 %
Lotto Example
Choose 6 numbers between 1 and 40
 (1) Winner picks all 6 correctly
C(40, 6) = 40! / (34! 6!)
= 3,838,380
Probability 1/ 3,838,380 = 0.000026%
Complementary Event E
Given E is an event in a sample space S
The probability of E,
– the complementary event of E
p(E) = 1 - p(E)
NOTE: E  E = U
Complementary Event Example
10 bits are generated randomly
What is probability that one of these bits is 0?
How many bit strings DO NOT have a zero? 1
How many bit strings of length 10 exist? 1024
Let E be event that strings DO NOT have zero
p(E) = 1 / 1024
Let E be event that strings have a zero
p(E) = 1 - p(E) = 1 - (1 / 1024) = 1023 / 1024 = 99.9%
Probability of Two Events
Let E1 and E2 be events in sample space S.
p(E1  E2) = p(E1) + p(E2) - p(E1  E2)
Two Events Probability Example
Pick a number (randomly) between 1-100
What is probability number is divisible by either 2 or 5?
p(E1) = 50 / 100
p(E2) = 20 / 100
Numbers divisible by 10 are divisible by 2 and 5
p(E1  E2) = 10 / 100
p(E1  E2) = p(E1) + p(E2) - p(E1  E2)
= (50 + 20 - 10) / 100 = 60 / 100 = 3 / 5
					 
									 
									 
									 
									 
									 
									 
									 
									 
									 
									 
									 
									 
									 
									 
									 
									 
									 
									 
									 
									 
									 
									 
									 
									 
									 
									 
									 
									 
									 
									 
									 
									 
									 
									 
									 
									 
									 
									 
									 
									 
									 
									 
									 
									 
									 
									 
									 
									 
									 
									 
									 
									 
									 
									 
									 
									 
									 
									 
                                             
                                             
                                             
                                             
                                             
                                             
                                             
                                             
                                             
                                             
                                            