You are on page 1of 37

The Basics of Counting

Counting

 Assume we have a set of objects with certain


properties
 Counting is used to determine the number of these
objects
 Examples:
• Number of available phone numbers with 7 digits in the local calling area
• Number of possible match starters (football, basketball) given the number
of team members and their positions
Basic counting rules

 Counting problems may be hard, and easy


solution not obvious
 Approach:
– simplify the solution by decomposing
the problem
 Two basic decomposition rules:
– Sum rule
– Product rule
 Sum rule
– A count decomposes into a set of independent
counts (“elements of counts are alternatives”)
 Product rule
– A count decomposes into a sequence of dependent
counts (“each element in the first count is associate
d with all elements of the second count”)
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 EITHER 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 studies student body

 There are 12 SEA instructors


 There are 322 SEA 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


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?

 4 · 5 = 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
Inclusion-Exclusion Principle
 To count the number of distinct elements in two sets
– 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 structures
– 6 take both
 How many CS students are there?
– 25 + 18 is too many

 25 + 18 - 6 = 37 CS students
Inclusion-Exclusion

 |AB| = |A|+|B|- |AB|

C++ Discrete

19 6 12

25 18
Pigeonhole Principle
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/k/10

 Of 100 people, at least 9 born same month


n = 100 objects k = 12 boxes (months)
n/k/12
Generalized Pigeonhole Examples

 How many discrete students in a class of 11


are guaranteed to make the same grade
(A,B,C,D,E)?
n = 11 objects k = 5 boxes
n/k
Permutations and Combinations
Permutation

 An ordered arrangement of a set of distinct


objects.

 List the permutations of {R,G,B}


– {B,G,R} {B,R,G}
– {G,B,R} {G,R,B}
– {R,B,G} {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} {G,B}
{B,R} {R,B}
{G,R} {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!
Note: (n  r ) !
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 7 2  
 
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 
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 
 
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:

 C(n,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!)
 = 
 
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 
 
Combinations Example

 How many poker hands are there?

 C(52,5) = 52! / ((52-5)! 5!)


 = (52     
 
Lotto Example

 Choose 6 numbers between 1 and 40


 (1) Winner picks all 6 correctly

 C(40, 6) = 40! / (34! 6!)


 = 3,838,380

You might also like