Discrete Structure Chapter 4 Counting 52
Discrete Structure Chapter 4 Counting 52
Counting
Counting
4.1
4.2
4.3
4.4
4.5
4.6
4.7
Rule of Sum
Rule of Product
Permutations
Combinations
Summation Notation
Combinations with Repetition
Summary
Counting
4.1: The Rule of Sum
m ways
n ways
cannot be done simultaneously
then performing either task can be accomplished in any one of
m+n ways
Counting
4.1: The Rules of Sum
Eg:
40 textbooks on sociology
50 textbooks on anthropology
to select 1 book: 40+50 choices
Counting
4.1: The Rules of Sum
Eg: A Computer Science instructor has seven introductory
books of each on C++, Java and Perl
Soln:
How many ways can a student select a book?
7 + 7 + 7 = 21 ways
Counting
4.1: The Rules of Sum
Eg:
things 1
ways
3 ... k
m1 m2 m3
mk
Counting
4.2: The Rules Product
Eg: An administrator assigns 12 of her employees to two
committees.
Soln:
Committee A - 5 members
Committee B 7 members
Therefore, he can select members for committee A and B in
5 x 7 = 35 ways
Counting
4.2: The Rules Product
m ways
n ways
mn ways
Counting
4.2: The Rules Product
Counting
4.2: The Rules of Product
Eg: The license plate: 2 letters-4 digits
(a) no letter or digit can be repeated
26 25 10 9 8 7
= 3,276,000 different possible plates
(b) with repetitions allowed
26 26 10 10 10 10
= 6,760,000 different possible plates
(c) same as (b), but only vowels and even digits
52 x 54
Counting
4.1 and 4.2: The Rules of Sum and Product
Eg: Mrs. Foster operates a Quick Snack Coffee Shop at AWL corporation.
The menu at her shop is limited: six kinds of muffins, eight kinds of
sandwiches and five beverages(hot coffee, hot tea, iced tea, cola and
orange juice).
Ms Dodd, an editor at AWL, sends her assistant Carl to the shop to get
her lunch either a muffin and a hot beverage or a sandwich and a cold
beverage.
Soln:
A muffin and a hot beverage = 6 x 2 = 12 ways
A sandwich and a cold beverage = 8 x 3 = 24 ways
There are 12 + 24 ways to buy Ms Dodds lunch
Counting
4.1 and 4.2: The Rules of Sum and Product
BASIC variables: single letter
or single letter and single digit
26+26x10=286
rule of sum
rule of product
Counting
4.1 and 4.2: The Rules of Sum and Product
Eg: Counting Passwords with Three or Fewer Letters
Counting
4.2: The Rules of Sum and Product
Eg: Counting the Number of Integers Divisible by 5
How many three digit integers(integers from 100 to 999 inclusive) are
divisible by 5?
Soln:
Counting
4.2: The Rules of Sum and Product
Eg: Number of Personal Identification Numbers(PINS)
A typical PIN(Personal Identification Number) is a sequence of any four
symbols chosen from the 26 letters in the alphabet and the ten digits,
with repetition allowed. How many different PINS are possible?
Soln:
Counting
4.2: The Rules of Sum and Product
Eg: The number of Elements in a Cartesian Product
Suppose A1 , A2 , A3 and A4 are sets with n1, n2 , n3 and n4
elements, respectively. Show that the set
A1 x A2 x A3 x A4 has n1 n2 n3 n4 elements.
Soln:
Counting
4.2: The Rules of Sum and Product
Eg: Number of PINS without repetition
A typical PIN(Personal Identification Number) is a sequence of any
four symbols chosen from the 26 letters in the alphabet and the ten
digits, with repetition is not allowed.. How many different PINS are
possible?
Soln:
Counting
4.2: The Rules of Sum and Product
Eg: Counting the following nested loop:
for I:= 1 to 4
for j:= 1 to 3
[Statements in body of inner loop. None contain branching statements
that lead out of the inner loop.]
next j
next i
How many times will the inner loop be iterated when the algorithm is
implemented and run?
Soln:
Counting
When the Product Rule is Difficult or Impossible to Apply:
Consider the following problem:
Three officers a president, a treasurer and a secretary -- are to be chosen from among
four people: Ann, Bob, Cyd and Dan.
Suppose that, for various reasons, Ann cannot be president and either Cyd or Dan must be
secretary. How many ways can the officers be chosen?
By Product Rule, a person might answer as follows:
3 choices for president(all except Ann)
3 choices for treasurer(all except the one chosen as president)
2 choices for secretary (Cyd or Dan)
Therefore, by product rule, 3 x 3 x 2 = 18 choices in all.
Unfortunately, this analysis is incorrect.
Why?
The no. of ways to choose the secretary varies depending on who is chosen for president
and treasurer. For instance, if Bob is chosen for president and Ann for treasurer, then there
are two choices for secretary (Cyd and Dan). But if Bob is chosen for president and Cyd for
treasurer, then there is just
one choice for secretary.
Counting
4.3: Permutations
Def: A permutation of a set of distinct objects is an ordered arrangement of
these objects.
Counting
4.3: Permutations
In general:
Given a set of n distinct objects, how many permutations does the set have?
n!
n ( n 1) ( n 2 ) . . . ( n r 1)
n!
P( n , r )
(n r ) !
Counting
4.3: Permutations
n!
n ( n 1) ( n 2 ) . . . ( n r 1)
P( n , r )
(n r ) !
Proof:
Step 1: Choose 1st element ( n ways to perform this)
Step 2: Choose 2nd element ( n 1 ways to perform this)
Step 3: Choose 3rd element (n 2 ways to perform this)
Counting
4.3: Permutations
Eg: Given the set {a , b , c }
ab ac ba bc ca cb
Counting
4.3: Permutations
E.g:
b) permutation of PEPPER
6!/(3!2!)=60
c) permutation of MASSASAUGA
10!/(4!3!)=25200
if all 4 As are together
7!/3!=840
Counting
4.3: Permutations
Eg: a) How many 4-permutations are there of a set of seven objects?
b)
Soln:
Counting
4.3: Permutations
Eg: a) How many different ways can three of the letters of the word
BYTES be chosen and written in a row?
b) How many different ways can this be done if the first letter must be B?
Soln:
Counting
4.3: Permutation
Eg: Permutations of the Letters in a word
a)
Counting
4.3: Permutations
Eg: Number of Manhattan paths between
two points (2,1) and (7,4) with integer coordinated
(7,4) y
(7,4)
(2,1)
0
(2,1)
4
Soln:
From (2,1) to (7,4): 3 Ups, 5 Rights
Each permutation of UUURRRRR is a path.
8!/(5!3!)=56
Counting
4.3: Permutations
Eg: Proving a property of P( n , r )
Prove that for all integers n > 2 ,
P( n , 2 ) + P( n , 1 ) = n2
Soln:
Counting
4.4: Combinations(The Binomial Theorem)
Counting
4.4: Combinations(The Binomial Theorem)
In general, the no. of r-combinations of a set with n distinct elements is
denoted by C(n , r) and is called a binomial coefficient (where n is a
nonnegative integer and (0 r n) ).
P( n , r )
n!
C( n , r )
,0 r n
r!
r !( n r ) !
Counting
4.4: Combinations(The Binomial Theorem)
eg.: Let S = {Ann, Bob, Chan, Dan}. Each committee consisting of three of the four
people in S is a 3-combination of S.
List all such 3-combination of S.
Solution:
{Bob, Chan, Dan}
{Ann, Chan, Dan}
{Ann, Bob, Dan}
{Ann, Bob, Chan}
Counting
4.4: Combinations(The Binomial Theorem)
Eg: Unordered Selection
a)
How many ways are there to select five players from a 10 member tennis
team to make a trip to a match at another school?
b)
How many unordered selections of two elements can be made from the
set {0 , 1 , 2 , 3}?
Soln:
a)
b)
C(10,5) =252
C(4,2)=6
{0,1},{0,2},{0,3},{1,2},{1,3},{2,3}
Counting
4.4: Combinations(The Binomial Theorem)
Eg: Relation Between Permutations & CombinationsWrite all 2-permutation
from the set {0 , 1 , 2 , 3}? Find P(4,2).
a)
Write all 2-combination from the set {0 , 1 , 2 , 3}? Find C(4,2).
Soln:
Counting
2.4: Combinations(The Binomial Theorem)
Eg: A standard deck of playing cards consists of 52 cards comprising four suits:
Clubs, Diamonds, Hearts, Spades.
Each suit has 13 cards: ace, 2 , 3 , 4 ,., 9 , 10 , jack , queen , king.
Counting
4.4: Combinations(The Binomial Theorem)
Eg: At Sultan Ismail High School, the PE teacher must select nine girls from
the junior and senior classes for a volleyball team.
a) If there are 28 juniors and 25 seniors, how many selection can she make?
b) If two juniors and one senior are the best spikers and must be on the
team, the how many way to select the team?
c) For a certain tournament the team must comprise four juniors and five
seniors. How many ways to select the team?
Counting
4.4: Combinations(The Binomial Theorem)
Eg: A PE teacher must make up four basketball teams of nine girls each from 36
freshman girls in her P.E. class. In how many ways can she select these four
teams?
Counting
4.4: Combinations(The Binomial Theorem)
Eg: The letters in TALLAHASSEE
a) How many arrangements can be made from the letters in TALLAHASSEE?
b) How many of these arrangements have no adjacent As ?
11!
831,600
3!2 !2 !2 !1!1!
b) without adjacent A:
E S T L L S H
8!
9
2 !2 !2 ! 3
disregard A first
9 positions for 3 A
to be inserted
Counting
4.4: Combinations(The Binomial Theorem)
Eg: How many ways are there to select a committee members to develop a
discrete mathematics course at a school if the committee is to consist of three
faculty members from the mathematics department and four from the computer
science department, if there are nine faculty members of the mathematics
department and eleven members of the computer science department?
Soln:
Counting
4.4: Combinations(The Binomial Theorem)
Eg: a) A student taking a history examination is directed to answer any seven of 10 essay
questions. There is no concern about order here, so how many ways can the student
answer the examination?
b) If the student must answer three questions from the first five and four questions from
the last five, how many ways the student can complete the examination?
c) Finally, should the direction on this examination indicate that the student must answer
seven of the 10 questions where at least three are selected from the first five, how
many ways can the student complete the examination?
Soln:
Counting
4.6: Combinations with Repetition
Note: In general, the number of r-combinations from a set with n elements when
repetition of elements is allowed is given by C ( n + r - 1 , r )
Eg: On their way home from track practice, seven high school freshmen stop at a
restaurant. Each of them bought one of the following: a cheeseburger, a hot dog, a
taco, or a fish sandwich. How many different purchases are possible?
1.
2.
3.
4.
5.
6.
7.
c,c,h,h,t,t,f
c,c,c,c,h,t,f
c,c,c,c,c,c,f
h,t,t,f,f,f,f
t,t,t,t,t,f,f
t,t,t,t,t,t,t
f , f , f , f , f , f ,f
1.
2.
3.
4.
5.
6.
7.
x x |x x | x x | x
xxxx|x|x|x
xxxxxx|||x
|x|xx|xxxx
||xxxxx|xx
||xxxxxxx|
|||xxxxxxx
No. of bars = n 1
; no. of star = r (i.e. 7-combinations of 4 elements)
The number of combinations = C ( n + r - 1 , r ) = C ( 4 + 7 1, 7) = C (10 ,7 )
Counting
4.5: Summation Notation
Counting
4.6: Combinations with Repetition
Eg: A donut shop offers 20 kinds of donuts. Assuming that there are at least a
dozen of each kind when we enter the shop. How many ways can we select
a dozen of donuts?
Soln: ( 12-combinations of 20 elements)
C ( n + r - 1 , r ) = C ( 20 + 12 1, 12) = C (31 , 12) = 141,120,525 ways.
Counting
4.6: Combinations with Repetition
Eg: In how many ways can we distribute seven bananas and six oranges among
four children so that each child receives at least one banana?
Soln:
After giving one child a banana, the remaining three bananas are distributed to
four children in:
C (4 + 3 1, 3) = 20 ways.
Six oranges are distributed in C (4 + 6 1, 6) = 84 ways.
Counting
4.6: Combinations with Repetition
Eg: How many ways are there to select five bills from a cash box containing $1
bills, $2 bills, $5 bills, $10 bills, $20 bills, $50 bills and $100 bills?
Assume that the order in which the bills are chosen does not matter, that the bills
of each denomination are indistinguishable, and that there are at least five bills of
each type.
Soln:
$100
$50
$20
$10
$5
$2
$1
*|* | ** | | * | |
Or
*| | | * * | | *| *
No. of bars = n 1
Counting
4.6: Combinations with Repetition
Eg: Counting Iterations of a Loop
How many times will the innermost loop be iterated when the algorithm segment below is
implemented and run? (Assume n is a positive integer.)
for k:= 1 to n
for j:= 1 to k
for i:=1 to j
[Statements in the body of the inner loop, none containing
branching statements that lead outside the loop.]
next I
next j
next k
Soln:
K 1
3
2
..
..
3 1
..
..
.. N
Counting
4.6: Combinations with Repetition
Exercise: How many ways are there to place ten indistinguishable balls
into eight distinguishable bins?
Soln:
Counting
4.6: Combinations with Repetition
Exercise: Suppose that a cookie shop has four different kinds of cookies.
How many different ways can six cookies be chosen?
Assume that only the type of cookie, and not the individual cookies or
the order in which they are chosen, matters.
Soln:
Counting
4.6: Combinations with Repetition
Exercise: In how many ways can one distribute 10 (identical) marbles
among six distinct containers?
Soln:
Counting
4.7 Summary
Select or Order r objects from n distinct objects
order is
relevant
repetitions
are allowed
type of result
YES
NO
permutation
YES
YES
arrangement
NO
NO
C( n , r ) n !/[ r !( n r ) !]
0 r n
combination
n r 1
with repetition
NO
YES
combination
formula
P( n, r ) n !/ ( n r ) !,
0 r n
n r , n, r 0
Counting
4.7 Summary
How do I know what to multiply and what to add?
When to use rule of product and when to use rule of sum?
Tips:
1.
You need to imagine the objects you are to count.
2.
Make an actual list of the items you are trying to count to get a sense
for how to obtain them in a systematic way.
3.
Construct a model that would allow you to continue counting the
objects.
Counting
End of Chapter 4