CH 2
CH 2
CH 2
Discrete Mathematics
Chapter 02
Basic Structures
Dr. Ahmed Hagag
Faculty of Computers and Artificial Intelligence
Benha University
Fall 2020
Chapter 2: Basic Structures
• Sets.
• Functions.
• Sequences, and Summations.
• Matrices.
𝑆 = {𝑎, 𝑏, 𝑐, 𝑑}
ellipses (…)
Interval Notation
Closed interval [𝑎, 𝑏]
Open interval (𝑎, 𝑏)
[𝑎, 𝑏] = {𝑥 | 𝑎 ≤ 𝑥 ≤ 𝑏}
[𝑎, 𝑏) = {𝑥 | 𝑎 ≤ 𝑥 < 𝑏}
(𝑎, 𝑏] = {𝑥 | 𝑎 < 𝑥 ≤ 𝑏}
(𝑎, 𝑏) = {𝑥 | 𝑎 < 𝑥 < 𝑏}
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 { }
Cardinality
The cardinality is the number of distinct elements in 𝑆.
The cardinality of 𝑆 is denoted by 𝑆 .
Example1
𝑆 = {𝑎, 𝑏, 𝑐, 𝑑}
𝑆 =4
𝐴 = {1, 2, 3, 7, 9}
∅=
Example1
𝑆 = {𝑎, 𝑏, 𝑐, 𝑑}
𝑆 =4
𝐴 = {1, 2, 3, 7, 9}
𝐴 =5
∅=
|∅| = 0
Example2
𝑆 = 𝑎, 𝑏, 𝑐, 𝑑, 2
𝑆 =
𝐴 = {1, 2, 3, {2,3}, 9}
𝐴 =
{∅} = { }
∅ =
Example2
𝑆 = 𝑎, 𝑏, 𝑐, 𝑑, 2
𝑆 =5
𝐴 = {1, 2, 3, {2,3}, 9}
𝐴 =5
{∅} = { }
∅ =1
Infinite
A set is said to be infinite if it is not finite.
The set of positive integers is infinite.
𝑍 + = {1,2,3, … }
Subset
The set 𝐴 is said to be a subset of 𝐵 if and only if
every element of 𝐴 is also an element of 𝐵 .
𝐴 ⊆ 𝐵 ↔ ∀𝑥(𝑥 ∈ 𝐴 → 𝑥 ∈ 𝐵)
Subset
The set 𝐴 is said to be a subset of 𝐵 if and only if
every element of 𝐴 is also an element of 𝐵 .
Subset
Proper Subset
The set 𝐴 is a subset of the set 𝐵 but that 𝐴 ≠ 𝐵,
we write 𝐴 ⊂ 𝐵
and say that 𝐴 is a 𝐩𝐫𝐨𝐩𝐞𝐫 𝐬𝐮𝐛𝐬𝐞𝐭 of 𝐵.
𝐴 ⊂ 𝐵 ↔ ∀𝑥 𝑥 ∈ 𝐴 → 𝑥 ∈ 𝐵 ∧ ∃𝑥 𝑥 ∈ 𝐵 ∧ 𝑥 ∉ 𝐴
Example
For each of the following sets,
determine whether 3 is an element of that set.
1,2,3,4
1, 2, 3, 4
1,2, 1,3
Venn Diagram
𝐴 = 1,2,3,4,7
𝐵 = 0,3,5,7,9
𝐶 = 1,2
Venn Diagram
𝐴 = 1,2,3,4,7
𝐵 = 0,3,5,7,9
𝐶 = 1,2 1, 2
3, 7 0, 5, 9
Universal Set
Power Set
𝐓𝐡𝐞 𝐬𝐞𝐭 𝐨𝐟 𝐚𝐥𝐥 𝐬𝐮𝐛𝐬𝐞𝐭𝐬.
Power Set
𝐓𝐡𝐞 𝐬𝐞𝐭 𝐨𝐟 𝐚𝐥𝐥 𝐬𝐮𝐛𝐬𝐞𝐭𝐬.
𝑃 𝑆 = 2𝑆
= ∅, 1 , 2 , 3 , 1,2 , 1,3 , 2,3 , 1,2,3
@Ahmed Hagag BS102 Discrete Mathematics 25
Sets (19/24)
Example1
Example1
Example2
Example2
Cartesian Products
𝐴×𝐵 = 𝐴 ∗ 𝐵 =2∗3=6
𝐴×𝐵 = 𝐴 ∗ 𝐵 =2∗3=6
Find 𝐵 × 𝐴 ?
Example:
Union
Let 𝐴 and 𝐵 be sets. The union of the sets A and B ,
denoted by 𝐴 ∪ 𝐵, is the set that contains those
elements that are either in 𝐴 or in 𝐵 , or in both.
Union
Let 𝐴 and 𝐵 be sets. The union of the sets A and B ,
denoted by 𝐴 ∪ 𝐵, is the set that contains those
elements that are either in 𝐴 or in 𝐵 , or in both.
Union
Let 𝐴 and 𝐵 be sets. The union of the sets A and B ,
denoted by 𝐴 ∪ 𝐵, is the set that contains those
elements that are either in 𝐴 or in 𝐵 , or in both.
Intersection
Let 𝐴 and 𝐵 be sets. The intersection of the sets A and
B , denoted by 𝐴 ∩ 𝐵, is the set that contains those
elements that are in both 𝐴 and 𝐵.
Intersection
Let 𝐴 and 𝐵 be sets. The intersection of the sets A and
B , denoted by 𝐴 ∩ 𝐵, is the set that contains those
elements that are in both 𝐴 and 𝐵.
Intersection
Let 𝐴 and 𝐵 be sets. The intersection of the sets A and
B , denoted by 𝐴 ∩ 𝐵, is the set that contains those
elements that are in both 𝐴 and 𝐵.
Disjoint
𝐴∩𝐵 =∅
Difference
Difference
𝐴 = 1,3,5 , 𝐵 = 1,2,3
𝐴−𝐵= 5
Difference
Complement
Complement
𝑈 = 1,2,3,4,5 , 𝐴 = 1,3
𝐴ҧ = 2,4,5
Complement
Generalized Unions
Generalized Unions
Generalized Intersections
Generalized Intersections
Example1
Example1 – Answer
Example2
Example2 – Answer
Function
Let 𝐴 and 𝐵 be nonempty sets. A function 𝑓 from 𝐴 to
𝐵 is an assignment of exactly one element of 𝐵 to
each element of 𝐴.
Function
The Function 𝒇: 𝑨 → 𝑩
The Function 𝒇: 𝑨 → 𝑩
Domain: 𝐴
Co-Domain: 𝐵
𝑓 𝑎 =𝑏
𝑏 is the image of 𝑎
𝑎 is a preimage of 𝑏
The Function 𝒇: 𝑨 → 𝑩
1 Domain = 𝑎, 𝑏, 𝑐, 𝑑, 𝑒
𝑎 2
𝑏 3 Co-Domain = 1,2,3,4,5,6,7
𝑐 4 Range = {1,3,4,5,7}
𝑑 5
𝑒 6
7
𝑨 → 𝑩
Definition
Let 𝑓1 and 𝑓2 be functions from 𝐴 to R. Then 𝑓1 + 𝑓2 and 𝑓1 𝑓2 are also
functions from 𝐴 to R defined for all 𝑥 ∈ 𝐴 by
𝑓1 + 𝑓2 (𝑥) = 𝑓1 (𝑥) + 𝑓2 (𝑥),
(𝑓1 𝑓2 )(𝑥) = 𝑓1 𝑥 𝑓2 (𝑥).
Example
Let 𝑓1 and 𝑓2 be functions from R to R such that 𝑓1 (𝑥) = 𝑥 2 and
𝑓2 (𝑥) = 𝑥 − 𝑥 2. What are the functions 𝑓1 + 𝑓2 and 𝑓1 𝑓2 ?
𝑓1 + 𝑓2 𝑥 = 𝑓1 𝑥 + 𝑓2 𝑥 = 𝑥 2 + 𝑥 − 𝑥 2 = 𝑥,
𝑓1 𝑓2 𝑥 = 𝑓1 𝑥 𝑓2 𝑥 = 𝑥 2 𝑥 − 𝑥 2 = 𝑥 3 − 𝑥 4.
Definition
Let 𝑓 be a function from 𝐴 to 𝐵 and let 𝑆 be a subset of 𝐴.
The image of 𝑆 under the function 𝑓 is the subset of 𝐵 that consists of
the images of the elements of 𝑆.
We denote the image of 𝑆 by 𝑓(𝑆), so
𝑓 𝑆 = 𝑡 ∃𝑠 ∈ 𝑆 𝑡 = 𝑓 𝑠 .
or shortly {𝑓 𝑠 | 𝑠 ∈ 𝑆}.
Example
Let 𝐴 = {𝑎, 𝑏, 𝑐, 𝑑, 𝑒} and 𝐵 = {1, 2, 3, 4} with 𝑓(𝑎) = 2, 𝑓(𝑏) = 1,
𝑓(𝑐) = 4, 𝑓(𝑑) = 1, and 𝑓(𝑒) = 1.
𝑆 = 𝑏, 𝑐, 𝑑 ⊆ 𝐴
The image of the subset 𝑆 = {𝑏, 𝑐, 𝑑} is the set 𝑓(𝑆) = {1, 4}
1 𝑓 𝑎 =1
𝑎 2
𝑏 3 𝑓 𝑏 =3
𝑐 4 𝑓 𝑐 =7
𝑑 5
𝑒 6 𝑓 𝑑 =4
7 𝑓 𝑒 =5
𝑨 → 𝑩
1 𝑓 𝑎 =1
𝑎 2
𝑏 3 𝑓 𝑏 =1
𝑐 4 𝑓 𝑐 =7
𝑑 5
𝑒 6 𝑓 𝑑 =4
7 𝑓 𝑒 =5
𝑨 → 𝑩
𝑓 𝑎 =1
𝑎
1
𝑏 𝑓 𝑏 =1
2
𝑐
3 𝑓 𝑐 =4
𝑑
4
𝑒 𝑓 𝑑 =2
Co-Domain = 1,2,3,4
𝑓 𝑒 =3
𝑨 → 𝑩 Range = {1,2,3,4}
𝑓 𝑎 =1
𝑎
1
𝑏 𝑓 𝑏 =1
2
𝑐
3 𝑓 𝑐 =4
𝑑
4
𝑒 𝑓 𝑑 =1
Co-Domain = 1,2,3,4
𝑓 𝑒 =3
𝑨 → 𝑩 Range = {1,3,4}
𝑓 𝑎 =1
𝑎 1
𝑏 2 𝑓 𝑏 =3
𝑐 3
𝑓 𝑐 =5
𝑑 4
𝑒 5 𝑓 𝑑 =2
Co-Domain = 1,2,3,4,5
𝑓 𝑒 =4
𝑨 → 𝑩 Range = {1,2,3,4,5}
𝑓 𝑎 =1
𝑎 1
𝑏 2 𝑓 𝑏 =3 NOT one-to-one
𝑐 3 NOT onto
𝑓 𝑐 =5
𝑑 4
𝑒 5 𝑓 𝑑 =1
Co-Domain = 1,2,3,4,5
𝑓 𝑒 =4
𝑨 → 𝑩 Range = {1,3,4,5}
𝑓 𝑎 =1
𝑎 1
𝑏 2 𝑓 𝑏 =2 Onto
𝑐 3
𝑓 𝑐 =3 NOT one-to-one
𝑑 4
𝑒 𝑓 𝑑 =1
Co-Domain = 1,2,3,4
𝑓 𝑒 =4
𝑨 → 𝑩 Range = {1,2,3,4}
𝑓 𝑎 =1
𝑎 1
𝑏 2 𝑓 𝑏 =3 One-to-one
𝑐 3 NOT onto
𝑓 𝑐 =5
𝑑 4
5 𝑓 𝑑 =2
Co-Domain = 1,2,3,4,5
𝑨 → 𝑩 Range = {1,2,3,5}
Examples
𝑨 → 𝑩
Examples
One-to-one
NOT onto
𝑨 → 𝑩
Examples
𝑨 → 𝑩
Examples
NOT One-to-one
Onto
𝑨 → 𝑩
Examples
𝑨 → 𝑩
Examples
One-to-one
Onto
∴ bijection
𝑨 → 𝑩
Examples
𝑨 → 𝑩
Examples
NOT One-to-one
NOT Onto
𝑨 → 𝑩
Examples
𝑨 → 𝑩
Examples
NOT a function
from 𝑨 to 𝑩
𝑨 → 𝑩
Examples
Examples (Answer)
Determine whether the function 𝑓 𝑥 = 𝑥 + 1 from the set of integers
to the set of integers is one-to-one.
𝑓 𝑎 = 𝑎 + 1 and 𝑓 𝑏 = 𝑏 + 1
Examples
Determine whether the function 𝑓(𝑥) = 𝑥 2 from the set of integers to
the set of integers is one-to-one.
Examples (Answer)
Determine whether the function 𝑓(𝑥) = 𝑥 2 from the set of integers to
the set of integers is one-to-one.
𝑓 𝑎 = 𝑎2 and 𝑓 𝑏 = 𝑏2
𝑓 𝑥 is one−to−one (if 𝑓 𝑎 = 𝑓 𝑏 and a equal b then).
𝑎2 = 𝑏2
±𝑎 = ±𝑏
𝑎 may be not equal 𝑏
∴ 𝑓 𝑥 is NOT one−to−one
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 𝑓(𝑎) = 𝑏. The
inverse function of f is denoted by 𝒇−𝟏. Hence, 𝑓 −1 𝑏 = 𝑎 when
𝑓(𝑎) = 𝑏.
Inverse Functions
Invertible
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.
Invertible – Example
Let f be the function from 𝑎, 𝑏, 𝑐 to { 1 , 2, 3} such that 𝑓(𝑎) = 2,
𝑓(𝑏) = 3, and 𝑓(𝑐) = 1. Is 𝑓 invertible, and if it is, what is its
inverse?
Invertible – Example
Let f be the function from 𝑎, 𝑏, 𝑐 to {1, 2, 3} such that 𝑓(𝑎) = 2,
𝑓(𝑏) = 3, and 𝑓(𝑐) = 1. Is 𝑓 invertible, and if it is, what is its
inverse?
Answer:
The function 𝑓 is invertible because it is a one-to-one correspondence.
The inverse function 𝑓 −1 reverses the correspondence given by 𝑓, so
𝑓 −1 (1) = 𝑐, 𝑓 −1 (2) = 𝑎, and 𝑓 −1 (3) = 𝑏.
Composition Example 1
Let g be the function from the set {𝑎 , 𝑏, 𝑐} to itself such that g(a) = b,
g(b) = c, and g(c) = a. Let f be the function from the set {𝑎 , 𝑏 , 𝑐} 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 ?
Composition Example 1
Let g be the function from the set {𝑎 , 𝑏, 𝑐} to itself such that g(a) = b,
g(b) = c, and g(c) = a. Let f be the function from the set {𝑎 , 𝑏 , 𝑐} to
the set { 1 , 2 , 3 } such that f(a) = 3 , f(b) = 2 , and f(c) = 1.
Answer:
1) The composition of f and g (i.e., (f ∘ g))
(f ∘g)(a) = 2, (f ∘g)(b) = 1, (f ∘g)(c) = 3
2) The composition of g and f (i.e., (g ∘ f)) cannot be defined
because the range of f is NOT a subset of the domain of g .
Composition Example 2
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 ?
Composition Example 2
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.
Answer:
1) The composition of f and g (i.e., (f ∘g))
(f ∘g)(x) = 𝑓 𝑔 𝑥 = 2 3𝑥 + 2 + 3 = 6𝑥 + 7
Floor function 𝒚 = 𝒙
Ceiling function 𝒚 = 𝒙
Useful Properties
Examples
0.5 =
0.5 =
3 =
−0.5 =
−1.2 =
1.1 =
0.3 + 2 =
1.1 + 0.5 =
Examples-Answer
0.5 = 0
0.5 = 1
3 =3
−0.5 = − 0.5 = −1
−1.2 = −1
1.1 = 1
0.3 + 2 = 2
1.1 + 0.5 = 3
Definition
• A sequence is a set of things (usually numbers) that
are in order.
➢ For example, 1 , 2, 3, 5, 8 is a sequence with five terms and
1, 3, 9, 27, 81, . . . , 30, . . . is an infinite sequence.
Example
• Consider the sequence {𝑎𝑛 } , where
1
𝑎𝑛 =
𝑛
The list of the terms of this sequence, beginning with 𝑎1 ,
namely,
𝑎1 , 𝑎2 , 𝑎3 , 𝑎4 , … ,
Starts with
1 1 1
1, , , , …
2 3 4
@Ahmed Hagag BS102 Discrete Mathematics 113
Sequences (3/13)
Geometric
Geometric – Example1
𝑎𝑟 𝑛 , 𝑛 = 0,1,2, …
𝑎=1
𝑟 = −1
Geometric – Example2
𝑎𝑟 𝑛 , 𝑛 = 0,1,2, …
𝑎=2
𝑟=5
Geometric – Example3
𝑎𝑟 𝑛 , 𝑛 = 0,1,2, …
𝑎=6
𝑟 = 1/3
Geometric – Example4
Find 𝒂, 𝒓? 𝟑 ∗ 𝟒𝒏 , 𝒏 = 𝟎, 𝟏, 𝟐, …
𝑎𝑟 𝑛 , 𝑛 = 0,1,2, …
𝑎=3
𝑟=4
Geometric – Example5
Find 𝒂, 𝒓? 𝟑 ∗ 𝟒𝒏 , 𝒏 = 𝟏, 𝟐, 𝟑, …
𝑎 = 12
𝑟=4
Arithmetic
Arithmetic – Example1
𝑎 + 𝑛𝑑 , 𝑛 = 0,1,2, …
𝑎 = −1
𝑑=4
Arithmetic – Example2
𝑎 + 𝑛𝑑 , 𝑛 = 0,1,2, …
𝑎=7
𝑑 = −3
Notes:
• Are terms obtained from previous terms by adding the
same amount or an amount that depends on the
position in the sequence?
• Are terms obtained from previous terms by
multiplying by a particular amount?
• Are terms obtained by combining previous terms in a
certain way?
• Are there cycles among the terms?
Fibonacci Sequence
0, 1, 1, 2, 3, 5, 8, …
Example 1
Example 1
Answer
100
1/𝑛
𝑛=1
Example 2
Example 2
Answer
Example 3
Example 3
Example 4
Double Summation
Find
Double Summation
Find
Definition:
A matrix is a rectangular array of numbers. A matrix
with 𝑚 rows and 𝑛 columns is called an 𝑚 × 𝑛 matrix. A
matrix with the same number of rows as columns is
called square.
1 2
Definition:
A matrix is a rectangular array of numbers. A matrix
with 𝑚 rows and 𝑛 columns is called an 𝑚 × 𝑛 matrix. A
matrix with the same number of rows as columns is
called square.
𝒎 × 𝒏 matrix
𝒎 × 𝒏 matrix
A B A+B
@Ahmed Hagag BS102 Discrete Mathematics 140
Matrices (4/14)
A B A+B
@Ahmed Hagag BS102 Discrete Mathematics 141
Matrices (5/14)
𝐀 𝒎𝒌 𝐁𝒌𝒏 𝐀𝐁 = 𝐂𝒎𝒏
𝐀 𝒎𝒌 𝐁𝒌𝒏 𝐀𝐁 = 𝐂𝒎𝒏
Example1 (1/2)
1 1 2 1 2
𝐀3×3 = 1 2 3 𝐌3×2 = 3 −1
1 3 −1 3×3 1 1 3×2
1 2
1
1 1 2 1 2 1 2
2 1 2 3 × 3 −1 = 3 −1
3 1 3 −1 1 1 1 1
Example1 (2/2)
1 1 2 1 2
𝐀3×3 = 1 2 3 𝐌3×2 = 3 −1
1 3 −1 3×3 1 1 3×2
Example1 (2/2)
1 1 2 1 2
𝐀3×3 = 1 2 3 𝐌3×2 = 3 −1
1 3 −1 3×3 1 1 3×2
Example2 (1/2)
Example2 (2/2)
1 0 0
𝐈3 = 0 1 0
0 0 1 3×3
Transpose of 𝐀 (𝐀𝒕 )
Interchanging the rows and columns of 𝐀
𝐀 𝒕
𝐀
Transpose of 𝐀 (𝐀𝒕 )
Interchanging the rows and columns of 𝐀
𝐀 𝒕
𝐀
Symmetric
A square matrix 𝐀 is called symmetric if 𝐀 = 𝐀𝒕
𝐀 𝐀𝒕
Symmetric
A square matrix 𝐀 is called symmetric if 𝐀 = 𝐀𝒕
Zero–One Matrices
A matrix all of whose entries are either 𝟎 or 𝟏
meet
join
Example (1/3)
Example (2/3)
Example (3/3)