The Basic Counting Principle
The Basic Counting Principle
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.
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|.
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.