Discrete Structure
The Basics of Counting
A counting problem:
Each user on a computer system has a password,
which is six to eight characters long, where each
characters is an uppercase letter or a digit. Each
password must contain at least one digit. How many
possible passwords are there?
This section introduces
• a variety of other counting problems
• the basic techniques of counting.
Basic Counting Principles
The product rule:
A × B = {(a, b) | a ∈ A ∧ b ∈ B}
Product Rule: If A and B are finite sets, then: |A × B| = |A| · |B|.
Example
• The chairs of an auditorium are to be labeled with an uppercase English
letter followed by a positive integer not exceeding 100. What is the largest
number of chairs that can be labeled differently?
✓ 26 × 100 = 2600 ways to label chairs
• Counting Functions How many functions are there from a set with m
elements to a set with n elements?
✓ A function corresponds to a choice of one of the n elements in the codomain
for each of the m elements in the domain. Hence, by the product rule there
are n · n · ··· · n = nm functions from a set with m elements to one with n
elements. For example, there are 53 = 125 different functions from a set with
three elements to a set with five elements
Basic Counting Principles
The sum rule:
If A and B are finite sets that are disjoint (meaning A ∩ B = ∅),
then |A ∪ B| = |A| + |B|
Example
• A student can choose a computer project from one of three lists. The three
lists contain 23, 15 and 19 possible projects respectively. How many possible
projects are there to choose from?
✓ 23+15+19=57 projects.
• Counting Internet Addresses (Task)
➢ How many different IPv4 addresses are available for computers on the
Internet?
The Subtraction Rule (Inclusion–Exclusion for Two Sets)
|A ∪ B| = |A| + |B| − |A ∩ B|
Example
• How many bit strings of length eight either start with a 1 bit or end
with the two bits 00?
✓ 128 + 64 − 32 = 160
Tree Diagrams
Counting problems can be solved using tree diagrams.
A tree consists of a root, a number of branches leaving the root, and
possible additional branches leaving the endpoints of other branches.