0% found this document useful (0 votes)
16 views28 pages

Chapter 6

Uploaded by

abrar.lol789
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views28 pages

Chapter 6

Uploaded by

abrar.lol789
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 28

Counting

Chapter 6

With Question/Answer
Animations

Copyright © McGraw-Hill Education. All rights reserved. No reproduction or distribution without the prior written consent of McGraw-Hill Education.
Chapter Summary
The Basics of Counting
The Pigeonhole Principle
The Basics of Counting
Section 6.1
Section Summary
The Product Rule
The Sum Rule
The Subtraction Rule
Examples, Examples, and Examples
Tree Diagrams
Basic Counting Principles: The Product
Rule
The Product Rule: A procedure can be
broken down into a sequence of two tasks.
There are n1 ways to do the first task and n2
ways to do the second task. Then there are
n1∙n2 ways to do the procedure.

Example: How many bit strings of length


seven are there?

either a 0 or a 1, the answer is 27 = 128.


Solution: Since each of the seven bits is
The Product Rule
Example: How many different license plates
can be made if each plate contains a
sequence of three uppercase English letters
followed by three digits?

there are 26 ∙ 26 ∙ 26 ∙ 10 ∙ 10 ∙ 10 =
Solution: By the product rule,

17,576,000 different possible license plates.


Product rule example
 How many strings of 4 decimal digits…

a) Do not contain the same digit twice?

We want to chose a digit, then another that is not the same, then
another…
 First digit: 10 possibilities
 Second digit: 9 possibilities (all but first digit)
 Third digit: 8 possibilities
 Fourth digit: 7 possibilities

Total = 10*9*8*7 = 5040


b) End with an even digit?

First three digits have 10 possibilities

Last digit has 5 possibilities

7
Total = 10*10*10*5 = 5000
Counting Functions
Counting Functions: How many functions
are there from a set with m elements to a set
with n elements?
Solution: Since a function represents a
choice of one of the n elements of the
codomain for each of the m elements in the

are n ∙ n ∙ ∙ ∙ n = nm such functions.


domain, the product rule tells us that there
Counting Functions
Counting One-to-One Functions: How many one-
to-one functions are there from a set with m
elements to one with n elements?
Solution: First note that when m > n there are no one-
to-one functions from a set with m elements to a set with
n elements.
Now let m ≤ n, Suppose the elements in the domain are
a1, a2,…, am. There are n ways to choose the value of a1
and
n−1 ways to choose a2
. . . . . .

. . . . . .

n − m + 1 ways to choose a
Telephone Numbering Plan
telephone number consists of 10 digits, consisting of a three-digit area code,
Example: The North American numbering plan (NANP) specifies that a

a three-digit office code, and a four-digit station code. There are some
restrictions on the digits.
 Let X denote a digit from 0 through 9.
 Let N denote a digit from 2 through 9.
 Let Y denote a digit that is 0 or 1.
 In the old plan (in use in the 1960s) the format was NYX-NNX-XXXX.
 In the new plan, the format is NXX-NXX-XXXX.

How many different telephone numbers are possible under the old plan and
the new plan?

Solution: Use the Product Rule.


 There are 8 ∙2 ∙10 = 160 area codes with the format NYX.
 There are 8 ∙10 ∙10 = 800 area codes with the format NXX.
 There are 8 ∙8 ∙10 = 640 office codes with the format NNX.
 There are 10 ∙10 ∙10 ∙10 = 10,000 station codes with the format XXXX.

Number of old plan telephone numbers: 160 ∙640 ∙10,000 =


1,024,000,000.
Number of new plan telephone numbers: 800 ∙800 ∙10,000 =
6,400,000,000.
Basic Counting Principles: The Sum Rule
The Sum Rule: If a task can be done either in one of n1
ways or in one of n2, where none of the set of n1 ways is
the same as any of the n2 ways, then there are n1 + n2
ways to do the task.
Example: The mathematics department must choose
either a student or a faculty member as a representative

for this representative if there are 37 members of the


for a university committee. How many choices are there

mathematics faculty and 83 mathematics majors and no


one is both a faculty member and a student.

37 + 83 = 120 possible ways to pick a


Solution: By the sum rule it follows that there are

representative.
The Sum Rule in terms of sets.
The sum rule can be phrased in terms of sets.
|A ∪ B|= |A| + |B| as long as A and B are
disjoint sets.
Or more generally,

|A1 ∪ A2 ∪ ∙∙∙ ∪ Am |= |A1| + |A2| + ∙∙∙ + |Am|


when Ai ∩ Aj = ∅ for all i, j.
The case where the sets have elements in
common will be discussed when we consider the
subtraction rule and taken up fully in Chapter 8.
Sum rule example
 How many strings of 4 decimal digits…
Have exactly three digits that are 9s?
 The string can have:
 The non-9 as the first digit
 OR the non-9 as the second digit
 OR the non-9 as the third digit
 OR the non-9 as the fourth digit
 Thus, we use the sum rule
 For each of those cases, there are 9 possibilities for
the non-9 digit (any number other than 9)
 Thus, the answer is 9+9+9+9 = 36

13
Combining the Sum and Product Rule
Example: Suppose statement labels in a
programming language can be either a single
letter or a letter followed by a digit. Find the
number of possible labels.

26 + 26 ∙ 10 = 286
Solution: Use the product rule.
Counting Passwords
 Combining the sum and product rule allows us to solve more complex problems.
Example: Each user on a computer system has a password, which is six to eight
characters long, where each character is an uppercase letter or a digit. Each
password must contain at least one digit. How many possible passwords are
there?

Solution: Let P be the total number of passwords, and let P6, P7, and P8 be the
passwords of length 6, 7, and 8.
 By the sum rule P = P6 + P7 +P8.
 To find each of P6, P7, and P8 , we find the number of passwords of the specified length
composed of letters and digits and subtract the number composed only of letters. We
find that:

P6 = 366 − 266 =2,176,782,336 − 308,915,776 =1,867,866,560.


P7 = 367 − 267 =
78,364,164,096 − 8,031,810,176 = 70,332,353,920.
P8 = 368 − 268 =
2,821,109,907,456 − 208,827,064,576 =2,612,282,842,880.

Consequently, P = P6 + P7 +P8 = 2,684,483,063,360.


Wedding pictures example
 Consider a wedding picture of 6 people
 There are 10 people, including the bride and groom

a) How many possibilities are there if the bride must be in


the picture
Product rule: place the bride AND then place the rest of the party
First place the bride
 She can be in one of 6 positions
Next, place the other five people via the product rule
 There are 9 people to choose for the second person, 8 for the third,
etc.
 Total = 9*8*7*6*5 = 15120
Product rule yields 6 * 15120 = 90,720 possibilities

16
Wedding pictures example
 Consider a wedding picture of 6 people
 There are 10 people, including the bride and groom

b) How many possibilities are there if the bride and groom


must both be in the picture
Product rule: place the bride/groom AND then place the rest of
the party
First place the bride and groom
 She can be in one of 6 positions
 He can be in one 5 remaining positions
 Total of 30 possibilities
Next, place the other four people via the product rule
 There are 8 people to choose for the third person, 7 for the fourth,
etc.
 Total = 8*7*6*5 = 1680
Product rule yields 30 * 1680 = 50,400 possibilities

17
Wedding pictures example
 Consider a wedding picture of 6 people
 There are 10 people, including the bride and groom

c) How many possibilities are there if only one of the bride and groom
are in the picture
Sum rule: place only the bride
 Product rule: place the bride AND then place the rest of the party
 First place the bride
 She can be in one of 6 positions
 Next, place the other five people via the product rule
There are 8 people to choose for the second person, 7 for the third, etc.
 We can’t choose the groom!
Total = 8*7*6*5*4 = 6720
 Product rule yields 6 * 6720 = 40,320 possibilities
 OR place only the groom
 Same possibilities as for bride: 40,320
Sum rule yields 40,320 + 40,320 = 80,640 possibilities

18
Basic Counting Principles: Subtraction Rule
Subtraction Rule: If a task can be done
either in one of n1 ways or in one of n2 ways,

is n1 + n2 minus the number of ways to do


then the total number of ways to do the task

the task that are common to the two different


ways.
Also known as, the principle of inclusion-
exclusion:
Counting Bit Strings
either start with a 1 bit or end with the two bits
Example: How many bit strings of length eight

00?
Solution: Use the subtraction rule.

that start with a 1 bit: 27 = 128


Number of bit strings of length eight

that end with bits 00: 26 = 64


Number of bit strings of length eight

that start with a 1 bit and end with bits 00 : 25


Number of bit strings of length eight

= 32
Hence, the number is 128 + 64 − 32 = 160.
Tree Diagrams
Tree Diagrams: We can solve many counting problems
through the use of tree diagrams, where a branch represents
a possible choice and the leaves represent possible outcomes.
Example: Suppose that “I Love Discrete Math” T-shirts come
in five different sizes: S,M,L,XL, and XXL. Each size comes in
four colors (white, red, green, and black), except XL, which
comes only in red, green, and black, and XXL, which comes
only in green and black. What is the minimum number of
shirts that the campus book store needs to stock to have one
of each size and color available?
Solution: Draw the tree diagram.

The store must stock 17 T-shirts.


Tree diagrams example
Use a tree diagram to find the number of bit
strings of length four with no three consecutive
0s

22
The Pigeonhole Principle
Section 6.2
Section Summary
The Pigeonhole Principle
The Generalized Pigeonhole Principle
The Pigeonhole Principle
 If a flock of 20 pigeons roosts in a set of 19 pigeonholes, one
of the pigeonholes must have more than 1 pigeon.

Pigeonhole Principle: If k is a positive integer and k + 1


objects are placed into k boxes, then at least one box contains
two or more objects.
Proof: We use a proof by contraposition. Suppose none of
the k boxes has more than one object. Then the total number

that we have k + 1 objects.


of objects would be at most k. This contradicts the statement
The Pigeonhole Principle
Corollary 1: A function f from a set with k +
1 elements to a set with k elements is not
one-to-one.
Proof: Use the pigeonhole principle.
Create a box for each element y in the
codomain of f .
Put in the box for y all of the elements x from

Because there are k + 1 elements and only k


the domain such that f(x) = y.

boxes, at least one box has two or more


elements.
Hence, f can’t be one-to-one.
Pigeonhole Principle
In a group of 367 people, there must be two
people with the same birthday
As there are 366 possible birthdays

In a group of 27 English words, at least two


words must start with the same letter
As there are only 26 letters
The Generalized Pigeonhole Principle
The Generalized Pigeonhole Principle: If

is at least one box containing at least ⌈N/k⌉


N objects are placed into k boxes, then there

objects.

Example: Among 100 people there are at


least ⌈100/12⌉ = 9 who were born in the
same month.

You might also like