Ch1 Fundamental Structure 2019
Ch1 Fundamental Structure 2019
CHAPTER 1:
FUNDAMENTAL STRUCTURES
What is Discrete Structure?
Discrete Objects
Discrete Structures
2
Why study discrete structures?
3
Sets
(In Book: Chapter 2-sec 2.1)
4
T. Mai Al-Ammar
Sets
6
T. Mai Al-Ammar
Sets (Cont.)
7
T. Mai Al-Ammar
Sets ( Cont. )
• Equal Sets :
• Two sets are equal if and only if they have the same elements, if A and B are
sets, then A = B if and only if ∀ 𝒙 ( 𝒙 ∈ 𝑨 ↔ 𝒙 ∈ 𝑩)
• e.g. { 1, 2,3 } = { 2 , 3, 1}
{ 1 , 2, 2, 3 } = { 1,2, 3 ,3 }
• Empty Set ( null set) :
• A set that has no elements. It is denoted by ∅ or { } . Note: {}
8
T. Mai Al-Ammar
Sets (Cont. )
• Venn Diagram :
• Sets can be represented graphically using Venn diagrams.
• In Venn diagram, the universal set is represented as a rectangle.
• Inside rectangle, circles are used to represent sets.
• And points represent elements.
U V
a
9
T. Mai Al-Ammar
Sets (subsets and superset)
• The set A is said to be a subset of the set B if and only if every element of A is
also an element of B, and B is said to be superset of A.
• A ⊆ B if and only if ∀x(x ∈ A → x ∈ B) is true
• To show that A ⊄ B, find a single element x A such that x B
• For every set S: ⊆ S and S ⊆ S
A
B
Example: Let A = {a, b, c}
B = {a, b, c, d},
C = { a, c, d, e}
then A ⊆ B , but A is not subset of C.
10
T. Mai Al-Ammar
Sets (proper subsets )
Proper subset:
if a set A is a subset of B but AB then A B.
for A B, it must be the case that AB is true and there must exist an
element x of B that is not an element of A:
i.e. ∀ 𝒙 𝒙 ∈ 𝑨 → 𝒙 ∈ 𝑩 ˄ ∃ 𝒙 ( 𝒙 ∈ 𝑩˄ x ∉ A)
• A = B if AB and B A i.e. x ((x A) <=> (x B))
11
T. Mai Al-Ammar
Sets ( Cont.)
Examples:
• Is {x} {x}? No
• Is {x} {x}? Yes
• Is {x} {x, {x}}? Yes
• Is {x} {x, {x}}? Yes
12
T. Mai Al-Ammar
Size of a Set
Questions:
|Ø|=?
If B={1, 1, 1}, then |B|=?
If S = { , {}, {,{}} }, then |S|=?
13
T. Mai Al-Ammar
Sets (Cartesian Products)
• Examples:
If A={1, 2}, B={a, b, c} then A x B={(1, a), (1, b), (1, c), (2, a), (2, b), (2, c)}
• Facts:
1. A x B ≠ B x A 2. |A x B| = |A| * |B|
• A1 x A2 x … x An = {(a1, a2,…, an) | ai Ai, for i=1, 2, …, n}
• Questions
• If P = {1,2}, then P x P x P =?
14
T. Mai Al-Ammar
Sets (power set)
Power Set :
• If S is a set, then 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). i.e., P(S) = { x | x S }.
Examples:
Ifs={0,1,2}, then P(S)={∅, {0}, {1}, {2}, {0, 1}, {0, 2}, {1, 2}, {0, 1, 2}}.
If S={a}, then P(S)={, {a}}.
If S = {a, b}, then P(S)={, {a}, {b}, {a, b}}.
If S = , then P(S)= {}
If S = {{}}, then P(S)= {, {{}} }
Fact:
16
T. Mai Al-Ammar
Sets Operations
1. Union
2. Intersection
3. Disjoint
4. Difference
5. Complement
6. Set Identities
7. Inclusion-exclusion
8. Computer representation
17
T. Mai Al-Ammar
Set operations ( Cont.)
1. Union :
The union of two sets A and B, denoted by AB, is the set that contains
those elements that are either in A or in B, or in both:
A B = { x | x A or x B}
e.g. The union of two sets {1,3,5} and { 1,2,3} is { 1, 2, 3,5, }
In the figure, the colored area (1,2, and 3) is the union of two sets.
18
T. Mai Al-Ammar
Set operations ( Cont.)
2. Intersection :
The intersection of two sets A and B, denoted by AB, is the set
containing those elements in both A and B:
A B = { x | x A and x B}
e.g. the intersection of two sets {1,3,5 } and {1,2,3} is {1,3}
In the figure, the colored area (2) is the intersection of two sets.
19
T. Mai Al-Ammar
Set operations ( Cont.)
A1 ∪ A2 ∪ ・ ・ ・ ∪ An
A1 ∩ A2 ∩ ・ ・ ・ ∩ An
21
T. Mai Al-Ammar
Sets Operations (Cont.)
3. Disjoint sets:
Two sets are said to be disjoint if their intersection is the empty set.
Examples:
22
T. Mai Al-Ammar
Sets Operations (Cont.)
4. Difference :
The difference of two sets A and B, denoted by A-B, is the set containing
those elements that are in A but not in B:
A – B = { x | xA and xB}
e.g. If A = {1, 3, 5}, and B = {1, 2, 3}, then A-B = {5}, and B-A = {2}.
In the figure, the colored area (1) is the difference of two sets.
In general : A-B B-A
23
T. Mai Al-Ammar
Set Operations (Cont.)
5. Complement :
The Complement of the set A : is the complement of A with the
respect t0 universal set U, i.e. those elements that are in universal set
but not in A .
24
T. Mai Al-Ammar
Set Identities
6. Set Identities
Identities Name
AU=A
Identity laws
AU=A
AUU=U
Domination laws
A=
AUA=A
Idempotent laws
AA=A
(Ac)c = A Complementation law
AUB=BUA
Commutative laws
AB=BA
A U (B U C) = (A U B) U C
Associative laws
A (B C) = (A B) C
25
T. Mai Al-Ammar
Set Identities
Facts:
• Uc = Ø and Øc = U
• A - B = A Bc 26
T. Mai Al-Ammar
Set Theory – Inclusion-exclusion
B A Wrong or right?
27
T. Mai Al-Ammar
Set Theory – Inclusion-exclusion
Answer:
Note that |A|+|B| counts each element that is in A but not in B, or in B not in A,
exactly once. Each element that is in both A and B will be counted twice
28
T. Mai Al-Ammar
Set Theory – Inclusion-exclusion
Example:
There are 150 CS majors
CS530
100 are taking CS530 CS520
Question:
How many are taking neither?
Answer:
Let U be a finite universal set. Let a1, a2,…, an be an arbitrary ordering of the
elements of U.
Represent a subset A of U with the bit string of length n, where
1 if ai A
i th
bit
0 if ai A
Examples:
Let U={1, 2, 3, 4, 5, 6, 7, 8, 9, 10} and then the set A={1, 3, 5, 7, 9} can be
represented by the string of bits:
10 1010 1010
The set B={1, 2, 4, 9} can be represented as:
11 0100 0010
30
T. Mai Al-Ammar
Set Theory – Computer representation
Examples:
A: 10 1010 1010
B: 11 0100 0010
• The set A U B can be represented as: 11 1110 1010
• The set A B can be represented as: 10 0000 0010
Questions:
If C={1, 6, 8, 10}, express following sets with bit strings
A-B, Ac, A U (B C) and A (B U C)
31
T. Mai Al-Ammar
Relations
(In Book: Chapter 9- sec 9.1 and 9.5)
32
T. Mai Al-Ammar
Relations
Relation:
first element of each ordered pair comes from A and the second
element comes from B.
a R b (a,b) R
a R b (a,b) ∉ R
33
T. Mai Al-Ammar
Relations- examples
Example:
Let A = Set of students; B = Set of courses, let R be the relation that
consists of pairs :
R = {(a,b) | student a is enrolled in course b}
Note that when a student is not enrolled in any course, there will be no
pairs in R that have this student as the first element.
Example :
Let A = Set of cities; B = Set of countries. Define the relation R by
specifying that (a, b) belongs to R if city a is the capital of b.
For instance, (Riyadh, Saudi Arabia), (Delhi, India), (Washington, USA)
are in R. 34
T. Mai Al-Ammar
Relations ( Cont.)
Example:
Let A={0, 1, 2} and B={a, b}. {(0, a), (0, b), (1, a), (2, b)} is a relation
from A to B. This means, 0Ra, but 1Rb.
Using a table
0.
.a R a b
0 X X
1 X
1.
2 X
.b
35
T. Mai Al-Ammar 2.
Relations ( Cont.)
element of A.
the relation.
related to each element of A, i.e. every element has only one image.
36
T. Mai Al-Ammar
Relations- on a set
Definition:
Example:
(a, b) є R if and only if a and b are positive integers not exceeding 4 such
that a divides b, we see that
R={(1, 1), (1, 2), (1, 3), (1, 4), (2, 2), (2, 4), (3, 3), (4, 4)}
.1 1 R 1 2 3 4
.2 2. 1 X X X X
2 X X
.3 3.
3 X
.4 4. 4 X
38
T. Mai Al-Ammar
Relations ( Cont.)
Example :
Which of these relations contain each of the pairs (1, 1), (1, 2), (2, 1), (1, -
1) and (2, 2)?
The contrapositive is : ∀𝒂 ∀𝒃 ( 𝒂 ≠ 𝒃 → ( 𝒂, 𝒃 ∉ 𝑹 ˅ 𝒃, 𝒂 ∉ 𝑹 ))
40
T. Mai Al-Ammar
Relations ( Properties of Relations )
Remark:
The terms symmetric and antisymmetric are not opposites.
A relation can have both of these properties or may lack both of them.
Example :
The reflexive relations are R1 (because a ≤ a, for all integer a), R3 and R4.
For each of the other relations ,it is easy to find a pair of the form (a, a)
that is not in the relation.
42
T. Mai Al-Ammar
Relations ( Properties of Relations )
43
T. Mai Al-Ammar
Relations ( Properties of Relations )
Example :
The transitive relations from Example 5 are R1, R2, R3 and R4.
Example :
R1= {(1, 1), (1, 2), (2, 1), (2, 2), (2, 3)},
R2={(1, 1), (1, 2), (2, 2), (3, 2), (3, 3)},
R4={(2, 3)},
46
T. Mai Al-Ammar
Relations -Equivalence relations
Definition:
47
T. Mai Al-Ammar
Relations -Equivalence relations
Example :
Let R be the relation on the set of real numbers such that aRb if and only
if a-b is an integer. Is R an equivalence relation?
• As a-a = 0 is an integer for all real numbers a. So, aRa for all real
numbers a. Hence R is reflexive.
• Let aRb, then a-b is an integer, so b-a also an integer. Hence bRa, i.e., R
is symmetric.
• If aRb and bRc, then a-b and b-c are integers. So, a-c = (a-b) + (b-c) is
also an integer. Hence, aRc. Thus R is transitive.
Consequently, R is an equivalence relation
48
T. Mai Al-Ammar
Relations -Partial orderings
Definition:
A relation R on a set S is called a partial ordering or partial order if it is reflexive,
antisymmetric, and transitive.
A set S together with a partial ordering R is called a partially ordered set, or poset, and
is denoted by (S,R). Members of S are called elements of the poset
Example:
Show that the “greater than or equal” relation (≥) is a partial ordering on the set of integers.
R= {(a, b) | a ≥ b} for all a, b, Z
R is reflexive, since a ≥ a for every integer a
R is antisymmetric, if a ≥ b and b ≥ a, then a = b.
R is transitive because a ≥ b and b ≥ c imply that a ≥ c.
It follows that ≥ is a partial ordering on the set of integers and (Z, ≥) is a poset.
49
T. Mai Al-Ammar
Relations -Partial ordering
Example:
Let R be the relation on the set of people such that xRy if x and y are people and
x is older than y. Show that R is not a partial ordering.
50
T. Mai Al-Ammar
Relations -Partial ordering
Definition:
The elements a and b of a poset (S, R) are called comparable if either a R b or
b R a. When a and b are elements of S such that neither a R b nor b R a, a
and b are called incomparable
Example:
The “divides” relation on the set of positive integers is a partial ordering
(Why). Are the integers 3 and 9 comparable? Are 5 and 7 comparable? In poset
(Z+, |)?
The integers 3 and 9 are comparable, because 3 | 9.
The integers 5 and 7 are incomparable, because 5 | 7 and 7 | 5.
51
T. Mai Al-Ammar
Relations -Partial ordering
Definition:
If (S, R) is a poset and every two elements of S are comparable, S is called a
totally ordered or linearly ordered set, and R is called a total order or a
linear order. A totally ordered set is also called a chain.
Example:
The poset (Z,≤) is totally ordered, because a ≤ b or b ≤ a whenever a and b are
integers.
The poset (Z+, | ) is not totally ordered because it contains elements that are
incomparable, such as 5 and 7.
52
T. Mai Al-Ammar
Relations -Partial ordering
Definition:
(S, R) is a well-ordered set if it is a poset such that R is a total ordering and
every nonempty subset of S has a least element.
Example:
The set of natural numbers is well ordered .
The set of real numbers is totally ordered but not well ordered.
The set of rational numbers is naturally totally ordered but not well ordered.
(If p/q∈Q+, we can find p/(q+1) ∈ Q+ and it is less than p/q)
53
T. Mai Al-Ammar
Functions
(In Book: Chapter 2-sec 2.3)
54
T. Mai Al-Ammar
Introduction
Definition:
• Let A and B be nonempty sets. A function f from A to B ( A 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.
• Function are sometimes also called mapping or transformations.
Functions are specified in different ways :
Explicitly state the assignment ( as example in the previous slide)
Give a formula, e.g. 𝑓 𝑥 = 𝑥 + 1
Use a computer program to specify a function
Define a function in terms of a relation from A to B 56
T. Mai Al-Ammar
Functions-example
Notation: f: RR,
domain codomain
f(x) = -(1/2)x - 25
f(x) = -(1/2)x - 25
57
T. Mai Al-Ammar
Functions -Image and Pre-image
Definition:
• If the function f : A B, then A is the domain and B is the co-domain
of f.
• If f(a) = b, we say that b is the image of a and a is a pre-image of b.
• The range or image of f is the set of all images of elements of A.
• If f is a function from A to B, we say that f maps A to B.
a b=f(a)
f(a)
A f B
58
T. Mai Al-Ammar
Functions- Image and Pre-image
59
T. Mai Al-Ammar
Functions -Examples
Example:
What are the domain, co-domain and range of the function that assigns
grades to students?
Range {21,22,24} 61
T. Mai Al-Ammar
Functions -Examples
Example:
Let f be the function that assigns the last two bits of a bit string of length 2
or greater to that string. For example, f(11010)=10.
both the co-domain and the range are the set {00, 01, 10, 11}
Example:
Range of f is the set of all integers that are perfect squares {0, 1, 4, 9, …}
62
T. Mai Al-Ammar
Functions ( Cont.)
programs
63
T. Mai Al-Ammar
Functions ( Cont.)
Definition:
Let f1 and f2 be two functions from A to R. Then f1+ f2 and f1 f2 are also
functions from A to R defined by
Example :
Let f1 and f2 be two functions from R to R such that f1 (x) = x2 and f2 (x)
= x – x2. What are the functions f1+f2 , f1 f2?
a b (a ≠ b f (a) ≠ f (b))
Example :
Determine whether the function f: {a, b, c, d} {1, 2, 3, 4, 5} with f(a) = 4,
f(b) = 5, f(c) = 1, and f(d) = 3 is injective.
The function f is one-to-one since f takes on different values at the four
elements of its domain.
Example :
Determine whether the function f : Z Z , f (x) = x2 is injective.
The function f is not one-to-one since, 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.
66
T. Mai Al-Ammar
Functions- Surjection
A function f from the set A to the set B is said to be onto or
∀𝒃 ∃𝒂 ( 𝒇 𝒂 = 𝒃)
67
T. Mai Al-Ammar
Functions - Surjection
Example :
Determine whether the function f: {a, b, c, d} {1, 2, 3} with f(a) = 3, f(b) = 2, f(c)=
1, and f(d) = 3 is surjective.
The function f is onto, since three elements of the co-domain are images of elements
in the domain.
Example:
Determine whether the function f: Z Z, f(x) = x2 is surjective.
The function f is not onto since, e.g. there is no integer x with x2 = -1.
Example :
70
T. Mai Al-Ammar
Functions-Questions
71
T. Mai Al-Ammar
Functions-Questions
A f B
75
T. Mai Al-Ammar
Functions -Examples
Example 15: Find out whether the function f: {a, b, c} {1, 2, 3} with
f(a) = 2, f(b) = 3, and f(c) = 1 is invertible. And if yes, what is its
inverse?
Sol: The function f is invertible, since it is bijective. 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 16: Determine whether the function f: R R, with f(x) = x2 is
invertible.
Sol: The function f is not one-to-one, since for instance, f(-2) = f(2) = 4,
but 2 ≠ -2.
Q5: find out whether the function f: Z Z, with f(x) = x+1 is invertible.
And if yes, what is its inverse?
76
T. Mai Al-Ammar
Functions –Compositions of functions
Note that the composition f o g can not be defined unless the range of g is a
subset of the domain of f.
(f o g)(a)
. g(a) . f(g(a)) .
a G(a) f(g(a))
g f
A B C
fog
77
T. Mai Al-Ammar
Functions -Examples
Example 17: Let g:{a, b, c}{a, b, c} with g(a)=b, g(b)=c, g(c)=a. Also, let
f:{a, b, c}{1, 2, 3} with f(a)=3, f(b)=2, f(c)=1. What are the
compositions of f and g, i.e., (f o g), and g and f, i.e., (g o f)?
Sol: The composition f o g, is defined by
(f o g)(a) = f(g(a)) = f(b) = 2,
(f o g)(b) = f(g(b)) = f(c) = 1, and
(f o g)(c) = f(g(c)) = f(a) = 3.
Note that g o f is not defined, because the range of f is not subset of the
domain of g.
Q6: Let g:{a, b, c}{a, b, c} with g(a)=a, g(b)=b, g(c)=c. Also, let f:{a, b,
c}{1, 2, 3} with f(a)=1, f(b)=2, f(c)=3. What are the compositions (f o g)
& (g o f)?
78
T. Mai Al-Ammar
Functions -Examples
Example 18: Let f:ZZ with f(x) = 2x+3, and g:ZZ with g(x) = 3x+2.
What are the compositions (f o g) and (g o f)?
Sol: Both compositions (f o g) and (g o f) are defined. (f o g)(x) = f(g(x)) =
f(3x+2) = 2(3x+2)+3 = 6x+7, and
(g o f)(x) = g(f(x)) = g(2x+3) = 3(2x+3)+2 = 6x+11.
Definition: Let A and B be two sets and f: AB be a function. The graph
of the function f is the set of ordered pairs
{(a, b) | , a A and f(a) = b}.
79
T. Mai Al-Ammar
Functions -Examples
Example 19:
80
T. Mai Al-Ammar
Functions -Properties
Some properties:
• f(Ø) = Ø
• f({a}) = {f(a)}
• f(A U B) = f(A) U f(B)
• f(A B) f(A) f(B)
• f-1() =
• f-1(A U B) = f-1(A) U f-1(B)
• f-1(A B) = f-1(A) f-1(B)
81
T. Mai Al-Ammar
Functions –Familiar functions
82
T. Mai Al-Ammar
End of Chapter 1
83
T. Mai Al-Ammar