Sunteți pe pagina 1din 79

SETS

CSC510 – Discrete Structures

Nur Azmina binti Mohamad Zamani

Faculty of Computer & Mathematical Sciences


DEFINITION of SET
 A collection of well-defined objects.

 An (unordered) collection of objects


called elements or members of the set.
[Cantor’s Naïve Definition]
SET
 Must be well-defined.

EXAMPLES:
- Vowels in English alphabet
V = {a, e, i, o, u}
- First five prime numbers
P = {2, 3, 5, 7, 11}

 Each element of set is written only once!


 Order is not important.
SET
EXAMPLES:
- Vowels in English alphabet
V = {a, e, i, o, u}

Set Notation Element Notation

- First five prime numbers


P = {2, 3, 5, 7, 11}

5∈P
‘5 is an element of P’ or ‘5 is in P’

20 ∉ P
‘20 is NOT an element of P’ or ‘ 20 is NOT in P’
REPRESENTING SETS
1) Listing the members.
2) Definition by property, using set builder notation.
{x | x has property P}
EXAMPLES:
- Seasons of the year.
S = {spring, summer, autumn, winter}
S = {x | x is a season of the year}
‘S is the set of all x such that x is a season of the year’.

- Even integers between 50 and 63.


E = {50, 52, 54, 56, 58, 60, 62}
E = {x | 50 <= x < 63, x is an even integer}
‘E is the set of all x such that x is an even integer between 50 and 63’.

 If enumeration of the members is hard we often use ellipses.


Example: a set of integers between 1 and 100
A= {1,2,3,…,100}
IMPORTANT SETS
 Natural numbers:
N = {0,1,2,3, …}

 Integers
Z = {…, -2,-1,0,1,2, …}

 Positive integers
Z+ = {1,2, 3.…}

 Rational numbers
Q = {p/q | p ∈ Z, q ∈ Z, q ≠ 0}

 Real numbers
R
CARDINALITY
 Definition: Let S be a set. If there are exactly n distinct elements
in S, where n is a nonnegative integer, we say S is a finite set and
that n is the cardinality of S. The cardinality of S is denoted by |S|.

EXAMPLES:
• V={1, 2, 3, 4, 5}
|V| = 5

• A={1,2,3,4, …, 20}
|A| = 20

•|Ø|=0
EQUIVALENT SETS
Definition: Two sets are EQUIVALENT if
they have the same number of elements.

EXAMPLE:
A = {a, b, c, d}
B = {1, 2, 3, 4}

|A| = |B| = 4, so A ≡ B
EQUAL SETS
Definition: Two sets are EQUAL if and only if they
have EXACTLY the same elements.

EXAMPLE:
A = {1, 2, 3} , B = {3, 1, 2}
OR
A = {1, 3, 2} , B = {2, 1, 2, 3, 3}

Note: Duplicates don't contribute anything new to a set, so remove


them. The order of the elements in a set doesn't contribute
anything new.

so A = B
VENN DIAGRAM
 A set can be visualized using Venn Diagrams:
V = { A, B, C }
TYPES OF SETS
 SPECIAL SETS:
- Universal Set
- Empty (Null) Set
 Infinite & Finite Set
 Power Set
UNIVERSAL SET
Definition: The set of all elements under consideration
in a given discussion. It is denoted as U.

EXAMPLE:
U = {a, b, c, d, e, f, g, h, i, j}

A = {a, b, c}
B = {c, d, e}
C = {f, g, h}
SUBSET
Definition: A set of A is said to be a subset of B if and
only if every element of A is also an element of B. We
use A ⊆ B to indicate A is a subset of B.

Another way to define:


∀x (x ∈ A) → (x ∈ B)
SUBSET
EXAMPLES:
 Example1
X={1,2,3,4,5,6}
Y={1,2}

Here set Y is a subset of set X as all the elements of set Y is in set X.

Hence, we can write Y ⊂ X.

 Example 2
X={1,2,3}
Y={1,2,3}

Here set Y is a subset (Not a proper subset) of set X as all the elements
of set Y is in set X.

Hence, we can write Y⊆X.


EMPTY (NULL) SET
Definition: The set that contains NO element. It is denoted by ∅ or { }.

EXAMPLE:
A = {x | x is a month containing 32 days}
So, A = ∅ , | ∅ | = 0

Theorem: ∅ ⊆ S
 Empty set is a subset of any set.

Proof:
 Recall the definition of a subset: all elements of a set A must be also
elements of B: ∀x (x ∈ A → x ∈ B).
 We must show the following implication holds for any S
∀x (x ∈ ∅ → x ∈ S)
 Since the empty set does not contain any element, x ∈ ∅ is
always False.
 Then the implication is always True.
End of proof
SUBSET PROPERTIES
Theorem: S ⊆ S
 Any set S is a subset of itself

Proof:
 The definition of a subset says: all elements of a set A
must be also elements of B: ∀x (x ∈ A → x ∈ B).
 Applying this to S we get:
∀x (x ∈ S → x ∈ S) which is trivially True
End of proof

Note on equivalence:
 Two sets are equal if each is a subset of the other set.
A PROPER SUBSET
Definition: “subset of but not equal to”.
A set A is a proper subset of set B (written as A ⊂ B) if every element
of A is an element of set B and | A | < | B |.

EXAMPLE:
X={1,2,3,4,5,6}
Y={1,2}

Here set Y ⊂ X since all elements in Y are contained in X too and X has
at least one element is more than set Y.
INFINITE & FINITE SET
Definition: A set is infinite if it is not
finite.

EXAMPLES:
 The set of natural numbers is an infinite
set.
N = {0, 1, 2, 3, ... }
 The set of reals is an infinite set.
 The set of days in a week is a finite set.
POWER SET
Definition: Given a set S, the power set of S
is the set of all subsets of S. The power set is
denoted by P(S).

EXAMPLES:
 Assume an empty set ∅.
 What is the power set of ∅ ?
P(∅) = { ∅ }
 What is the cardinality of P(∅) ?
| P(∅) | = 1
POWER SET
 Assume set {1}
• P( {1} ) = { ∅, {1} }
• |P({1})| = 2

 Assume {1,2}
• P( {1,2} ) = { ∅, {1}, {2}, {1,2} }
• |P({1,2} )| = 4

 Assume {1,2,3}
• P({1,2,3}) = {∅, {1}, {2}, {3}, {1,2}, {1,3}, {2,3}, {1,2,3} }
• |P({1,2,3} | = 8

 If S is a set with |S| = n then | P(S) | = 2n.


N-TUPLE
 Sets are used to represent unordered collections.
 Ordered n-tuples are used to represent ordered collection.

Definition: An ordered n-tuple (x1, x2, ..., xN) is the ordered


collection that has x1 as its first element, x2 as its second
element, ..., and xN as its N-th element, N ≥ 2.

EXAMPLE:
 Coordinates of a point in the 2-D plane (12, 16).
CARTESIAN PRODUCT
Definition: Let S and T be sets. The Cartesian product
of S and T, denoted by S x T, is the set of all ordered
pairs (s, t), where s ∈ S and t ∈ T.
Hence, S x T = { (s,t) | s ∈ S ∧ t ∈ T}.

EXAMPLES:
 S = {1,2} and T = {a,b,c}
 S x T = { (1,a), (1,b), (1,c), (2,a), (2,b), (2,c) }
 T x S = { (a,1), (a, 2), (b,1), (b,2), (c,1), (c,2) }

 Note: S x T ≠ T x S !!!!
CARDINALITY OF CARTESIAN
PRODUCT
 |S x T| = |S| * |T|.

EXAMPLE:
 A= {John, Peter, Mike}
 B ={Jane, Ann, Laura}
 A x B = {(John, Jane), (John, Ann) , (John, Laura),
(Peter, Jane), (Peter, Ann) , (Peter, Laura) , (Mike, Jane)
, (Mike, Ann) , (Mike, Laura)}
 |A x B| = 9
 |A|=3, |B|=3 Æ |A| |B|= 9

Definition: A subset of the Cartesian product A x B is


called a relation from the set A to the set B.
SETS
OPERATIONS
CSC510 – Discrete Structures

Nur Azmina binti Mohamad Zamani

Faculty of Computer & Mathematical Sciences


SET UNION
Definition: The union of sets A and B (denoted
by A∪B) is the set of elements which are in A, in
B, or in both A and B.
Hence, A∪B={x|x∈A OR x∈B}.

EXAMPLE:
A = {1,2,3,6}
B = { 2,4,6,9}

A ∪ B = {1,2,3,4,6,9}
SET INTERSECTION
Definition: The intersection of sets A and B
(denoted by A∩B) is the set of elements which
are in both A and B.
Hence, A∩B={x|x∈A AND x∈B}.

EXAMPLE:
A = {1,2,3,6}
B = { 2,4,6,9}

A ∩ B = {2,6}
DISJOINT SETS
Definition:
 Two sets are called disjoint if their intersection is empty.
 A and B are disjoint if and only if A ∩ B = ∅.

EXAMPLE:
A={1,2,3,6}
B={4,7,8}

A∩B=∅
CARDINALITY OF SET UNION
 Formula: |A ∪ B| = |A| + |B| - |A ∩ B|

 More general rule:


– The principle of inclusion and
exclusion.
SET DIFFERENCE / RELATIVE
COMPLEMENT
Definition: The set difference of sets A and B (denoted
by A–B) is the set of elements which are only in A but
not in B. Hence, A−B = {x|x∈A AND x∉B}.

EXAMPLE:
A={10,11,12,13}
B={13,14,15}

(A−B)={10,11,12}
(B−A)={14,15}

Here, we can see (A−B)≠(B−A)


COMPLEMENT OF A SET
Definition: The complement of a set A (denoted by A′) is the
set of elements which are not in set A.
Hence, A′={x | x ∉ A}.
 More specifically, A′ = (U−A) where U is a universal set
which contains all objects.

EXAMPLE:
U={1,2,3,4,5,6,7,8}
A ={1,3,5,7}

A’ = {2,4,6,8}
SET IDENTITIES
 analogous to logical equivalences

 Identity
A ∪ ∅ =A
A ∩ U =A
 Domination
A∪U=U
A∩∅=∅
 Idempotent
A ∪A =A
A ∩A =A
SET IDENTITIES
 Double complement
A =A
 Commutative
A ∪ B = B ∪A
A ∩ B = B ∩A
 Associative
A ∪ (B ∪ C) = (A ∪B) ∪C
A ∩ (B ∩ C) = (A ∩ B) ∩C
 Distributive
A ∪ (B ∩C) = (A∪ B) ∩(A ∪ C)
A ∩ (B ∪ C) = (A ∩B) ∪(A ∩C)
SET IDENTITIES
 DeMorgan’s
(A ∩ B) = A ∪ B
(A ∪ B) = A ∩ B
 Absorption
A ∪ (A ∩ B) = A
A ∩ (A ∪ B) = A
 Complement
A ∪A = U
A ∩A = ∅
 Difference
A – B =A ∩ B
SET IDENTITIES
 Set identities can be proved using membership tables.
 List each combination of sets that an element can belong to.
 Then show that for each such a combination the element either
belongs or does not belong to both sets in the identity.

EXAMPLE:
 Prove: (A ∩ B) = A ∪ B
COMPUTER REPRESENTATION
OF SETS
COMPUTER REPRESENTATION
OF SETS
SETS
RELATIONS
CSC510 – Discrete Structures

Nur Azmina binti Mohamad Zamani

Faculty of Computer & Mathematical Sciences


BINARY RELATION
Definition: Let A and B be two sets. A binary relation
from A to B is a subset of a Cartesian product A x B.
REPRESENTING BINARY
RELATIONS
REPRESENTING BINARY
RELATIONS
RELATIONS ON A SET
Definition: A relation on a set A is a relation from A to A.

EXAMPLE:
R1 = {(a,b) | a ≤ b},
R2 = {(a,b) | a > b},
R3 = {(a,b) | a = b or a = -b},
R4 = {(a,b) | a = b},
R5 = {(a,b) | a = b + 1},
R6 = {(a,b) | a + b ≤ 3}.

Which of these relations contain each of the pairs (1,1), (1,2), (2,1), (1,-1),
and (2,2) ?
(1,1) -> R1 , R3 , R4 , R6
(1,2) -> R1 , R6
(2,1) -> R2 , R5 , R6
(1,-1) -> R2 , R3 , R6
(2,2) -> R1 , R3 , R4
NUMBER OF BINARY RELATIONS
PROPERTIES OF RELATIONS
 Reflexive Relations
 Irreflexive Relations
 Symmetric Relations
 Antisymmetric Relations
 Transitive Relations
REFLEXIVE RELATIONS
Definition: A relation R on a set A is called reflexive if (a,a) ∈ R for
every element a ∈ A.

EXAMPLE:
Consider the following relations on {1,2,3,4}:
R1 = {(1,1), (1,2), (2,1), (2,2), (3,4), (4,1), (4,4)},
R2 = {(1,1), (1,2), (2,1)},
R3 = {(1,1), (1,2), (1,4), (2,1), (2,2), (3,3), (4,1), (4,4)},
R4 = {(2,1), (3,1), (3,2), (4,1), (4,2), (4,3)},
R5 = {(1,1), (1,2), (1,3), (1,4), (2,2), (2,3), (2,4), (3,3), (3,4), (4,4)},
R6 = {(3,4)}.
Which relations are REFLEXIVE?
R3 and R5 - contains (1,1), (2,2), (3,3) and (4,4)
IRREFLEXIVE RELATIONS
Definition: A relation R on a set A is called irreflexive if (a,a) ∉ R for every
element a ∈ A.

EXAMPLE:
Consider the following relations on {1,2,3,4}:
R1 = {(1,1), (1,2), (2,1), (2,2), (3,4), (4,1), (4,4)},
R2 = {(1,1), (1,2), (2,1)},
R3 = {(1,1), (1,2), (1,4), (2,1), (2,2), (3,3), (4,1), (4,4)},
R4 = {(2,1), (3,1), (3,2), (4,1), (4,2), (4,3)},
R5 = {(1,1), (1,2), (1,3), (1,4), (2,2), (2,3), (2,4), (3,3), (3,4), (4,4)},
R6 = {(3,4)}.
Which relations are IRREFLEXIVE?
R1 , R2 , R4 , and R6 – does not contains (1,1), (2,2), (3,3) and (4,4)
IRREFLEXIVE RELATIONS (cont.)
SYMMETRIC RELATIONS
Definition: A relation R on a set A is called
symmetric if
∀ a, b ∈ A (a,b) ∈ R → (b,a) ∈ R

EXAMPLE:
Consider the following relations on {1,2,3,4}:
R = {(1,2), (1,3), (1,4), (2,1), (2,3), (2,4), (3,1),
(3,2), (3,4), (4,1), (4,2), (4,3)}

Is R SYMMETRIC?
YES - (a,b) ∈ R → (b,a) ∈ R
ANTISYMMETRIC RELATIONS
Definition: A relation on a set A is called antisymmetric if
[(a,b) ∈ R and (b,a) ∈ R] → a = b where a, b ∈ A

EXAMPLE:
Relation R on A = {1,2,3,4} defined as:
R = {(1,2),(2,2),(3,3)}

Is R ANTISYMMETRIC?

YES
TRANSITIVE RELATIONS
Definition: A relation R on a set A is called transitive if
[(a,b) ∈ R and (b,c) ∈ R] → (a,c) ∈ R for all a, b, c ∈ A.

EXAMPLE 1:
Consider the following relations on {1,2,3,4}:
R1 = {(1,1), (1,2), (2,1), (2,2), (3,4), (4,1), (4,4)},
R2 = {(1,1), (1,2), (2,1)},
R3 = {(1,1), (1,2), (1,4), (2,1), (2,2), (3,3), (4,1), (4,4)},
R4 = {(2,1), (3,1), (3,2), (4,1), (4,2), (4,3)},
R5 = {(1,1), (1,2), (1,3), (1,4), (2,2), (2,3), (2,4), (3,3), (3,4), (4,4)},
R6 = {(3,4)}.
Which relations are TRANSITIVE?

R4 , R5 , R6
TRANSITIVE RELATIONS (cont.)
EXAMPLE 2

EXAMPLE 3
 EQUIVALENCE RELATION
◦ Reflexive, Symmetric and Transitive

 PARTIAL ORDER RELATION


◦ Reflexive, Antisymmetric and Transitive
SETS -
FUNCTIONS
CSC510 – Discrete Structures

Nur Azmina binti Mohamad Zamani

Faculty of Computer & Mathematical Sciences


FUNCTIONS
REPRESENTING FUNCTIONS
1) Explicitly state the assignments in between elements of the
two sets.
2) Compactly by a formula. (using ‘standard’ functions)

EXAMPLE 1:
Let A = {1,2,3} and B = {a,b,c}
Assume f is defined as:
•1c
•2a
•3c

Is f a function ?
Yes - since f(1)=c, f(2)=a, f(3)=c. each element of A is assigned
an element from B.
REPRESENTING FUNCTIONS
(cont.)
EXAMPLE 2:
Let A = {1,2,3} and B = {a,b,c}
Assume g is defined as:
•1c
•1b
•2a
•3c
Is g a function ?
No - g(1) = is assigned both c and b.
IMPORTANT SETS
IMPORTANT SETS (cont.)
EXAMPLE:
Let A = {1,2,3} and B = {a,b,c}
• Assume f is defined as:
1c
2a
3c
 What is the image of 1?
1  c, c is the image of 1.
 What is the pre-image of a?
2  a, 2 is a pre-image of a.
 Domain of f ?
{1,2,3}
 Codomain of f ?
{a,b,c}
 Range of f ?
{a,c}
IMAGE OF A SUBSET

EXAMPLE1:
IMAGE OF A SUBSET (cont.)
IMAGE OF A SUBSET (cont.)
EXAMPLE 2:
TYPES OF FUNCTIONS
 Injective Function
 Surjective Function
 Bijective Function
 Identity Function
 Inverse Function
INJECTIVE FUNCTION
INJECTIVE FUNCTION (cont.)
EXAMPLE 1:
Let A = {1,2,3} and B = {a,b,c}
 Define f as:
1→c
2→a
3→c
Is f one to one?
No, it is not one-to-one since f(1) = f(3) =
c, and1 ≠ 3.
INJECTIVE FUNCTION (cont.)
EXAMPLE 2:
Let g : Z → Z, where g(x) = 2x - 1.
Is g is one-to-one ?
Yes.
Suppose g(a) = g(b),
i.e.,
2a - 1 = 2b - 1
=> 2a = 2b
=> a = b.
SURJECTIVE FUNCTION
SURJECTIVE FUNCTION (cont.)
EXAMPLE 1:
Let A = {1,2,3} and B = {a,b,c}
Define f as:
•1c
•2a
•3c
Is f an onto?
No. f is NOT onto, since b ∈ B has no pre-
image
SURJECTIVE FUNCTION (cont.)
EXAMPLE 2:
Let A = {0,1,2,3,4,5,6,7,8,9}, and B = {0,1,2}

Define h: A → B as h(x) = x mod 3.

Is h an onto function?
Yes. h is onto since a pre-image of 0 is 6, a pre-
image of 1 is 4, a pre-image of 2 is 8.
BIJECTIVE FUNCTIONS
BIJECTIVE FUNCTION (cont.)
EXAMPLE 1:
Let A = {1,2,3} and B = {a,b,c}
Define f as:
•1c
•2a
•3b
Is f is a bijection?
Yes. It is both one-to-one and onto.
IDENTITY FUNCTION
INVERSE FUNCTION
INVERSE FUNCTION (cont.)
INVERSE FUNCTION (cont.)
INVERSE FUNCTION (cont.)
INVERSE FUNCTION (cont.)
COMPOSITION OF FUNCTION
COMPOSITION OF FUNCTION
(cont.)
COMPOSITION OF FUNCTION
(cont.)
COMPOSITION OF FUNCTION
(cont.)

S-ar putea să vă placă și