Date post: | 18-Jan-2016 |
Category: |
Documents |
Upload: | alyson-webb |
View: | 222 times |
Download: | 0 times |
11
Basics of CountingBasics of Counting
CS/APMA 202CS/APMA 202
Rosen section 4.1Rosen section 4.1
Aaron BloomfieldAaron Bloomfield
22
The product ruleThe product rule
If there are If there are nn11 ways to do task 1, and ways to do task 1, and nn22 ways to ways to
do task 2do task 2 Then there are Then there are nn11nn22 ways to do both tasks in ways to do both tasks in
sequencesequence This applies when doing the “procedure” is made up This applies when doing the “procedure” is made up
of separate tasksof separate tasks We must make one choice AND a second choiceWe must make one choice AND a second choice
33
Product rule exampleProduct rule example
Rosen, section 4.1, question 1 (a)Rosen, section 4.1, question 1 (a) There are 18 math majors and 325 CS majorsThere are 18 math majors and 325 CS majors How many ways are there to pick one math How many ways are there to pick one math
major major andand one CS major? one CS major?
Total is 18 * 325 = 5850Total is 18 * 325 = 5850
44
Product rule exampleProduct rule example
Rosen, section 4.1, question 22 (a) and (b)Rosen, section 4.1, question 22 (a) and (b)How many strings of 4 decimal digits…How many strings of 4 decimal digits…
a)a) Do not contain the same digit twice?Do not contain the same digit twice?We want to chose a digit, then another that is not the same, We want to chose a digit, then another that is not the same, then another…then another…
First digit: 10 possibilitiesFirst digit: 10 possibilitiesSecond digit: 9 possibilities (all but first digit)Second digit: 9 possibilities (all but first digit)Third digit: 8 possibilitiesThird digit: 8 possibilitiesFourth digit: 7 possibilitiesFourth digit: 7 possibilities
Total = 10*9*8*7 = 5040Total = 10*9*8*7 = 5040
b)b) End with an even digit?End with an even digit?First three digits have 10 possibilitiesFirst three digits have 10 possibilitiesLast digit has 5 possibilitiesLast digit has 5 possibilitiesTotal = 10*10*10*5 = 5000Total = 10*10*10*5 = 5000
55
The sum ruleThe sum rule
If there are If there are nn11 ways to do task 1, and ways to do task 1, and nn22 ways to ways to
do task 2do task 2 If these tasks can be done at the same time, then…If these tasks can be done at the same time, then… Then there are Then there are nn11++nn22 ways to do one of the two tasks ways to do one of the two tasks We must make one choice OR a second choiceWe must make one choice OR a second choice
66
Sum rule exampleSum rule example
Rosen, section 4.1, question 1 (b)Rosen, section 4.1, question 1 (b) There are 18 math majors and 325 CS majorsThere are 18 math majors and 325 CS majors How many ways are there to pick one math How many ways are there to pick one math
major major oror one CS major? one CS major?
Total is 18 + 325 = 343Total is 18 + 325 = 343
77
Sum rule exampleSum rule example
Rosen, section 4.1, question 22 (c)Rosen, section 4.1, question 22 (c)How many strings of 4 decimal digits…How many strings of 4 decimal digits…
c)c) Have exactly three digits that are 9s?Have exactly three digits that are 9s? The string can have:The string can have:
The non-9 as the first digitThe non-9 as the first digitOR the non-9 as the second digitOR the non-9 as the second digitOR the non-9 as the third digitOR the non-9 as the third digitOR the non-9 as the fourth digitOR the non-9 as the fourth digitThus, we use the sum ruleThus, we use the sum rule
For each of those cases, there are 9 possibilities for For each of those cases, there are 9 possibilities for the non-9 digit (any number other than 9)the non-9 digit (any number other than 9)
Thus, the answer is 9+9+9+9 = 36Thus, the answer is 9+9+9+9 = 36
8
Quick surveyQuick survey
I’m feeling good with the sum rule I’m feeling good with the sum rule and the product rule…and the product rule…
a)a) Very wellVery well
b)b) With some review, I’ll be goodWith some review, I’ll be good
c)c) Not reallyNot really
d)d) Not at allNot at all
99
More complex counting problemsMore complex counting problems
We combining the product rule and the We combining the product rule and the sum rulesum rule
Thus we can solve more interesting and Thus we can solve more interesting and complex problemscomplex problems
1010
Wedding pictures exampleWedding pictures example
Rosen, section 4.1, question 38Rosen, section 4.1, question 38Consider a wedding picture of 6 peopleConsider a wedding picture of 6 people
There are 10 people, including the bride and groomThere are 10 people, including the bride and groom
a)a) How many possibilities are there if the bride must be in How many possibilities are there if the bride must be in the picturethe picture
Product rule: place the bride AND then place the rest of the Product rule: place the bride AND then place the rest of the partypartyFirst place the brideFirst place the bride
She can be in one of 6 positionsShe can be in one of 6 positions
Next, place the other five people via the product ruleNext, place the other five people via the product ruleThere are 9 people to choose for the second person, 8 for the There are 9 people to choose for the second person, 8 for the third, etc.third, etc.Total = 9*8*7*6*5 = 15120Total = 9*8*7*6*5 = 15120
Product rule yields 6 * 15120 = 90,720 possibilitiesProduct rule yields 6 * 15120 = 90,720 possibilities
1111
Wedding pictures exampleWedding pictures example
Rosen, section 4.1, question 38Rosen, section 4.1, question 38Consider a wedding picture of 6 peopleConsider a wedding picture of 6 people
There are 10 people, including the bride and groomThere are 10 people, including the bride and groom
b)b) How many possibilities are there if the bride and groom How many possibilities are there if the bride and groom must both be in the picturemust both be in the picture
Product rule: place the bride/groom AND then place the rest of Product rule: place the bride/groom AND then place the rest of the partythe partyFirst place the bride and groomFirst place the bride and groom
She can be in one of 6 positionsShe can be in one of 6 positionsHe can be in one 5 remaining positionsHe can be in one 5 remaining positionsTotal of 30 possibilitiesTotal of 30 possibilities
Next, place the other four people via the product ruleNext, place the other four people via the product ruleThere are 8 people to choose for the third person, 7 for the fourth, There are 8 people to choose for the third person, 7 for the fourth, etc.etc.Total = 8*7*6*5 = 1680Total = 8*7*6*5 = 1680
Product rule yields 30 * 1680 = 50,400 possibilitiesProduct rule yields 30 * 1680 = 50,400 possibilities
1212
Wedding pictures exampleWedding pictures example
Rosen, section 4.1, question 38Rosen, section 4.1, question 38Consider a wedding picture of 6 peopleConsider a wedding picture of 6 people
There are 10 people, including the bride and groomThere are 10 people, including the bride and groom
c)c) How many possibilities are there if only one of the bride and How many possibilities are there if only one of the bride and groom are in the picturegroom are in the picture
Sum rule: place only the brideSum rule: place only the brideProduct rule: place the bride AND then place the rest of the partyProduct rule: place the bride AND then place the rest of the partyFirst place the brideFirst place the bride She can be in one of 6 positionsShe can be in one of 6 positions
Next, place the other five people via the product ruleNext, place the other five people via the product ruleThere are 8 people to choose for the second person, 7 for the third, etc.There are 8 people to choose for the second person, 7 for the third, etc.
We can’t choose the groom!We can’t choose the groom!Total = 8*7*6*5*4 = 6720Total = 8*7*6*5*4 = 6720
Product rule yields 6 * 6720 = 40,320 possibilitiesProduct rule yields 6 * 6720 = 40,320 possibilities OR place only the groomOR place only the groom
Same possibilities as for bride: 40,320Same possibilities as for bride: 40,320
Sum rule yields 40,320 + 40,320 = 80,640 possibilitiesSum rule yields 40,320 + 40,320 = 80,640 possibilities
1313
Wedding pictures exampleWedding pictures example
Rosen, section 4.1, question 38Rosen, section 4.1, question 38Consider a wedding picture of 6 peopleConsider a wedding picture of 6 people
There are 10 people, including the bride and groomThere are 10 people, including the bride and groom
Alternative means to get the answerAlternative means to get the answer
c)c) How many possibilities are there if only one of the bride and How many possibilities are there if only one of the bride and groom are in the picturegroom are in the picture
Total ways to place the bride (with or without groom): 90,720 Total ways to place the bride (with or without groom): 90,720 From part (a)From part (a)
Total ways for both the bride and groom: 50,400Total ways for both the bride and groom: 50,400From part (b)From part (b)
Total ways to place ONLY the bride: 90,720 – 50,400 = 40,320Total ways to place ONLY the bride: 90,720 – 50,400 = 40,320Same number for the groomSame number for the groomTotal = 40,320 + 40,320 = 80,640Total = 40,320 + 40,320 = 80,640
14
Quick surveyQuick survey
I’m feeling good with these sum and I’m feeling good with these sum and product rule examples…product rule examples…
a)a) Very wellVery well
b)b) With some review, I’ll be goodWith some review, I’ll be good
c)c) Not reallyNot really
d)d) Not at allNot at all
1616
The inclusion-exclusion principleThe inclusion-exclusion principle
When counting the possibilities, we can’t When counting the possibilities, we can’t include a given outcome more than once!include a given outcome more than once!
|A|A11U AU A22| = |A| = |A11| + |A| + |A22| - |A| - |A11∩ A∩ A22|| Let ALet A11 have 5 elements, A have 5 elements, A22 have 3 elements, have 3 elements,
and 1 element be both in Aand 1 element be both in A11 and A and A22
Total in the union is 5+3-1 = 7, not 8Total in the union is 5+3-1 = 7, not 8
1717
Inclusion-exclusion exampleInclusion-exclusion example
Rosen, section 4.1, example 16Rosen, section 4.1, example 16How may bit strings of length eight start with 1 or end with 00?How may bit strings of length eight start with 1 or end with 00?
Count bit strings that start with 1Count bit strings that start with 1 Rest of bits can be anything: 2Rest of bits can be anything: 277 = 128 = 128 This is |AThis is |A11||
Count bit strings that end with 00Count bit strings that end with 00 Rest of bits can be anything: 2Rest of bits can be anything: 266 = 64 = 64 This is |AThis is |A22||
Count bit strings that both start with 1 and end with 00Count bit strings that both start with 1 and end with 00 Rest of the bits can be anything: 2Rest of the bits can be anything: 255 = 32 = 32 This is This is |AThis is This is |A11∩ A∩ A22||
Use formula |AUse formula |A11U AU A22| = |A| = |A11| + |A| + |A22| - |A| - |A11∩ A∩ A22||
Total is 128 + 64 – 32 = 160Total is 128 + 64 – 32 = 160
1818
Bit string possibilitiesBit string possibilities
Rosen, section 4.1, question 42Rosen, section 4.1, question 42
How many bit strings of length 10 contain How many bit strings of length 10 contain either 5 consecutive 0s or 5 consecutive either 5 consecutive 0s or 5 consecutive 1s?1s?
1919
Bit string possibilitiesBit string possibilities
Consider 5 consecutive 0s firstConsider 5 consecutive 0s first
Sum rule: the 5 consecutive 0’s can start at position 1, 2, 3, 4, 5, or 6Sum rule: the 5 consecutive 0’s can start at position 1, 2, 3, 4, 5, or 6 Starting at position 1Starting at position 1
Remaining 5 bits can be anything: 2Remaining 5 bits can be anything: 255 = 32 = 32 Starting at position 2Starting at position 2
First bit must be a 1First bit must be a 1 Otherwise, we are including possibilities from the previous case!Otherwise, we are including possibilities from the previous case!
Remaining bits can be anything: 2Remaining bits can be anything: 244 = 16 = 16 Starting at position 3Starting at position 3
Second bit must be a 1 (same reason as above)Second bit must be a 1 (same reason as above)
First bit and last 3 bits can be anything: 2First bit and last 3 bits can be anything: 244 = 16 = 16 Starting at positions 4 and 5 and 6Starting at positions 4 and 5 and 6
Same as starting at positions 2 or 3: 16 eachSame as starting at positions 2 or 3: 16 each Total = 32 + 16 + 16 + 16 + 16 + 16 = 112Total = 32 + 16 + 16 + 16 + 16 + 16 = 112
The 5 consecutive 1’s follow the same pattern, and have 112 possibilitiesThe 5 consecutive 1’s follow the same pattern, and have 112 possibilities
There are two cases counted twice (that we thus need to exclude): There are two cases counted twice (that we thus need to exclude): 0000011111 and 11111000000000011111 and 1111100000
Total = 112 + 112 – 2 = 222Total = 112 + 112 – 2 = 222
2020
Tree diagramsTree diagrams
We can use tree diagrams to enumerate We can use tree diagrams to enumerate the possible choicesthe possible choices
Once the tree is laid out, the result is the Once the tree is laid out, the result is the number of (valid) leavesnumber of (valid) leaves
2121
Tree diagrams exampleTree diagrams example
Rosen, section 4.1, question 48Rosen, section 4.1, question 48
Use a tree diagram to find the number of bit strings of Use a tree diagram to find the number of bit strings of length four with no three consecutive 0slength four with no three consecutive 0s
2222
An example closer to home…An example closer to home…
winlose
winwin
loselose
win
winwin
win
lose
lose
lose
lose
How many ways can the Cavs finish the How many ways can the Cavs finish the season 9 and 2?season 9 and 2?
Playing Miami
Playing GA Tech
Playing VA Tech
(7,1)
(7,2) (8,1)
(7,3)
(7,4) (8,3) (7,3)
(8,2)
(9,2)
(8,2) (9,1)
(8,3) (9,2) (9,2) (10,1)
23
Quick surveyQuick survey
I felt I understood the material in this I felt I understood the material in this slide set…slide set…
a)a) Very wellVery well
b)b) With some review, I’ll be goodWith some review, I’ll be good
c)c) Not reallyNot really
d)d) Not at allNot at all
24
Quick surveyQuick survey
The pace of the lecture for this The pace of the lecture for this slide set was…slide set was…
a)a) FastFast
b)b) About rightAbout right
c)c) A little slowA little slow
d)d) Too slowToo slow
25
Quick surveyQuick survey
How interesting was the material in How interesting was the material in this slide set? Be honest!this slide set? Be honest!
a)a) Wow! That was SOOOOOO cool!Wow! That was SOOOOOO cool!
b)b) Somewhat interestingSomewhat interesting
c)c) Rather bortingRather borting
d)d) ZzzzzzzzzzzZzzzzzzzzzz
2626
Beware!!!Beware!!!