Counting: With Question/Answer Animations
Counting: With Question/Answer Animations
Counting: With Question/Answer Animations
Chapter 6
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
Permutations and Combinations
Binomial Coefficients and Identities
Generalized Permutations and Combinations
Generating Permutations and Combinations (not yet
included in overheads)
The Basics of Counting
Section 6.1
Section Summary
The Product Rule
The Sum Rule
The Subtraction Rule
The Division 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.
How many different telephone numbers are possible under the old plan and the new plan?
By the product rule, there are 2|S| such bit strings, and therefore
2|S| subsets.
Product Rule in Terms of Sets
If A1, A2, … , Am are finite sets, then the number of
elements in the Cartesian product of these sets is the
product of the number of elements of each set.
The task of choosing an element in the Cartesian
product A1 ⨉ A2 ⨉ ∙∙∙ ⨉ Am is done by choosing an
element in A1, an element in A2 , …, and an element
in Am.
By the product rule, it follows that:
|A1 ⨉ A2 ⨉ ∙∙∙ ⨉ Am |= |A1| ∙ |A2| ∙ ∙∙∙ ∙ |Am|.
DNA and Genomes
A gene is a segment of a DNA molecule that encodes a particular protein
and the entirety of genetic information of an organism is called its genome.
DNA molecules consist of two strands of blocks known as nucleotides. Each
nucleotide is composed of bases: adenine (A), cytosine (C), guanine (G), or
thymine (T).
The DNA of bacteria has between 105 and 107 links (one of the four bases).
Mammals have between 108 and 1010 links. So, by the product rule there are
at least 4105 different sequences of bases in the DNA of bacteria and 4108
different sequences of bases in the DNA of mammals.
The human genome includes approximately 23,000 genes, each with 1,000
or more links.
Biologists, mathematicians, and computer scientists all work on
determining the DNA sequence (genome) of different organisms.
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 a university
committee. How many choices are there for this representative
if there are 37 members of the mathematics faculty and 83
mathematics majors and no one is both a faculty member and
a student.
Solution: By the sum rule it follows that there are
37 + 83 = 120 possible ways to pick a 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,
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:
Class A Addresses: used for the largest networks, a 0,followed by a 7-bit netid and a 24-
bit hostid.
Class B Addresses: used for the medium-sized networks, a 10,followed by a 14-bit netid
and a 16-bit hostid.
Class C Addresses: used for the smallest networks, a 110,followed by a 21-bit netid and a
8-bit hostid.
Neither Class D nor Class E addresses are assigned as the address of a computer on the
internet. Only Classes A, B, and C are available.
1111111 is not available as the netid of a Class A network.
Hostids consisting of all 0s and all 1s are not available in any network.
Counting Internet Addresses
Example: How many different IPv4 addresses are available for computers on the
internet?
Solution: Use both the sum and the product rule. Let x be the number of available
addresses, and let xA, xB, and xC denote the number of addresses for the respective
classes.
To find, xA: 27 − 1 = 127 netids. 224 − 2 = 16,777,214 hostids.
xA = 127∙ 16,777,214 = 2,130,706,178.
To find, xB: 214 = 16,384 netids. 216 − 2 = 16,534 hostids.
xB = 16,384 ∙ 16, 534 = 1,073,709,056.
To find, xC: 221 = 2,097,152 netids. 28 − 2 = 254 hostids.
xC = 2,097,152 ∙ 254 = 532,676,608.
Hence, the total number of available IPv4 addresses is
x = xA + xB + xC
= 2,130,706,178 + 1,073,709,056 + 532,676,608
= 3, 737,091,842. Not Enough Today !!
The newer IPv6 protocol solves the problem
of too few addresses.
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, then the total number
of ways to do the task is n1 + n2 minus the number of
ways to do the task that are common to the two
different ways.
Also known as, the principle of inclusion-exclusion:
Counting Bit Strings
Example: How many bit strings of length eight either
start with a 1 bit or end with the two bits 00?
Solution: Use the subtraction rule.
Number of bit strings of length eight
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 = 32
Hence, the number is 128 + 64 − 32 = 160.
Basic Counting Principles: Division Rule
Division Rule: There are n/d ways to do a task if it can be done using a procedure that can
be carried out in n ways, and for every way w, exactly d of the n ways correspond to way w.
Restated in terms of sets: If the finite set A is the union of n pairwise disjoint subsets each
with d elements, then n = |A|/d.
In terms of functions: If f is a function from A to B, where both are finite sets, and for every
value y ∈ B there are exactly d values x ∈ A such that f(x) = y, then |B| = |A|/d.
Example: How many ways are there to seat four people around a circular table, where two
seatings are considered the same when each person has the same left and right neighbor?
Solution: Number the seats around the table from 1 to 4 proceeding clockwise. There are
four ways to select the person for seat 1, 3 for seat 2, 2, for seat 3, and one way for seat 4.
Thus there are 4! = 24 ways to order the four people. But since two seatings are the same
when each person has the same left and right neighbor, for every choice for seat 1, we get
the same seating.
Therefore, by the division rule, there are 24/4 = 6 different seating arrangements.
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.
where the inequality ⌈N/k⌉ < ⌈N/k⌉ + 1 has been used. This is a
contradiction because there are a total of n objects.
Solution:
P(100,3) = 100 ∙ 99 ∙ 98 = 970,200
Solving Counting Problems by Counting
Permutations (continued)
Example: Suppose that a saleswoman has to visit eight
different cities. She must begin her trip in a specified city,
but she can visit the other seven cities in any order she
wishes. How many possible orders can the saleswoman use
when visiting these cities?
Solution: The first city is chosen, and the rest are ordered
arbitrarily. Hence the orders are:
7! = 7 ∙ 6 ∙ 5 ∙ 4 ∙ 3 ∙ 2 ∙ 1 = 5040
If she wants to find the tour with the shortest path that
visits all the cities, she must consider 5040 paths!
Solving Counting Problems by Counting
Permutations (continued)
Example: How many permutations of the letters
ABCDEFGH contain the string ABC ?
6! = 6 ∙ 5 ∙ 4 ∙ 3 ∙ 2 ∙ 1 = 720
Combinations
Definition: An r-combination of elements of a set is an
unordered selection of r elements from the set. Thus, an r-
combination is simply a subset of the set with r elements.
The number of r-combinations of a set with n distinct elements
is denoted by C(n, r). The notation is also used and is called
a binomial coefficient. (We will see the notation again in the
binomial theorem in Section 6.4.)
Example: Let S be the set {a, b, c, d}. Then {a, c, d} is a 3-
combination from S. It is the same as {d, c, a} since the order
listed does not matter.
C(4,2) = 6 because the 2-combinations of {a, b, c, d} are the six
subsets {a, b}, {a, c}, {a, d}, {b, c}, {b, d}, and {c, d}.
Combinations
Theorem 2: The number of r-combinations of a set
with n elements, where n ≥ r ≥ 0, equals
and
To obtain y3 , a y must be chosen from each of the sums. There is only one way to do this. So, the coefficient
of y3 is 1.
We have used a counting argument to show that (x + y)3 = x3 + 3x2y + 3x y2 + y3 .
Next we present the binomial theorem gives the coefficients of the terms in the expansion of (x + y)n .
Binomial Theorem
Binomial Theorem: Let x and y be variables, and n a
nonnegative integer. Then:
Pascal’s Identity
Pascal’s Identity: If n and k are integers with n ≥ k ≥ 0, then
There are
subsets of k elements that contain a, since there are subsets of k − 1
elements of S,
subsets of k elements of T that do not contain a, because there are subsets
of k elements of S.
See Exercise 19
Hence, for an algebraic
proof.
Pascal’s Triangle
The nth row in
the triangle
consists of the
binomial
coefficients ,
k = 0,1,….,n.
continued →
Combinations with Repetition
Some possible ways of
placing the five bills:
The number of ways to select five bills corresponds to the number of ways to
arrange six bars and five stars in a row.
This is the number of unordered selections of 5 objects from a set of 11.
Hence, there are
solutions.
Combinations with Repetition
Example: Suppose that a cookie shop has four
different kinds of cookies. How many different ways
can six cookies be chosen?
Solution: The number of ways to choose six cookies is
the number of 6-combinations of a set with four
elements. By Theorem 2