Sets in Discrete Structures
Sets in Discrete Structures
Roster Form
Set of positive even numbers less than 10, A = {2, 4, 6, 8}
Set of vowels in English alphabet, B = {a, e, i, o, u}
C = {{1, 2}, {{3}, 2}, {2}, {1}} C is a set that contains sets
Elements of C are:
{1, 2}
{{3}, 2}
{2}
{1}
SET BUILDER NOTATION
The set is defined by specifying a property that elements of
the set have in common
the set is described as S = { x | p(x) }
Examples
A = {x | 1≤x<10 and (x%2)=0} A = {2, 4, 6, 8}
B = {x | x is a vowel in the English alphabet} B = {a, e, i, o, u}
C = {x | x is a prime number} C = {2, 3, 5, 7, 11, 13,…}
D = {5x | x is an integer} D = {…, -10, -5, 0, 5, 10,…}
VENN DIAGRAM
Visual representation of relations between sets
A schematic diagram that shows possible logical relations between different
mathematical sets
a u U – Universe of discourse
i
A – name of the set
A e
c Lower case letters – elements in the set
o
x
U m
Important Sets
Let A be an arbitrary set. It can be any set, even an empty or universal set
Theorem 1: A ⊆ U All sets belongs to a universal set
Theorem 2: ∅ ⊆ A An empty set is a subset of all sets
Theorem 3: A ⊆ A All sets are a subset of itself
Power Sets
Power set creates a new set whose elements are all subsets of a set
“Power set of set S” is denoted by P(S)
Cardinality of a power set of set S is 2n, where n = |S|
A = {1, 2}
Subsets of A are: ∅ {1} {2} {1, 2}
P(A) = {∅, {1}, {2}, {1, 2}}
|P(A)| = 22 = 4 Power set of an empty set Power set of a set of empty set
P(∅) = {∅} P({∅}) = {∅, {∅}}
A set will not be a subset of its own power set |P(∅)| = 20 = 1 |P({∅})| = 21 = 2
A ⊄ P(A)
A = {1, 2} B = {a}
P(A) = {∅, {1}, {2}, {1, 2}} P(B) = {∅, {a}}
1 ∉ P(A) and 2 ∉ P(A) |P(B)| = 21 = 2
B = {{1}, {1, 2}, ∅}
P(B) = {∅, {{1}}, {{1, 2}}, {∅}, {{1}, {1, 2}}, {{1}, ∅}, {{1, 2}, ∅}, {{1}, {1, 2}, ∅}}
|P(B)| = 23 = 8
EXERCISE: Use set builder notation to give the
description of each set
1. [0,3,6,9,12]
2. [m,n,o,p]
3.
Given: a=(2,4,6) b=(2,6) c=(4,6) d=(4,6,8)
Which of these sets are subsets of which other of these sets
4. What is the power set of (0,1,2)?
5. What is the power set of empty set?
Set Operations
1. Union A B
2. Intersection
3. Difference
4. Complement
5. Cartesian Product
4
1 2
Union 3
The union of set A and B is the set of elements which are in A, B and both A and B
Union is denoted by ∪
A ∪ B = { x | x ∈ A or x ∈ B}
A = {1, 2, 3} C
B = {2, 4} D
A ∪ B = {1, 2, 3, 4}
C = {1, {2}, 3}
D = {{3}, 4}
C ∪ D = {1, {2}, 3, {3}, 4}
Set Operations
1. Union A B
2. Intersection
3. Difference
4. Complement
5. Cartesian Product
4
1 2
Intersection
The intersection of set A and B is the set of elements which are in both A and B 6
Intersection is denoted by ∩ A ∩ B={ x | x ∈ A and x ∈ B} 5
C
A = {1, 2, 3} D
B = {2, 4}
A ∩ B = {2}
Difference 3
The set difference of A and B is the set of
elements which are only in A but not in B
Denoted by A – B
A − B = { x | x ∈ A and x ∉ B}
A = {1, 2, 3}
B = {2, 4}
A – B = {1, 3}
B – A = {4}
A–B≠B–A
Set Operations U
2
1. Union A
2. Intersection
3. Difference 5 √81
4. Complement B
5. Cartesian Product
1
7
-12
6
3
Complement
The complement of a set A is the set of elements which are not in set A 4
Denoted by Ā or A’
Ā = ꓯx { x | x ∉ A }
Ā = (U − A) U={-12,1,2,3,4,5,6,7,√81}
U=Z A={1,3,5,7}
A = Z- B={-12,√81,}
Ā=W Ā={-12,2,4,6, √81}
For complement of a set, it's important to know which U the set belongs to Ḃ={1,2,3,4,5,6,7}
B = { x | x is an odd number}
B‘ = {x | x is not an odd number}
ORDERED PAIRS AND ORDERED N-TUPLES
Set theory has a wide range of applications in other disciplines of mathematics, owing to its
extremely generic and abstract character. Analysis is an area of mathematics in which differential and
integral calculus are essential components. Set theory is used to get a grasp of limit points and what is
meant by the continuity of a function in this branch of mathematics. Using an algebraic approach to set
operations leads to boolean algebra, where the operations of intersection, union, and difference are
viewed as logical operations that are equivalent to the logical operators and, or, not.
SET THEORY APPLICATION IN COMPUTERS
1. Database Management
Set theory is foundational for understanding databases. Data in a database can be thought of as a
collection of sets. For instance, a table in a relational database is essentially a set of tuples. The operations we
perform on these sets are similar to standard set operations, such as union, intersection, and difference.
2. Programming Languages
Many programming languages include built-in support for sets. For instance, Python has a set data structure that
allows you to perform set operations easily.
# Define two sets
set_a = {1, 2, 3, 4}
set_b = {3, 4, 5, 6}
# Union of sets
union_set = set_a | set_b
# Intersection of sets
intersection_set = set_a & set_b
# Difference of sets
difference_set = set_a - set_b
print("Union:", union_set) print("Intersection:",
intersection_set) print("Difference:",
difference_set)
SET THEORY APPLICATION IN COMPUTERS
3. Algorithms
Set theory is also essential in algorithm design and # Finding common elements in two lists
analysis. Many algorithms can be described in terms of set list_a = [1, 2, 3, 4]
operations. For example, searching and sorting algorithms can list_b = [3, 4, 5, 6]
common_elements = set(list_a) & set(list_b)
be conceptualized as operations on sets of data. print("Common Elements:", common_elements)
SET A SET B
4. Venn Diagrams in Set Theory
Venn diagrams visually represent set operations. They are
useful for illustrating relationships between different sets.
Below is a simple Venn diagram that shows the union and
intersection of two sets.
UNION INTERSECTION
In this diagram, Set A and Set B represent two different
datasets, and the arrows indicate the operations performed
between them.
SET THEORY APPLICATION IN COMPUTERS
5. Applications in Artificial Intelligence
# Facts as sets
Set theory also finds applications in artificial intelligence, animals = {'cat', 'dog', 'fish’}
particularly in knowledge representation and reasoning. The pets = {'dog', 'cat’}
relationships between different concepts can be modeled using # Check if pets are part of animals is_pet =
pets.issubset(animals)
sets and set operations. In AI, we often represent knowledge as print("Are all pets animals?", is_pet)
sets of facts.
EXERCISE:
Find A2
A2 = ________________
Cartesian Product
EXERCISE:
C x A x B = ___________ C x B x A = _________ A x B x C = _____________
A x C x B = ___________ B x C x A = _________ (A x B) x C = ____________
CARTESIAN PRODUCT APPLICATION