Upload
rockers91
View
221
Download
0
Embed Size (px)
Citation preview
8/10/2019 Discrete Structure Chapter 4 Counting 52
1/52
Chapter 4
Counting
8/10/2019 Discrete Structure Chapter 4 Counting 52
2/52
4.1 Rule of Sum
4.2 Rule of Product
4.3 Permutations
4.4 Combinations
4.5 Summation Notation
4.6 Combinations with Repetition
4.7 Summary
Counting
8/10/2019 Discrete Structure Chapter 4 Counting 52
3/52
Counting
4.1: The Rule of Sum
The Rule of Sum:
m ways n ways
cannot be done simultaneously
then performing eithertask can be accomplished in any one of
m+n ways
8/10/2019 Discrete Structure Chapter 4 Counting 52
4/52
Counting
4.1: The Rules of Sum
Eg: 40 textbooks on sociology
50 textbooks on anthropology
to select 1 book: 40+50 choices
8/10/2019 Discrete Structure Chapter 4 Counting 52
5/52
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
8/10/2019 Discrete Structure Chapter 4 Counting 52
6/52
Counting
4.1: The Rules of Sum
Eg: things 1 2 3 ... kways m1 m2 m3 mk
select one of them: m1 +m2 +m3+...+ mk ways
8/10/2019 Discrete Structure Chapter 4 Counting 52
7/52
4.2: The Rules Product
Eg: An administrator assigns 12 of her employees to twocommittees.
Soln:Committee A - 5 members
Committee B7 members
Therefore, he can select members for committee A and B in5 x 7 = 35 ways
Counting
8/10/2019 Discrete Structure Chapter 4 Counting 52
8/52
Counting
4.2: The Rules Product
The Rule of Product
m ways n ways
then performing this task can be accomplished in any one ofmn ways
8/10/2019 Discrete Structure Chapter 4 Counting 52
9/52
Eg:A drama club of Central University is holding an auditionto select a hero and a heroin for a play.
If six men and eight women came for the audition, how manyways can we select a hero and a heroin?
Soln:
6 x 8 = 48 ways
Counting
4.2: The Rules Product
8/10/2019 Discrete Structure Chapter 4 Counting 52
10/52
Counting
4.2: The Rules of Product
Eg: The license plate: 2 letters-4 digits
(a) no letter or digit can be repeated26 25 10 9 8 7
(b) with repetitions allowed
26 26 10 10 10 10
(c) same as (b), but only vowels and even digits
52 x 54
= 3,276,000 different possible plates
= 6,760,000 different possible plates
8/10/2019 Discrete Structure Chapter 4 Counting 52
11/52
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 ofsandwiches and five beverages(hot coffee, hot tea, iced tea, cola andorange juice).
Ms Dodd, an editor at AWL, sends her assistant Carl to the shop to gether lunch either a muffin and a hot beverage or a sandwich and a coldbeverage.
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
8/10/2019 Discrete Structure Chapter 4 Counting 52
12/52
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
8/10/2019 Discrete Structure Chapter 4 Counting 52
13/52
Eg:Counting Passwords with Three or Fewer Letters
A computer access password consists of from one to three
letters chosen from the 26 in the alphabet with repetitions
allowed. How many different passwords are possible?
Soln:
Counting
4.1 and 4.2: The Rules of Sum and Product
8/10/2019 Discrete Structure Chapter 4 Counting 52
14/52
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
8/10/2019 Discrete Structure Chapter 4 Counting 52
15/52
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
8/10/2019 Discrete Structure Chapter 4 Counting 52
16/52
Eg: The number of Elements in a Cartesian Product
Suppose A1, A2, A3and A4 are sets with n1, n2, n3and n4
elements, respectively. Show that the set
A1x A2x A3x A4 has n1n2 n3n4 elements.
Soln:
Counting
4.2: The Rules of Sum and Product
8/10/2019 Discrete Structure Chapter 4 Counting 52
17/52
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
8/10/2019 Discrete Structure Chapter 4 Counting 52
18/52
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 jnext i
How many times will the inner loop be iterated when the algorithm is
implemented and run?
Soln:
Counting
4.2: The Rules of Sum and Product
8/10/2019 Discrete Structure Chapter 4 Counting 52
19/52
When the Product Rule is Difficult or Impossible to Apply:
Consider the following problem:
Three officersa president, a treasurer and a secretary -- are to be chosen from amongfour people: Ann, Bob, Cyd and Dan.
Suppose that, for various reasons, Ann cannot be president and either Cyd or Dan must besecretary. 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 presidentand treasurer. For instance, if Bob is chosen for president and Ann for treasurer, then thereare two choices for secretary (Cyd and Dan). But if Bob is chosen for president and Cyd fortreasurer, then there is just
one choice for secretary.
The clearest way construct a tree diagram.
Counting
8/10/2019 Discrete Structure Chapter 4 Counting 52
20/52
Counting
4.3: Permutations
Note: For an integer n, nfactorial (denoted n!) is defined by
0!=1, (n = 0)
n!=(n)(n-1)(n-2)...(3)(2)(1), for n>1.
Def:A permutation of a set of distinct objects is an ordered arrangement of
these objects.
Eg:Consider the set of elements a, b , c
abc acb cba bac bca cab
The number of permutations of three elements are
3! = 3 x 2 x 1 = 6 permutations
8/10/2019 Discrete Structure Chapter 4 Counting 52
21/52
Counting
4.3: Permutations
n n n n r n
n rP n r
( ) ( ) . . . ( )
!
( ) !( , )1 2 1
if repetitions are allowed:nr
In general:
Given a set of n distinct objects, how many permutations does the set have?
Step 1: Choose 1st element ( n ways to perform this)
Step 2: Choose 2ndelement ( n1 ways to perform this)
Step n: Choose n th element (1 way to perform this)
Therefore, for n objects n!
The number of r-permutation of a set with n-elements is denoted by P(n,r) ,
where (1 < r < n ).
8/10/2019 Discrete Structure Chapter 4 Counting 52
22/52
Proof:
Step 1: Choose 1stelement ( n ways to perform this)
Step 2: Choose 2nd
element ( n
1 ways to perform this)
Step 3: Choose 3rdelement (n 2ways to perform this)
Step r: Choose r th element (n - ( r - 1) way to perform this)
Therefore, by Rule of Product:
nx (n 1)x (n 2)x x (n r + 1 )
Counting4.3: Permutations
n n n n r n
n r
P n r
( ) ( ) . . . ( ) !
( ) !
( , )1 2 1
8/10/2019 Discrete Structure Chapter 4 Counting 52
23/52
Eg: Given the set {a , b , c }
ab ac ba bc ca cb
This is called 2-permutation of {a , b , c }
Counting
4.3: Permutations
8/10/2019 Discrete Structure Chapter 4 Counting 52
24/52
Counting
4.3: Permutations
E.g: a) permutation of letters BALL
4!/2!=12
b) permutation of PEPPER6!/(3!2!)=60
c) permutation of MASSASAUGA
10!/(4!3!)=25200
if all 4 As are together
7!/3!=840
8/10/2019 Discrete Structure Chapter 4 Counting 52
25/52
Eg:a) How many 4-permutations are there of a set of seven objects?b) How many 5-permutations are there of a set of five objects?
Soln:
Counting
4.3: Permutations
8/10/2019 Discrete Structure Chapter 4 Counting 52
26/52
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: Permutations
8/10/2019 Discrete Structure Chapter 4 Counting 52
27/52
Counting
4.3: Permutation
Eg: Permutations of the Letters in a word
a) How many ways can the letters in the word COMPUTER
be arranged in a row?
b) How many ways can the letters in the word COMPUTER
be arranged if the letters CO must remain next to eachother(in order) as a unit?
8/10/2019 Discrete Structure Chapter 4 Counting 52
28/52
Counting4.3: Permutations
Eg: Number of Manhattan paths between
two points (2,1) and (7,4) with integer coordinated
Soln:
From (2,1) to (7,4): 3 Ups, 5 Rights
Each permutation of UUURRRRR is a path.
8!/(5!3!)=56
y y
x x0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
(2,1)
(7,4)
(2,1)
(7,4)
8/10/2019 Discrete Structure Chapter 4 Counting 52
29/52
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.3: Permutations
8/10/2019 Discrete Structure Chapter 4 Counting 52
30/52
Counting
4.4: Combinations(The Binomial Theorem)
When dealing with any counting problem, we should ask
ourselves about the importance of order in the problem.
When order is relevant, we think in terms of permutations and
arrangements and the rule of product. When order is not
relevant, combinations could play a key role in solving the
problem.
8/10/2019 Discrete Structure Chapter 4 Counting 52
31/52
C i
8/10/2019 Discrete Structure Chapter 4 Counting 52
32/52
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)
C ti
8/10/2019 Discrete Structure Chapter 4 Counting 52
33/52
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:
Counting
4.4: Combinations(The Binomial Theorem)
a) C(10,5) =252
b) C(4,2)=6{0,1},{0,2},{0,3},{1,2},{1,3},{2,3}
C ti
8/10/2019 Discrete Structure Chapter 4 Counting 52
34/52
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
4.4: Combinations(The Binomial Theorem)
C ti
8/10/2019 Discrete Structure Chapter 4 Counting 52
35/52
Counting
2.4: Combinations(The Binomial Theorem)
Select 3 cards from a deck of playing cards without replacement:
order of selection is relevant: P(52,3)= 52 51 50
order of selection is irrelevant: P(52,3)/3!=C(52,3)
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.
8/10/2019 Discrete Structure Chapter 4 Counting 52
36/52
Counting
4.4: Combinations(The Binomial Theorem)
Eg:At Sultan Ismail High School, the PE teacher must select nine girls fromthe 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 fiveseniors. How many ways to select the team?
a) C(53,9) = 4,431,613,550 ways
b) C(50,6) = 15,890,700 ways
c)By Rule of Product: C(28,4) x C(25,5) = 1,087,836,750 ways
8/10/2019 Discrete Structure Chapter 4 Counting 52
37/52
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)
C(36,9) x C(27,9) x C(18,9) x C(9,9) = 2.145 x 10 19
8/10/2019 Discrete Structure Chapter 4 Counting 52
38/52
Counting
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
3 2 2 2 1 1831600
!
! ! ! ! ! !,
b) without adjacent A:
82 2 2
93
!! ! !
disregard A first 9 positions for 3 A
to be inserted
4.4: Combinations(The Binomial Theorem)
E E S T L L S H
Counting
8/10/2019 Discrete Structure Chapter 4 Counting 52
39/52
Counting4.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
8/10/2019 Discrete Structure Chapter 4 Counting 52
40/52
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:
Counting4.4: Combinations(The Binomial Theorem)
Counting
8/10/2019 Discrete Structure Chapter 4 Counting 52
41/52
Counting4.6: Combinations with Repetition
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. c , c , h , h , t , t , f
2. c , c , c , c , h , t , f
3. c , c , c , c , c , c , f
4. h , t , t , f , f , f , f
5. t , t , t , t , t , f , f
6. t , t , t , t , t , t , t
7. f , f , f , f , f , f ,f
1. x x |x x | x x | x
2. x x x x | x | x | x
3. x x x x x x | | | x
4. | x | x x | x x x x
5. | | x x x x x | x x
6. | | x x x x x x x |
7. | | | x x x x x x x
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 )
No. of bars = n1 ; no. of star = r (i.e. 7-combinations of 4 elements)
The number of combinations = C ( n + r - 1 , r ) = C ( 4 + 71, 7) = C (10 ,7 )
8/10/2019 Discrete Structure Chapter 4 Counting 52
42/52
Counting
4.5: Summation Notation
Counting
8/10/2019 Discrete Structure Chapter 4 Counting 52
43/52
Eg:A donutshop offers 20 kinds of donuts. Assuming that there are at least adozen 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 + 121, 12) = C (31 , 12) = 141,120,525 ways.
Counting
4.6: Combinations with Repetition
Counting
8/10/2019 Discrete Structure Chapter 4 Counting 52
44/52
Eg: In how many ways can we distribute seven bananas and six oranges amongfour 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 + 31, 3) = 20 ways.
Six oranges are distributed in C (4 + 61, 6) = 84 ways.
Therefore, to distribute seven bananas and six oranges = 20 x 84 = 1680 ways.
Counting
4.6: Combinations with Repetition
Counting
8/10/2019 Discrete Structure Chapter 4 Counting 52
45/52
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:
Examples of ways to select five bills:
| | | * * | | | * * *
Or * | * | * * | | * | |
Or * | | | * * | | * | *
No. of bars = n1 ; no. of stars = r (i.e. 5-combinations of 7 elements)
C ( n + r - 1 , r ) = C (7 + 51, 5) = C (11, 5) = 462 ways.
$100 $50 $20 $10 $5 $2 $1
Counting
8/10/2019 Discrete Structure Chapter 4 Counting 52
46/52
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:
Counting
4.6: Combinations with Repetition
K 1 2 3 .. n
J 1 1 2 1 2 3 .. 1 2 .. n
i 1 1 1 2 1 1 2 1 2 3 1 1 2 .. 1 .. N
The number of iteration of the innermost loop= [n(n + 1)(n + 2)]/6
Counting
8/10/2019 Discrete Structure Chapter 4 Counting 52
47/52
Exercise:How many ways are there to place ten indistinguishable balls
into eight distinguishable bins?
Soln:
Counting
4.6: Combinations with Repetition
Counting
8/10/2019 Discrete Structure Chapter 4 Counting 52
48/52
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
8/10/2019 Discrete Structure Chapter 4 Counting 52
49/52
8/10/2019 Discrete Structure Chapter 4 Counting 52
50/52
Counting
4.7 Summary
order is repetitions
relevant are allowed type of result formula
YES NO permutation
YES YES arrangement
NO NO combination
combination
NO YES with repetition
P n r n n r
r n
( , ) !/ ( ) !,
0
n n rr
, , 0
C n r n r n r
r n
( , ) !/ [ !( ) !]
0
n r
r
1
Select or Order robjects from ndistinct objects
8/10/2019 Discrete Structure Chapter 4 Counting 52
51/52
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
4.7 Summary
8/10/2019 Discrete Structure Chapter 4 Counting 52
52/52
Counting
End of Chapter 4