You are on page 1of 173

Discrete Mathematics

Set Theory, Functions, Counting


Set Theory
• Basic Concepts of Set Theory: Definitions
• Inclusion and Equality of Sets
• Cartesian product
• The Power Set
• Some operations on Sets
• Venn Diagrams
• Some Basic Set Identities
Basic Concepts of Set Theory: Notations

• Intuitively, set means a collection of objects of any


sort.
• Example:
• The set of all Canadians.
• A pair of shoes.
• A bouquet of flowers.
• A flock of sheep.
Basic Concepts of Set Theory: Notations
• A set is a collection of objects which share some
common property.
• A set of real numbers.
• Any object belonging to a set is called member
or an element of that set.
• A set is said to be well – defined if it is possible
to determine, whether any given object is a
member of the set.
Basic Concepts of Set Theory: Notations
• If an element p belongs to set A, it is represented as
• p𝜖𝐴
• p is an element of the set A or p belongs to set A.
• Example:
• {1, 3, 4}
• A set consisting of elements 1, 3 and 4.
Basic Concepts of Set Theory: Notations
• A = { 1, 3, 4}
1∈A
3∈A
4∈A
2∉𝐴
Basic Concepts of Set Theory: Notations
• In general, a set can be defined by a predicate.
• S1 = {x | x is an odd positive integer}
• S2 = {x | x is a province of Canada}
• S3 = {x | x is a river}
• S4 = {x | x = a or x = b}
• {x | P(x) }
• If an element b belongs to this set if P(b) is true.
Basic Concepts of Set Theory: Notations
• S1 = {1, 3, 5,…}
• S2 = {2, 4, 6,…, 18}

• A set is finite if it contains a finite number of


distinguishable elements; otherwise, a set is infinite.
Basic Concepts of Set Theory: Notations
• S = { a, {1,2}, p, {q}}
• The set {q} is an element of S.
• q is an element of {q}.
• q is not an element of S.
Basic Concepts of Set Theory: Inclusion and
Equality of sets
• Let A and B be any two sets. If every element of A is
an element of B, then A is a subset of B, or A is said to
be included in B, or B includes A.
• It is symbolically denoted by 𝐴 ⊆ 𝐵 .
Basic Concepts of Set Theory: Inclusion and
Equality of sets
• A = { 1, 2, 3}
• B = { 1, 2}
• C = {1, 3}
• D = {3}

•B ⊆ 𝐴 {1, 2} ⊆ {1,2,3}
•C ⊆ 𝐴 {1, 3} ⊆ {1, 2, 3}
•D ⊆ 𝐴 {3} ⊆ {1,2,3}
Basic Concepts of Set Theory: Inclusion and
Equality of sets
• A = {{1},2, 3}

• {1} ∈ A
• {{1}, 2} ⊆ 𝐴
• {{1}} ⊆ 𝐴
• {2, 3} ⊆ 𝐴
Basic Concepts of Set Theory: Inclusion and
Equality of sets
• Two sets A and B are said to be equal iff A ⊆
𝐵 𝑎𝑛𝑑 B ⊆ 𝐴.
• Example:
• A = {1,2,4} B = {1, 2, 2, 4}
•A = B
• A = {1, 4, 2} B = {1, 2 , 4}
•A = B
• P = {{1,2}, 4} Q = {1, 2, 4}
•P ≠ Q
Basic Concepts of Set Theory: Inclusion and
Equality of sets
• A set A is called a proper subset of set B if A ⊆ 𝐵 and
A ≠ 𝐵.
• It is denoted as A ⊂ 𝐵.

• A = { 1, 2} B = { 1, 2, 3, 4}
•A ⊂ 𝐵
Basic Concepts of Set Theory: Inclusion and
Equality of sets
• A set is called a universal set if it includes every set
under discussion.
• A universal set is denoted by E.
Basic Concepts of Set Theory: Inclusion and
Equality of sets
• A set which does not contain any element is called an
empty set or null set.
• It is denoted by ∅.
Set Theory
• N = {0, 1, 2, 3,...}, the set of natural numbers
• Z = {..., −2, −1, 0, 1, 2,...}, the set of integers
• Z+ = {1, 2, 3,...}, the set of positive integers
• Q = {p/q | p ∈ Z, q ∈ Z, and q ≠ 0}, the set of rational
numbers
• R, the set of real numbers
• R+, the set of positive real numbers
• C, the set of complex numbers
The notation for intervals of real numbers.
• When a and b are real numbers with a<b, we write
• [a, b]={x | a ≤ x ≤ b}
• [a, b) = {x | a ≤ x < b}
• (a, b]={x | a < x ≤ b}
• (a,b) = {x|a<x<b}
• [a, b] is called the closed interval from a to b and (a, b)
is called the open interval from a to b.
Example
• The set {N, Z, Q, R} is a set containing four elements, each of which is
a set.
• The four elements of this set are
• N, the set of natural numbers;
• Z, the set of integers;
• Q, the set of rational numbers; and
• R, the set of real numbers.
Empty Set
• There is a special set that has no elements. This set is
called the empty set, or null set, and is denoted by ∅.
• The empty set can also be denoted by { } (that is, we
represent the empty set with a pair of braces that
encloses all the elements in this set). Often, a set of
elements with certain properties turns out to be the
null set.
• For instance, the set of all positive integers that are
greater than their squares is the null set. A set with
one element is called a singleton set.
Singleton Set
• A set with one element is called a singleton set.
• A common error is to confuse the empty set ∅ with
the set {∅}, which is a singleton set.
• A useful analogy for remembering this difference is to
think of folders in a computer file system. The empty
set can be thought of as an empty folder and the set
consisting of just the empty set can be thought of as a
folder with exactly one folder inside, namely, the
empty folder.
Venn Diagrams
• Sets can be represented graphically using Venn diagrams, named after
the English mathematician John Venn, who introduced their use in
1881.
• In Venn diagrams the universal set U, which contains all the objects
under consideration, is represented by a rectangle. (Note that the
universal set varies depending on which objects are of interest.)
• Inside this rectangle, circles or other geometrical figures are used to
represent sets.
• Sometimes points are used to represent the particular elements of
the set.
• Venn diagrams are often used to indicate the relationships between
sets.
Example
• Draw a Venn diagram that represents
V, the set of vowels in the English
alphabet.
• We draw a rectangle to indicate
the universal set U, which is the
set of the 26 letters of the English
alphabet.
• Inside this rectangle we draw a
circle to represent V . Inside this
circle we indicate the elements of
V with points
Subset
• The set A is a subset of B if and only if
every element of A is also an element of B.
• We use the notation A ⊆ B to indicate that
A is a subset of the set B.
• We see that A ⊆ B if and only if the
quantification ∀x(x ∈ A → x ∈ B) is true.
• Note that to show that A is not a subset of
B we need only find one element x ∈ A
with x ∉ B.
• Showing that A is a Subset of B
• To show that A ⊆ B, show that if x belongs to A then x also belongs to B.
• Showing that A is Not a Subset of B
• To show that A ⊆ B, find a single x ∈ A such that x ∉ B.
The Size of the Set
• Let S be a set. If there are exactly n distinct elements in S where n is a
nonnegative integer, we say that S is a finite set and that n is the
cardinality of S. The cardinality of S is denoted by |S|.
• Example:
• Let A be the set of odd positive integers less than 10.
• Then |A| = 5.
Example
• Let S be the set of letters in the English alphabet.
Example
• Let S be the set of letters in the English alphabet.
• Then |S| = 26.
Power Set
• Given a set S, the power set of S is the set of all
subsets of the set S. The power set of S is denoted by
P(S).
• What is the power set of the set {0, 1, 2}?
• P({0, 1, 2}) = {∅,{0},{1},{2},{0, 1},{0, 2},{1, 2},{0, 1,
2}}.
• Note that the empty set and the set itself are
members of this set of subsets.
Example
• What is the power set of the empty set? What is the power set of the
set {∅}?
Example
• What is the power set of the empty set? What is the power set of the
set {∅}?

• The empty set has exactly one subset, namely, itself.


• P(∅) = {∅}.
• The set {∅} has exactly two subsets, namely, ∅ and the set {∅} itself.
• Therefore, P({∅}) = {∅,{∅}}.
Power Set
• If a set has n elements, then its power set has 2n elements.
Cartesian Products
• The order of elements in a collection is often important. Because sets
are unordered, a different structure is needed to represent ordered
collections. This is provided by ordered n-tuples.
• The ordered n-tuple (a1, a2,...,an) is the ordered collection that has a1
as its first element, a2 as its second element,..., and an as its nth
element.
Cartesian Products
• Two ordered n-tuples are equal if and only if each corresponding pair
of their elements is equal.
• (a1, a2,...,an) = (b1, b2,...,bn) if and only if ai = bi, for i = 1, 2,...,n. In
particular, ordered 2-tuples are called ordered pairs.
• The ordered pairs (a, b) and (c, d) are equal if and only if a = c and b =
d. Note that (a, b) and (b, a) are not equal unless a = b.
Cartesian Products
• Let A and B be sets. The Cartesian product of A and B,
denoted by A × B, is the set of all ordered pairs (a, b),
where a ∈ A and b ∈ B.

• A × B = {(a, b) | a ∈ A ∧ b ∈ B}.
Example
• What is the Cartesian product of A = {1, 2} and B
= {a, b, c}?

• The Cartesian product A × B is

• A × B = {(1, a), (1, b), (1, c), (2, a), (2, b), (2, c)}.
Example
• Show that the Cartesian product B × A is not equal to the
Cartesian product A × B, where A = {1, 2} and B = {a, b, c}?

• The Cartesian product B × A is


• B × A = {(a, 1), (a, 2), (b, 1), (b, 2), (c, 1), (c, 2)}.
• This is not equal to A × B
Cartesian product of more than two sets
• The Cartesian product of the sets A1, A2,...,An, denoted by A1 × A2 ×···×
An, is the set of ordered n-tuples (a1, a2,...,an), where ai belongs to Ai
for i = 1, 2,...,n. In other words, A1 × A2 ×···× An = {(a1, a2,...,an) | ai ∈ Ai
for i = 1, 2,...,n}.
Example
• What is the Cartesian product A × B × C, where A
= {0, 1}, B = {1, 2}, and C = {0, 1, 2} ?

•A × B × C =
{(0, 1, 0), (0, 1, 1), (0, 1, 2), (0, 2, 0), (0, 2, 1), (0, 2,
2), (1, 1, 0), (1, 1, 1), (1, 1, 2), (1, 2, 0), (1, 2, 1), (1,
2, 2)}.
Example
• A = {1, 2}. What is A X A?
Example
• A = {1, 2}. What is A X A?

• A X A = {1,2} X {1,2}

• {(1, 1), (1, 2), (2, 1), (2, 2)}


Examples
• Give the power sets of {a, b} and {1, 2, 3}.
• {x|x is the square of an integer and x<100}
• {-3,-2,-1,0,1,2,3}
• A = {1,2,3} and B = {4, 5, 6}
• A X B?
• B X A?
• A = {a,b,c,d} and B = {y,z}
• AXB?
• Power sets of A and B.
Set
Operations
• Let A and B be sets. The
union of the sets A and B,
denoted by A ∪ B, is the set
that contains those elements
that are either in A or in B, or
in both.
• An element x belongs to the
union of the sets A and B if
and only if x belongs to A or
x belongs to B.
• A ∪ B = {x | x ∈ A ∨ x ∈ B}.
Set Operations
• Example:
• The union of the sets {1, 3, 5} and {1, 2, 3}.
• {1, 3, 5}∪{1, 2, 3}={1, 2, 3, 5}.
Example
• Union of sets A = {1,5,9} and B = {2,4,6}
• A ∪ B = { 1,2,4,5,6,9}
Set
Operations
• Let A and B be sets. The
intersection of the sets A
and B, denoted by A ∩ B, is
the set containing those
elements in both A and B.
• An element x belongs to the
intersection of the sets A
and B if and only if x belongs
to A and x belongs to B.
• A ∩ B = {x | x ∈ A ∧ x ∈ B}.
Example
• The intersection of the sets {1, 3, 5} and {1, 2, 3} is,
• {1, 3, 5}∩{1, 2, 3}={1, 3}.
Example
• The intersection of the sets {2,4,6} and {1, 2, 3} is,
• {2,4,6}∩{1, 2, 3}={2}.
Set Operations
• Two sets are called disjoint if their intersection is the empty set.
• Let A = {1, 3, 5, 7, 9} and B = {2, 4, 6, 8, 10}. Because A ∩ B = ∅, A and
B are disjoint.
Example
• Let A = {1,2,3} and B = {4, 5, 6}.
• A ∩ B = ∅, A and B are disjoint.
Set Operations
• Let A and B be sets. The difference of
A and B, denoted by A − B, is the set
containing those elements that are in
A but not in B. The difference of A and
B is also called the complement of B
with respect to A.
• An element x belongs to the difference
of A and B if and only if x ∈ A and x ∉
B.
• A − B = {x | x ∈ A ∧ x ∉ B}.
Example
• The difference of {1, 3, 5} and {1, 2, 3} is the set {5}; that is, {1, 3,
5}−{1, 2, 3}={5}.
• This is different from the difference of {1, 2, 3} and {1, 3, 5}, which is
the set {2}.
Example
• The difference of {1, 2, 3} and {1, 3, 5} is {2}.
Set Operations
• Let U be the universal set. The
complement of the set A, denoted by
Ā, is the complement of A with respect
to U. Therefore, the complement of
the set A is U − A.
• An element belongs to Ā if and only if
x ∉ A.
• Ā = {x ∈ U | x ∉ A}.
Example
• Let A be the set of positive integers greater than 10 (with universal
set the set of all positive integers).
• Ā = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}.
Example
• Let A = {a, e, i, o, u} (where the universal set is the set of letters of the
English alphabet). Find Ā.
Example
• Let A = {a, e, i, o, u} (where the universal set is the set of letters of the
English alphabet). Ā = {b, c, d, f, g, h, j, k, l, m, n, p, q, r, s, t, v,w, x, y,z}.
Examples
• A = { 1,2,3, 5,6,7}
• B = {1,2,7,8,9}
• Calculate set operations on set A and B.

• Give the power sets of {a, b} and {1, 2, 3}.


• {x|x is the square of an integer and x<100}
• {-3,-2,-1,0,1,2,3}
Set Identities
• Identity laws
• A ∪∅= A
•A ∩ U = A
Set Identities
• Domination laws
•A∪U=U
• A ∩∅=∅
Set Identities
• Idempotent laws
•A∩A=A
•A∪A=A
Set Identities
• Complementation law
Set Identities
• Commutative laws
•A∪B=B∪A
•A∩B=B∩A
Set Identities
• Associative laws
• A ∪ (B ∪ C) = (A ∪ B) ∪ C
• A ∩ (B ∩ C) = (A ∩ B) ∩ C
Set Identities
• Distributive laws
• A ∪ (B ∩ C) = (A ∪ B) ∩ (A ∪ C)
• A ∩ (B ∪ C) = (A ∩ B) ∪ (A ∩ C)
Set Identities
• De Morgan’s laws
Set Identities
• Absorption laws
• A ∪ (A ∩ B) = A
• A ∩ (A ∪ B) = A
Set Identities
• Complement laws
Example
Example

De Morgan Law

A∪B=B∪A
A∩B=B∩A
Example
Generalized
Unions
•A∪B∪C
• It contains those
elements that are
in all of A, B, and
C.
Generalized
Intersections
•A∩B∩C
• It contains those
elements that are
in at least one of
the sets A, B, and
C,
Example
• Let A = {0, 2, 4, 6, 8}, B = {0, 1, 2, 3, 4}, and C = {0, 3, 6, 9}. What are A
∪ B ∪ C and A ∩ B ∩ C?

• The set A ∪ B ∪ C contains those elements in at least one of A, B, and


C.
• Hence, A ∪ B ∪ C = {0, 1, 2, 3, 4, 6, 8, 9}.

• The set A ∩ B ∩ C contains those elements in all three of A, B, and C.


• Thus, A ∩ B ∩ C = {0}.
Unions of an arbitrary number of sets
• The union of a collection of sets is the set that contains those
elements that are members of at least one set in the collection.
Intersections of an arbitrary number of sets
• The intersection of a collection of sets is the set that contains those
elements that are members of all the sets in the collection.
Example
• A = {1,3,5,7} B = {2,4,6,8} C ={1,3,6,8}
What are A ∪ B ∪ C and A ∩ B ∩ C?
Example
Example
Example
• To see that the union of these sets is the set of
positive integers, note that every positive integer n is
in at least one of the sets, because it belongs to An =
{1, 2,...,n}, and every element of the sets in the union
is a positive integer.
• To see that the intersection of these sets is the set {1},
note that the only element that belongs to all the sets
A1, A2,... is 1. To see this note that A1 = {1} and 1 ∈ Ai
for i = 1, 2,....
Functions
• For example, suppose that
each student in a discrete
mathematics class is
assigned a letter grade from
the set {A, B, C, D, F}. And
suppose that the grades are
A for Adams, C for Chou, B
for Goodfriend, A for
Rodriguez, and F for Stevens.
This assignment of grades is
illustrated in Figure.
Functions
• Let A and B be nonempty sets. A function f from A to B is an
assignment of exactly one element of B to each element of A. We
write f (a) = b if b is the unique element of B assigned by the function
f to the element a of A. If f is a function from A to B, we write f : A →
B
• A function f : A → B can also be defined in terms of a relation from A
to B.
• A relation from A to B that contains one, and only one, ordered pair
(a, b) for every element a ∈ A, defines a function f from A to B.
• This function is defined by the assignment f (a) = b, where (a, b) is the
unique ordered pair in the relation that has a as its first element.
• If f is a function from A to B, we say that A is the domain of f and B is
the codomain of f.
• If f (a) = b, we say that b is the image of a and a is a preimage of b.
• The range, or image, of f is the set of all images of elements of A.
Also, if f is a function from A to B, we say that f maps A to B.
Example
• What are the domain, codomain, and range of the function that
assigns grades to students.
• Let G be the function that assigns a grade to a student in our discrete
mathematics class. Note that G(Adams) = A, for instance. The domain
of G is the set {Adams, Chou, Goodfriend, Rodriguez, Stevens}, and
the codomain is the set {A, B, C, D, F}. The range of G is the set {A, B,
C, F}, because each grade except D is assigned to some student.
Example
• Let f : Z → Z assign the square of an integer to this integer.
• Then, f (x) = x2, where the domain of f is the set of all integers, the
codomain of f is the set of all integers, and the range of f is the set of
all integers that are perfect squares, namely, {0, 1, 4, 9,...}.
Example
• Identity function
• Let A be a non-empty set. The function f ∶ A → A define by f(x) = x, ∀x
∈ A is called an identity function on A.
• This function maps any element of A onto itself. For this function, the
range is entire co-domain.
Example
• Constant function
• A function whose range is a singleton set is called a constant function.
• Thus, a function f ∶ A → B, f(x) = c, ∀x ∈ A where c is a fixed element
of B, is called a constant function
Example
• Even function
• A function f ∶ A → B is said to be an even function if f(−x) = f(x), ∀x ∈
A.
• f ∶ R→R, f(x) = x2 is an even function.
Example
• Odd function
• A function f ∶ A → B is said to be an odd function if f(−x) = −f(x),∀x ∈
A.
• f ∶ R→R, f(x) = x3 is an odd function.
Functions
• Two real-valued functions or two integer valued functions with the
same domain can be added, as well as multiplied
• Let f1 and f2 be functions from A to R. Then f1 + f2 and f1 f2 are also
functions from A to R defined for all x ∈ A by
• (f1 + f2)(x) = f1(x) + f2(x),
• (f1 f2)(x) = f1(x) f2(x).
Example
• Let f1 and f2 be functions from R to R such that f1(x) = x2 and f2(x) = x −
x2. What are the functions f1 + f2 and f1 f2?
• Solution: From the definition of the sum and product of functions, it
follows that
• (f1 + f2)(x) = f1(x) + f2(x) = x2 + (x − x2) = x
• (f1 f2)(x) = x2(x − x2) = x3 − x4.
One – to – One Functions
• Some functions never assign the same value to two different domain
elements. These functions are said to be one-to-one.
• A function f is said to be one-to-one, or an injunction, if and only if
f(a) = f(b) implies that a = b for all a and b in the domain of f. A
function is said to be injective if it is one-to-one.
Example
• Determine whether the
function f from {a, b, c, d}
to {1, 2, 3, 4, 5} with f (a) =
4, f (b) = 5, f (c) = 1, and f
(d) = 3 is one-to-one.
• The function f is one-to-
one because f takes on
different values at the
four elements of its
domain. This is illustrated
in Figure.
Example
• Determine whether the function f (x) = x2 from the set of integers to
the set of integers is one-to-one.
• Solution: The function f (x) = x2 is not one-to-one because, for
instance, f (1) = f (−1) = 1, but 1 ≠ −1.
Example
• Determine whether the function f (x) = x + 1 from the set of real
numbers to itself is one-to-one.
• Solution: The function f (x) = x + 1 is a one-to-one function. To
demonstrate this, note that x + 1 ≠ y + 1 when x ≠ y.
Onto Function
• For some functions the range and the codomain are equal. That is,
every member of the codomain is the image of some element of the
domain. Functions with this property are called onto functions.
• A function f from A to B is called onto, or a surjection, if and only if for
every element b ∈ B there is an element a ∈ A with f (a) = b. A
function f is called surjective if it is onto.
Example
• Let f be the function from {a, b, c, d} to {1, 2, 3} defined
by f (a) = 3, f (b) = 2, f (c) = 1, and f (d) = 3. Is f an onto
function?
• Solution: Because all three elements of the codomain
are images of elements in the domain, we see that f is
onto. This is illustrated in Figure. Note that if the
codomain were {1, 2, 3, 4}, then f would not be onto.
Example
• Is the function f (x) = x + 1 from the set of integers to the set of
integers onto?
• This function is onto, because for every integer y there is an integer x
such that f (x) = y. To see this, note that f (x) = y if and only if x + 1 = y,
which holds if and only if x = y − 1.
Bijective Function
• The function f is a one-to-one correspondence, or a bijection, if it is
both one-to-one and onto. We also say that such a function is
bijective.
Example
• Let f be the function from {a, b, c, d} to {1, 2, 3, 4} with f (a) = 4, f (b) =
2, f (c) = 1, and f (d) = 3. Is f a bijection?
• The function f is one-to-one and onto. It is one-to-one because no
two values in the domain are assigned the same function value. It is
onto because all four elements of the codomain are images of
elements in the domain. Hence, f is a bijection.
• Suppose that f : A → B.
• To show that f is injective
• Show that if f (x) = f (y) for arbitrary x, y ∈ A with x = y, then x = y.
• To show that f is not injective
• Find particular elements x, y ∈ A such that x = y and f (x) = f (y).
• To show that f is surjective
• Consider an arbitrary element y ∈ B and find an element x ∈ A such that f (x)
= y.
• To show that f is not surjective
• Find a particular y ∈ B such that f (x) ≠ y for all x ∈ A
Inverse Functions
• Now consider a one-to-one correspondence f from the set A to the
set B.
• Because f is an onto function, every element of B is the image of
some element in A.
• Furthermore, because f is also a one-to-one function, every element
of B is the image of a unique element of A.
• Consequently, we can define a new function from B to A that reverses
the correspondence given by f .
Inverse Functions
• Let f be a one-to-one correspondence from the set A to the set B. The
inverse function of f is the function that assigns to an element b
belonging to B the unique element a in A such that f (a) = b. The
inverse function of f is denoted by f −1.
• Hence, f −1(b) = a when f (a) = b.
Inverse Functions
• If a function f is not a one-to-one correspondence, we cannot define
an inverse function of f .
• When f is not a one-to-one correspondence, either it is not one-to-
one, or it is not onto.
• If f is not one-to-one, some element b in the codomain is the image of
more than one element in the domain.
• If f is not onto, for some element b in the codomain, no element a in
the domain exists for which f (a) = b.
Inverse Functions
• Consequently, if f is not a one-to-one correspondence, we cannot
assign to each element b in the codomain a unique element a in the
domain such that f (a) = b (because for some b there is either more
than one such a or no such a).
• A one-to-one correspondence is called invertible because we can
define an inverse of this function.
• A function is not invertible if it is not a one-to-one correspondence,
because the inverse of such a function does not exist.
Example
• Let f be the function from {a, b, c} to {1, 2, 3} such that f (a) = 2, f (b) =
3, and f (c) = 1. Is f invertible, and if it is, what is its inverse?
• Solution:
• The function f is invertible because it is a one-to-one correspondence.
• The inverse function f−1 reverses the correspondence given by f , so
f−1(1) = c, f −1(2) = a, and f −1(3) = b.
Example
• Let f : Z → Z be such that f (x) = x + 1. Is f invertible, and if it is, what is
its inverse?
• Solution:
• The function f has an inverse because it is a one-to-one
correspondence.
• To reverse the correspondence, suppose that y is the image of x, so
that y = x + 1.
• Then x = y − 1. This means that y − 1 is the unique element of Z that is
sent to y by f . Consequently, f −1 (y) = y − 1.
Example
• Let f be the function from R to R with f (x) = x2. Is f invertible?
• Solution:
• Because f (−2) = f (2) = 4, f is not one-to-one. If an inverse function
were defined, it would have to assign two elements to 4. Hence, f is
not invertible.
• (Note we can also show that f is not invertible because it is not onto.)
Example
• Show that if we restrict the function f(x) = x2 from the set of all
nonnegative real numbers to the set of all nonnegative real numbers,
then f is invertible.
• Solution: The function f(x) = x2 from the set of nonnegative real
numbers to the set of nonnegative real numbers is one-to-one. To see
this, note that if f (x) = f (y), then x2 = y2, so x2 − y2 = (x + y)(x − y) = 0.
• This means that x + y = 0 or x − y = 0, so x = −y or x = y.
• Because both x and y are nonnegative, we must have x = y.
• So, this function is one-to-one.
Example
• Furthermore, f(x) = x2 is onto when the codomain is the set of all
nonnegative real numbers, because each nonnegative real number
has a square root.
• That is, if y is a nonnegative real number, there exists a nonnegative
real number x such that x = √𝑦, which means that x2 = y.
• Because the function f(x) = x2 from the set of nonnegative real
numbers to the set of nonnegative real numbers is one-to-one and
onto, it is invertible. Its inverse is given by the rule f−1(y) = √𝑦.
Compositions of Functions
• Let g be a function from the set A to the set B and let f be a function
from the set B to the set C. (g: A→B, f: B→C)
• The composition of the functions f and g, denoted for all a ∈ A by f ◦
g, is defined by (f ◦ g)(a) = f (g(a)).
Compositions of Functions
• f ◦ g is the function that assigns to the element a of A the element
assigned by f to g(a).
• That is, to find (f ◦ g)(a) we first apply the function g to a to obtain g(a)
and then we apply the function f to the result g(a) to obtain (f ◦ g)(a) =
f (g(a)).
• Note that the composition f ◦ g cannot be defined unless the range of
g is a subset of the domain of f.
• Consider functions f ∶ A → B and g ∶ C → D. Then, we may define g ∘ f
∶ A → D, called the composition of f & g , as follows.
• ( g ∘ f )(x) = g(f(x)), x ∈ A , where B ⊆ C
Composition of Functions
• Let f ∶ A → B, then f ∘ IA = f = IB ∘ f.
• f ∘ g ≠ g ∘ f. (the commutative law does not hold for the composition
of functions)
• Let the function f ∶ A → B and g ∶ B → C, then
• If f and g are one to one functions, then g ∘ f is also one to one function.
• If f and g are onto functions, then g ∘ f is also onto function.
• ( g ∘ f )−1 (x) = ( f −1 ∘ g −1 )(x).
Example
• Let g be the function from the set {a, b, c} to itself such that g(a) = b,
g(b) = c, and g(c) = a. Let f be the function from the set {a, b, c} to the set
{1, 2, 3} such that f (a) = 3, f (b) = 2, and f (c) = 1.
• What is the composition of f and g, and what is the composition of g
and f ?
• Solution:
• The composition f ◦ g is defined by (f ◦ g)(a) = f (g(a)) = f (b) = 2, (f ◦ g) (b)
= f (g(b)) = f (c) = 1, and (f ◦ g)(c) = f (g(c)) = f (a) = 3.
• Note that g ◦ f is not defined, because the range of f is not a subset of
the domain of g.
Example
• Let f and g be the functions from the set of integers to the set of
integers defined by f (x) = 2x + 3 and g(x) = 3x + 2.
• What is the composition of f and g? What is the composition of g and
f?
• Solution:
• Both the compositions f ◦ g and g ◦ f are defined.
• (f ◦ g)(x) = f (g(x)) = f (3x + 2) = 2(3x + 2) + 3 = 6x + 7
• (g ◦ f )(x) = g(f (x)) = g(2x + 3) = 3(2x + 3) + 2 = 6x + 11.
Counting
• The Basics of Counting
• The Pigeonhole Principle
• Permutations and Combinations
• Binomial Coefficients
• Generalized Permutations and Combinations
• Generating Permutations and Combinations
The Basics of Counting
• Suppose that a password on a computer system consists of six, seven,
or eight characters.
• Each of these characters must be a digit or a letter of the alphabet.
Each password must contain at least one digit.
• How many such passwords are there?
• The techniques needed to answer this question and a wide variety of
other counting problems will be introduced here.
Basic Counting Principles
• THE PRODUCT RULE
• Suppose that a procedure can be broken down into a sequence of
two tasks.
• If there are n1 ways to do the first task and for each of these ways of
doing the first task, there are n2 ways to do the second task, then
there are n1n2 ways to do the procedure.
Example
• A new company with just two employees, Sanchez and Patel, rents a
floor of a building with 12 offices. How many ways are there to assign
different offices to these two employees?
• Solution: The procedure of assigning offices to these two employees
consists of assigning an office to Sanchez, which can be done in 12
ways, then assigning an office to Patel different from the office
assigned to Sanchez, which can be done in 11 ways. By the product
rule, there are 12 · 11 = 132 ways to assign offices to these two
employees.
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?
• Solution: The procedure of labeling a chair consists of two tasks,
namely, assigning to the seat one of the 26 uppercase English letters,
and then assigning to it one of the 100 possible integers.
• The product rule shows that there are 26 · 100 = 2600 different ways
that a chair can be labeled. Therefore, the largest number of chairs
that can be labeled differently is 2600.
Example
• How many two digits even numbers can be formed from the digits 1,
2, 3, 4, 9 if the digits can be repeated?
• Solution
• The unit’s place takes value 2 and 4
• ten’s place takes any of the 5 digits in 5 different ways as the digits
can be repeated.
• Therefore, by multiplication principle, the required number of two
digits even numbers is 5 × 2 = 10.
Example
• How many different bit strings of length seven are there?
• Solution: Each of the seven bits can be chosen in two ways, because
each bit is either 0 or 1.
• Therefore, the product rule shows there are a total of 27 = 128
different bit strings of length seven
Basic Counting Principles
• THE SUM RULE
• If a task can be done either in one of n1 ways or in one of n2 ways,
where none of the set of n1 ways is the same as any of the set of n2
ways, then there are n1 + n2 ways to do the task.
Example
• A student can choose a computer project from one of three lists. The
three lists contain 23, 15, and 19 possible projects, respectively. No
project is on more than one list. How many possible projects are
there to choose from?
• Solution: The student can choose a project by selecting a project from
the first list, the second list, or the third list. Because no project is on
more than one list, by the sum rule there are 23 + 15 + 19 = 57 ways
to choose a project
Basic Counting Principles
• THE SUBTRACTION RULE
• If a task can be done in either n1 ways or n2 ways, then the 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.
• The subtraction rule is also known as the principle of inclusion–
exclusion.
Basic Counting Principles
• Suppose that A1 and A2 are sets.
• Then, there are |A1| ways to select an element from A1 and
• |A2| ways to select an element from A2.
• The number of ways to select an element from A1 or from A2, that is, the
number of ways to select an element from their union, is the sum of the
number of ways to select an element from A1 and the number of ways to
select an element from A2, minus the number of ways to select an element
that is in both A1 and A2.
• Because there are |A1 ∪ A2| ways to select an element in either A1 or in
A2, and |A1 ∩ A2| ways to select an element common to both sets, we
have
• |A1 ∪ A2|=|A1|+|A2|−|A1 ∩ A2|
Example
• A computer company receives 350 applications from computer graduates
for a job planning a line of new Web servers. Suppose that 220 of these
applicants majored in computer science, 147 majored in business, and 51
majored both in computer science and in business. How many of these
applicants majored neither in computer science nor in business?
• Let A1 be the set of students who majored in computer science and A2 the
set of students who majored in business. Then A1 ∪ A2 is the set of
students who majored in computer science or business (or both), and A1 ∩
A2 is the set of students who majored both in computer science and in
business. By the subtraction rule the number of students who majored
either in computer science or in business (or both) equals
• |A1 ∪ A2|=|A1|+|A2|−|A1 ∩ A2| = 220 + 147 − 51 = 316.
Example
• We conclude that 350 − 316 = 34 of the applicants majored neither in
computer science nor in business.
Basic Counting Principles
• THE 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.
The Pigeonhole Principle
• Suppose that a flock of 20 pigeons flies into a set of 19 pigeonholes to
roost. Because there are 20 pigeons but only 19 pigeonholes, a least
one of these 19 pigeonholes must have at least two pigeons in it.
• To see why this is true, note that if each pigeonhole had at most one
pigeon in it, at most 19 pigeons, one per hole, could be
accommodated.
• This illustrates a general principle called the pigeonhole principle,
which states that if there are more pigeons than pigeonholes, then
there must be at least one pigeonhole with at least two pigeons in it
The Pigeonhole Principle
• THE PIGEONHOLE PRINCIPLE
• If k is a positive integer and k + 1 or more objects are placed into k
boxes, then there is at least one box containing two or more of the
objects
• We prove the pigeonhole principle using a proof by contraposition.
• Suppose that none of the k boxes contains more than one object.
Then the total number of objects would be at most k.
• This is a contradiction, because there are at least k + 1 objects.
The Pigeonhole Principle
• The pigeonhole principle is also called the Dirichlet drawer principle.
• A function f from a set with k + 1 or more elements to a set with k
elements is not one-to-one.
• Suppose that for each element y in the codomain of f we have a box
that contains all elements x of the domain of f such that f (x) = y.
Because the domain contains k + 1 or more elements and the
codomain contains only k elements, the pigeonhole principle tells us
that one of these boxes contains two or more elements x of the
domain. This means that f cannot be one-to-one
Example
• In any group of 27 English words, there must be at least two that
begin with the same letter, because there are 26 letters in the English
alphabet.
The Generalized Pigeonhole Principle
• THE GENERALIZED PIGEONHOLE PRINCIPLE
• If N objects are placed into k boxes, then there is at least one box
containing at least N/k objects.
The Generalized Pigeonhole Principle
• The pigeonhole principle states that there must be at least two
objects in the same box when there are more objects than boxes.
• However, even more can be said when the number of objects exceeds
a multiple of the number of boxes.
• For instance, among any set of 21 decimal digits there must be 3 that
are the same.
• This follows because when 21 objects are distributed into 10 boxes,
one box must have more than 2 objects.
Example
• Among 100 people there are at least 100/12 = 9 who were born in
the same month.
Factorial
• The continued product of first n natural numbers is called ‘n factorial’
and is denoted by n!.
• 4! = 4 x 3 x 2 x 1
=24
• 0! = 1.
• n! = n x (n-1)!
Permutations
• A permutation of a set of distinct objects is an ordered arrangement
of these objects.
• In permutation the order of arrangement is taken into account,
when the order is changed, a different permutation is obtained.
• The number of r-permutations of a set with n elements is denoted by
P (n, r).
Permutation
• Six arrangements can be made with three distinct objects a, b, c
taking two at a time are
• ab, ba, bc, cb, ac, ca
• By the product rule, it follows that P (3, 2) = 3 · 2 = 6
• Each of these arrangements is called a permutation.
Permutations
• Suppose that we are given ‘n’ distinct objects and wish to arrange ‘r’
of these objects in a line where 1 ≤ r ≤ n.
• Since there are ‘n’ ways of choosing the 1st object, after this is done
‘n − 1’ ways of choosing the 2nd object and finally n − (r − 1) ways of
choosing the rth object.
• P(n,r)=n (n−1) (n−2)………(n−(r−1))
• ( n (n−1) (n−2)………(n−(r−1))(n−r)(n−r−1)………3. 2.
1)/((n−r)(n−r−1)………3. 2. 1)
• n! /(n − r)!
• P(n, n) = n!
• P(n, 0) = 1
• Suppose that there are eight runners in a race. The winner receives a
gold medal, the second place finisher receives a silver medal, and the
third-place finisher receives a bronze medal. How many different
ways are there to award these medals, if all possible outcomes of the
race can occur and there are no ties?
• Solution:
• The number of different ways to award the medals is the number of
3-permutations of a set with eight elements.
• Hence, there are P(8, 3) = 8 · 7 · 6 = 336 possible ways to award the
medals.
• 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 number of possible paths between the cities is the
number of permutations of seven elements, because the first city is
determined, but the remaining seven can be ordered arbitrarily.
Consequently, there are 7! = 7 · 6 · 5 · 4 · 3 · 2 · 1 = 5040 ways for the
saleswoman to choose her tour.
Permutations
• Suppose that a set consists of ‘n’ objects of which n1 are of one type,
n2 are of second type, … , nk are of kth type.
• Here n = n1 + n2 + ⋯ + nk.
• Then the number of different permutations of the objects is

• 𝐧!/( 𝐧1 ! 𝐧2 ! … 𝐧𝐤 ! )
Permutation
• A number of different permutations of the letters of the word
JISSISSITTI is
• 11! / 1! 4! 4! 2! = 34650
Combination
• How many different committees of three students can be formed
from a group of four students?
• There are four ways to choose the three students for the committee,
where the order in which these students are chosen does not matter.
Combination
• Let S be the set {1, 2, 3, 4}.
• Then {1, 3, 4} is a 3-combination from S.
• Note that {4, 1, 3} is the same 3-combination as {1, 3, 4}, because the
order in which the elements of a set are listed does not matter.
Combinations
• 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 elements, where n is a
nonnegative integer and r is an integer with 0 ≤ r ≤ n, equals

n n!
C(n, r) = =
r r! n − r !
n n
• 0
= n
=1
n
• 1
=n
n 1
• r
= ∙ P(𝑛, 𝑟)
r!
n n n−1
• r
= × r−1
r
• The number of r-combinations with repetition that can be selected
from a set of n elements is 𝐧+𝒓−𝟏
𝐫
.
Example
• nCr = nCn−r

n! n! n!
• = = = nCr
n− n−r ! n−r ! n−n+r ! n−r ! r! n−r !
Example
• How many ways are there to select five players from a 10-member
tennis team to make a trip to a match at another school?
• Solution:
The number of such combinations is C(10, 5) = 10!/ 5! 5! = 252.
Example
• A group of 30 people have been trained as astronauts to go on the
first mission to Mars. How many ways are there to select a crew of six
people to go on this mission (assuming that all crew members have
the same job)?
• C(30, 6) = 30!/ 6! 24!

=30 · 29 · 28 · 27 · 26 · 25/ 6 · 5 · 4 · 3 · 2 · 1
= 593,775
Example
• How many poker hands of five cards can be dealt from a standard
deck of 52 cards?
• Solution: Because the order in which the five cards are dealt from a
deck of 52 cards does not matter, there are

C(52, 5) = 52!/5!47!
Example
• How many poker hands of five cards can be dealt from a standard
deck of 52 cards?
• Solution: Because the order in which the five cards are dealt from a
deck of 52 cards does not matter, there are

C(52, 5) = 52!/5!47!
= 52 · 51 · 50 · 49 · 48 / 5 · 4 · 3 · 2 · 1
= 2,598,960.
• Also, how many ways are there to select 47 cards from a standard
deck of 52 cards?

• C(52, 47) = 52! / 47!5!


Example
• Suppose that there are 9 faculty members in the mathematics
department and 11 in the computer science department. How many
ways are there to select a committee to develop a discrete
mathematics course at a school if the committee is to consist of three
faculty members from the mathematics department and four from
the computer science department?
• Solution:
• By the product rule, the answer is the product of the number of 3-
combinations of a set with 9 elements and the number of 4-
combinations of a set with 11 elements.
• The number of ways to select the committee is

• C(9, 3) · C(11, 4) = 9! / 3!6! · 11! / 4!7!


= 84 · 330
= 27,720
Generation of Permutations
• Scan the digits of a given permutation from left to right and note the
first consecutive pair (an-1 and an) such that an-1<an. Remember
position of an-1. Let m = n-1.
• Search the smallest digit among digits am+1, am+2,…,an that is larger
than am, call it X.
• Interchange am and X.
• Arrange digits am+1 to an in increasing order as am+1<am+2<an.
• Print a1,a2,…,an.
Example
• 1374652
• 1375246
Generating Combinations
• An r-combination can be represented by a sequence containing the
elements in the subset in increasing order.
• The r-combinations can be listed using lexicographic order on these
sequences.
• In this lexicographic ordering, the first r - combination is {1, 2,...,r − 1,
r} and the last r-combination is {n − r + 1, n − r + 2,...,n − 1, n}.
• First, locate the last element ai in the sequence such that ai ≠ n − r + i.
• Then, replace ai with ai + 1 and aj with ai + j − i + 1, for j = i + 1, i +
2,...,r.
• This produces the next larger r-combination in lexicographic order.
• Find the next larger 4-combination of the set {1, 2, 3, 4, 5, 6} after {1,
2, 5, 6}.
• Solution: The last term among the terms ai with a1 = 1, a2 = 2, a3 = 5,
and a4 = 6 such that ai ≠ 6 − 4 + i is a2 = 2.
• To obtain the next larger 4-combination, increment a2 by 1 to obtain
a2 = 3.
• Then set a3 = 3 + 1 = 4 and a4 = 3 + 2 = 5.
• Hence the next larger 4-combination is {1, 3, 4, 5}.
Binomial Coefficient
1 1 1
• x+𝑦 =x+y= 0
𝑥1 𝑦 0 + 1
𝑥 0 𝑦1
2 2 2 2
• x+𝑦 = 𝑥2 + 2xy + 𝑦2 = 0
𝑥2 𝑦0 + 1
𝑥1 𝑦1 + 2
𝑥0 𝑦2
3 3 3 3 3
• x+𝑦 = 𝑥 3 + 3𝑥 2 y + 3𝑥𝑦 2 + 𝑦 3 = 0
𝑥 3𝑦0 + 1
𝑥 2 𝑦1 + 2
𝑥1𝑦 2 + 3
𝑥0𝑦3

N
N
N N 0 N N−1 1 N N−2 2 N 0 N N N−𝑗
x+𝑦 = 𝑥 𝑦 + 𝑥 𝑦 + 𝑥 𝑦 + ⋯+ 𝑥 𝑦 =෍ 𝑥 𝑦𝑗
0 1 2 N 𝑗
j=0
BINOMIAL COEFFICIENT

𝐧 𝐧
=
𝒋 𝐧−𝒋
𝐧+𝟏 𝐧 𝐧
= +
𝐣+𝟏 𝒋 𝐣+𝟏

𝐧 𝐧
𝐈𝐟 = 𝐭𝐡𝐞𝐧 𝐞𝐢𝐭𝐡𝐞𝐫 𝐚 = 𝐛 𝐨𝐫 𝐚 + 𝐛 = 𝐧
𝒂 𝒃
BINOMIAL COEFFICIENT
Discrete Mathematics
• Reference Books:
• J. P. Tremblay and R. Manohar, Discrete Mathematical Structures with
Applications to Computer Science, Tata McGraw-Hill,1997.
• S. Lipschutz and M. L. Lipson, Schaum’s Outline of Theory and Problems of
Discrete Mathematics, 2nd Ed., Tata McGraw-Hill,1999.
• K. H. Rosen, Discrete Mathematics and its applications, Tata McGraw-Hill, 6th
Ed., 2007.
• David Liben-Nowell, Discrete Mathematics for Computer Science, Wiley
publication, July 2017.
• Eric Gossett, Discrete Mathematics with Proof, 2nd Edition,Wiley publication,
July 2009.

You might also like