Lecture – 2
Set and its Operations
Discrete Structures (CSAL-1213)
Course Instructor: Mahwish Shahid
Course Instructor
Mahwish Shahid
Email: [email protected]
For queries and counselling: write an email for appointment or
visit during counselling hours
Office: Sports Building (GYM Faculty),
o 2nd floor, Cabin 13, FOIT
Textbook:
Main Text:
K. Rosen: Discrete Structures and its Applications
Weekly Readings:
L. Lovasz: Discrete Mathematics, Elementary and Beyond
Reference:
R. J. Wilson: Graph Theory
Policies and Guidelines
No usage of cellphones in the class!
Attendance Policy/Late Policy
Quiz Policy
Mostly announced and 4-6 Quizzes
Assignments
4 Handwritten Assignments (minimum)
Plagiarism / AI results in Zero (0)
Class Participation
Class exercises (No retake)
Good Practices
Be on time in class
Be regular (do not miss a single class)
Start assignments on time
Do not miss any assignment or quiz
Come up with good questions (ask in class/after class)
Visit during office hours to discuss your problems/assignments
Bad Practices
Excuses
Coming late in class (remember: quiz will be in first 15 min of class)
Come to class without pen and notebooks
Asking for leaves --- Teacher has no authority to grant leaves.
Manage your 6 absents as emergency leaves, or request HoD/Dean for extra leaves.
Requesting to increase marks
Coming to class without reading the required text/notes
Copying / plagiarism
Asking to extend the deadline
Using mobile phones in class or Cross talk in class
Set
Unordered Collection of Objects
A set is a well-defined collection of distinct objects, considered as an object in its own
right.
Notation: Sets are typically denoted using curly braces: A = {1, 2, 3}.
Students in Class: {ali, amna, hadi, sara}
Cities of Pakistan: {Lahore, Karachi, Islamabad, Faislabad, Multan, …}
Sets can contain non-related elements as well, {red, 5, Ali}
We’ll use set of numbers
• Set of all Prime numbers: {1,3,5,7, ….}
• Set of Natural Numbers: {1,2,3,4,5,6,7…}
• Set of Whole Numbers: {0,1,2,3,4,5,6,7, …..}
Properties of Sets
Order does not matter: {1,2,3,4,5} is equivalent to {2,5,4,1,3}
Does not have duplicate elements, always Unique/ distinct elements
• Such as list of students ID in class
Elements of a Set
Element: An object in a set is called an element.
A set contains the various members or elements that makeup the set
Membership: If an object x is in a set A, we write x ∈ A.
• Example: 2 ∈ {1, 2, 3} means 2 is an element of the set.
• If an object is not in the set, we write x ∉ A.
• Example: 4 ∉ {1, 2, 3}.
Specifying a Set
Set Name should be in capital letters (A,B,C,S,….)
A={1,2,3,4,…} B={a,e,i,o,u}
Set elements should be represent in small case letters (a,x,y,…)
Its easiest way to list elements if finite i.e. A={1,2,3,4,5}
For infinite set: use Ellipsis (…) i.e. B =
{0,1,2,3, …..}
• Ellipsis may cause confusion: what's Next??? i.e. C = {3,5,7,….}
Set Notations
Roster Notation: also called List Notation : Useful when there is a small or finite number of
elements.
List all elements of the set inside curly braces.
Syntax: 𝑆={element 1, element 2, element 3, ...}
Example: Set of prime numbers less than 10: 𝑃={2,3,5,7}
Set Builder Notations: Useful for describing sets with infinite elements or when listing
elements is impractical.
we describe the properties that the elements of the set satisfy, instead of listing them explicitly.
Syntax: S={x ∣ condition on x} where: 𝑥 is a variable representing the elements of the set.
The condition on 𝑥 specifies which elements are included.
Examples: The set of all integers greater than 0:
• 𝑆={𝑥 ∣ 𝑥 > 0 , 𝑥 ∈ 𝑍} Read as x such that x is greater than 0, where x belongs to Z
• The set of even numbers: 𝐸={𝑥 ∣ 𝑥 is an even number}
Examples of Set Builder Notations:
Examples of Set-Builder Notation
Finite Set: The set of integers between 1 and 5:
• S={x ∣ 1 ≤ x ≤ 5 , x ∈ Z}
• Equivalent in roster form: S={1,2,3,4,5}
Infinite Set: The set of positive real numbers:
R+={x ∣ x > 0, x ∈ R}
• This is an infinite set, and we can’t list all elements.
Most Common sets
Types of Sets
• Finite Set: A set with a limited number of elements.
• Example: A = {1, 2, 3}.
• Infinite Set: A set with an unlimited number of elements.
• Example: The set of natural numbers N = {1, 2, 3, ...}.
• Empty Set: A set with no elements, denoted by ∅ or {}.
Class Activity
Write each of the following sets by listing their elements
between braces
Class Activity
write following set in set builder notation
1. {0, 3, 6, 9, 12}
2. {−3,−2,−1, 0, 1, 2, 3}
3. {m, n, o, p}
Empty Set
contains no elements. It is a set with Zero elements, called Null / Empty
Set
Written using the symbol ∅ or A={}
∅ ≠ {∅} , where ∅ means zero elements and { ∅} means 1 elements
If replace ∅ with {} then : {} ≠ { { } }
The cardinality (number of elements) of the empty set is 0.
It can be an element of other sets:
A= {∅, 1, 2, 3,x}
Example 1: The set of all natural numbers less than 0.
S={x ∣ x < 0 , x ∈ N } = ∅
Types of Sets
• Universal Set (U): The set containing all possible elements under
consideration.
• Example: U = {1, 2, 3, 4, 5}.
• Subset (⊆): A set A is a subset of set B if all elements of A are also
elements of B.
• Example: A = {1, 2}, B = {1, 2, 3}, A ⊆ B.
• Power Set: The set of all subsets of a set A.
• Example: If A = {1, 2}, then the power set of A is P(A) = {∅, {1}, {2}, {1,
2}}.
Universal Set
Subset – Set of Sets
Subset – Set Equality
Types of Subsets
Proper Subset
• A set A is a proper subset of set B, denoted by A ⊂ B, if every element of
A is also in B, and A ≠ B (i.e., A is strictly smaller than B).
• Example:
• Let A = {1, 2} and B = {1, 2, 3}.
• A ⊂ B because all elements of A are in B, and A is not equal to B.
Improper Subset
• Every set is a subset of itself, and this is called an improper subset.
• It is denoted by A ⊆ A.
• Example:
• If A = {1, 2, 3}, then A ⊆ A is true because every element of A is in A.
Proper Subsets
Power Set
Types of Sets
Disjoint Sets
• Two sets A and B are disjoint if they have no elements in common.
• In other words, A ∩ B = ∅ (empty set).
• Example:
• Let A = {1, 2, 3} and B = {4, 5, 6}.
• Since A and B share no elements, A and B are disjoint sets.
Types of Sets
Singleton Set: A set that contains exactly one element is called a
singleton set.
• Example:
• Let A = {5}.
• A is a singleton set because it has only one element.
Class Activity
Write Power set of
{1}
1
A tree listing of subset
Cardinality of set
the number of elements contained in the set.
It represents the "size" of the set.
If 𝐴 is a set, the cardinality of 𝐴 is denoted by ∣𝐴∣
Example:
For the set 𝐴={1,2,3} the cardinality is: ∣𝐴∣=3
For set B={1,2,3,4….} the cardinality is: ∣B∣= ∞
For empty sets its ∣∅∣=0
If 𝐴={1,2} and 𝐵={𝑥,𝑦,𝑧} then:
• ∣𝐴×𝐵∣ = ∣𝐴∣ × ∣𝐵∣ = 2 × 3 = 6
Tuples
Unlike sets, Tuples are ordered
In 2D Space, it’s a (x,y) pair of numbers to specify a location
i.e. x has to come first in order then y
In 3D space, it’s a triple of number to specify a location (x,y,z)
(1,2,3) is not same as (3,2,1)
In n-Dimensional space, it’s a n-tuple of numbers
2D Space: use pairs or 2 Tuple
3D Space: use Triple or 3 tuples
Cartesian Product
The Cartesian product of two sets A and B, denoted by A × B,
is the set of all ordered pairs (a, b) where a belongs to A and b belongs to B.
Notation: 𝐴×𝐵 = {(𝑎,𝑏) ∣ 𝑎∈𝐴 and 𝑏∈𝐵}
Cartesian Product
Let A = {1, 2} and B = {x, y}.
Then, the Cartesian product A × B is:
𝐴×𝐵={ (1,𝑥), (1,𝑦), (2,𝑥), (2,𝑦) }
Each pair consists of one element from set A and one element from set B.
SO does 𝐴×𝐵 is equivalent to 𝐵 × 𝐴
Let A = {1, 2}.
The Cartesian product A × A is:
A×A = { (1,1), (1,2), (2,1), (2,2) }
Activity - Cartesian Product
Let A = {1, 2, 3, 4} and B = {a, b, c}. Find 𝐴×𝐵 and 𝐵 × 𝐴
Find the followings and also sketch them
1. {1,2} x {-1,2}
2. NxN
3. RxR
4. ZxZ
5. RxN
6. NXZ
Cartesian product in Real Life
• Cartesian product is used in combinations like:
• Coordinates: For a coordinate system, the x-axis values form one set and the y-
axis values form another set. The Cartesian product gives all the points on the
plane:
• Let X = {1, 2, 3} and Y = {4, 5}.
• The Cartesian product X × Y would give all the points on a 2D plane: (1, 4), (1, 5), (2,
4), (2, 5), (3, 4), (3, 5).
• Product Options: For a product with different color and size options:
• Colors: C = {Red, Blue}
• Sizes: S = {Small, Medium}
• Cartesian product C × S gives all possible product combinations: (Red, Small), (Red,
Medium), (Blue, Small), (Blue, Medium).
Set Identities
Venn diagrams
a set can be visualized with a circle, which we regard as enclosing all the elements of the set.
Such diagrams can illustrate how sets combine using various operations
To Visualizing Sets and set operations:
Graphical representation of sets
• Box: Universal set of English Alphabets
• Circle: Set of vowels
Use to visually represent union, intersection, and difference.
Note: individual elements are usually not written in a venn Diagram
Examples in coming slides: A Venn diagram illustrating A ∪ B, A ∩ B, and A - B.
Venn diagrams
How to make a Venn diagram for
set AUB is shaded with horizontal lines while C is
shaded with vertical lines
How to make a Venn diagram for
The set A is shaded with horizontal lines, and B∩C is
shaded with vertical lines
Draw Venn Diagram of
𝐴=𝑈 − 𝐴, 𝑊h𝑖𝑐h 𝑚𝑒𝑎𝑛𝑠𝑎𝑙𝑙𝑒𝑙𝑒𝑚𝑒𝑛𝑡𝑠𝑜𝑓 𝑈 𝑤h𝑖𝑐h 𝑎𝑟𝑒𝑛𝑜𝑡 𝑖𝑛 𝐴
U A
Draw Venn Diagram of B-A
Draw Venn Diagram of
Set Operators
• Union (∪): The union of two sets A and B is a set containing all elements of A and B.
• Notation: A ∪ B.
• Example: If A = {1, 2, 3} and B = {3, 4, 5}, then A ∪ B = {1, 2, 3, 4, 5}.
• Intersection (∩): The intersection of two sets A and B is a set containing all elements that are
both in A and B.
• Notation: A ∩ B.
• Example: If A = {1, 2, 3} and B = {3, 4, 5}, then A ∩ B = {3}.
• Difference (or Relative Complement) (A - B): The difference of sets A and B is a set
containing all elements that are in A but not in B.
• Notation: A - B.
• Example: If A = {1, 2, 3} and B = {3, 4, 5}, then A - B = {1, 2}.
• Complement (A'): The complement of a set A refers to all elements in the universal set U
that are not in A.
• Notation: A'.
• Example: If U = {1, 2, 3, 4, 5} and A = {1, 2, 3}, then A' = {4, 5}
Shaded Area of diagram Represents AUB
Set Operation: Union
Set Operation: Intersection
Shaded Area of diagram Represents A ∩ B
Set operations: Relative Difference
• The relative difference (or set difference) of two sets A and B, denoted
by A - B,
• is the set of all elements that are in A but not in B.
• Notation: A−B={x ∣ x ∈ A and x ∉ B}
• Example:
• Let A = {1, 2, 3, 4} and B = {3, 4, 5}.
• The relative difference A - B is: A−B={1,2}A−
• These are the elements that are in A but not in B.
Set operations: Symmetric Difference
The symmetric difference of two sets A and B, denoted by A △ B , A delta B
is the set of elements that are in either A or B, but not in both.
A△B= (A∪B) − (A∩B) Or A△B= (A-B) ∪ (B-A)
For example,
the symmetric difference of the sets {1,2,3} and{3,4} is {1,2,4}
Set operations: Complement of a set
Set Operations
Class Activity
Suppose A = {4,3,6,7,1,9}, B={5,6,8,4} and C ={5,8,4}, find the
followings
1. AUB
2. A
3. C-B
4. B-C
Membership Tables
A membership table represents whether each element of the universal
set is a member of given sets.
• If an element belongs to a set, we denote this with a 1.
• If an element does not belong to a set, we denote this with a 0.
• Example:
• Let the universal set be U = {1, 2, 3, 4, 5}.
• Let A = {1, 3, 5} and B = {2, 3, 4}.
• Table Setup: Elements of the universal set will form rows, and each set
(A, B) will form columns.
• For element 1, since it is in set A but not in B, the row is 1 0.
• For element 2, since it is in B but not in A, the row is 0 1.
• This continues for all elements of the universal set.
Operations Using Membership Tables
Union of Sets:
• A ∪ B represents the elements that are in either A or B (or both).
• In the membership table, A ∪ B takes the value 1 if either A or B has a 1.
Intersection of Sets:
A ∩ B represents the elements that are in both A and B.
• In the membership table, A ∩ B takes the value 1 only if both A and B
have a 1.
• Complement of Set A:
• A' represents all the elements that are in the universal set but not in A.
• In the membership table, A' takes the value 1 if A has a 0, and 0 if A has a
1.
Operations Using Membership Tables
Difference of Sets:
• A - B represents the elements that are in A but not in B.
• In the membership table, A - B takes the value 1 if A has a 1 and B has a 0.
Symmetric Difference:
• A △ B represents the elements that are in A or B, but not in both.
• In the membership table, A △ B takes the value 1 if A and B have different
values.
Activity – Membership Tables
1. You are given a universal set U and two smaller sets A and B.
2. Use these sets to fill out the membership tables for the following set operations:
1. Union (A ∪ B)
2. Intersection (A ∩ B)
3. Difference (A - B and B - A)
4. Symmetric Difference (A △ B)
3. Once you complete your table, compare your answers with a partner or group.
Universal Set (U): 𝑈={1,2,3,4,5,6}
Set A: 𝐴={1,2,4}
Set B: 𝐵={2,3,5}
Using Set Identities
Number of Subsets (Section 1.3 of book)
1
A Decision Tree counts the # of leaf nodes
n
i.e. 2
Popup Quiz:
An alternate way to count and represent subset (through binary strings)
Suppose we want to know what will be 223rd subset of a set with 10
elements
Where we have list down all subsets in particular order.
How to list???
Lets start with a set of 3 elements i.e. {a, b, c}
Subsets using binary strings
Lets start with a set of 3 elements i.e. {a, b, c}
Encode the subsets with binary strings:
If an element is present in the subset
• Mark it by 1
If an element is not present in the subset
• Mark as 0
Example:
{a,c} 101 Since a and c are in the subset so we marked both as 1
{b} 010 Since a and c are not in the subset so we marked both as 0
{a,b,c} 111
“n” number of Subsets using binary strings
Lets see how to do it for n elements, where n could be any number
For length n
We can represent 2n Numbers i.e. ( 0 to 2n - 1)
A set with n elements have 2n Number of subsets
Length of binary strings Number of combinations allowed
Length 3 8 - (0-7) => 23
Length 4 16 - (0-15) =>24
Length 5 32 - (0-31) =>25
Length 10 1024 - (0-1023) =>210
n n
Length n 2 - (0 – 2 -1)
“n” number of Subsets using binary strings
Suppose we want to know what will be 223rd subset of a set with 10
elements
The binary of 223 is (00 1101 1111)2
If , … are the ten elements of set
Then 223rd subset consist of following elements:
(, , , )
As we Encode the subsets with binary strings:
• If an element is present, we mark it by ONE, if not present we put ZERO
This is call one –one correspondence or Bijection
Sequences (Section 1.5 of book)
Suppose we want to determine the number of strings of length n for set containing
elements {a,b,c}
1. The set {a,b,c}has 3 elements: 'a', 'b', and 'c'.
2. Each position in the string of length n can be filled with any one of these 3 elements.
3. Since there are 3 possible choices for each position in the string, for a string of length n,
there are 3 choices for the first position, 3 choices for the second position, and so on, up to
n positions.
Thus, the total number of strings is calculated by multiplying the number of choices
for each position.
Formula: Number of strings=3n
Sequence: Example
If n=2 the number of strings of length 2 is: 3 2=9
9 possible strings are: aa, ab, ac, ba, bb, bc, ca, cb, cc
If n=3 the number of strings is: 33 = 27
These would include strings like: aaa, aab, aac, …s, ccc
So, the general rule is that for any string length n, the number of
possible strings is 3n.
Number of Subsets (Section 1.3 of book)
How many subsets of empty set ∅?
empty set has no elements (n=0), the number of subsets is:
20=1
Thus, the empty set has exactly 1 subset, which is the empty set itself.
Number of Subsets (Section 1.3 of book)
How many subsets of single element, A={a}?
The set has n=1 element. Thus, the number of subsets is: 2 1=2
The subsets are: The empty set and the set {a} itself
Subset of A= {∅, {a} }
Number of Subsets (Section 1.3 of book)
How many subsets of single element, X={a, b}?
The set has n=2 element. Thus, the number of subsets is: 2 2 = 4
The subsets are: Subset of X = {∅, {a} , {b} , {a,b}}
Fuzzy Set
a set where each element has a degree of membership ranging from 0 to
1.
Unlike classical (crisp) sets where an element either belongs to a set or
doesn’t, fuzzy sets allow partial membership.
Example:
In a set of "tall people", some individuals may be considered "partially
tall" based on their height.
Fuzzy vs Crisp Sets
Crisp Sets:
Elements either fully belong to a set or do not belong at all.
Example: In the set of "people taller than 6 feet", anyone taller than 6 feet
is included, others are excluded.
Fuzzy Sets:
Allows for degrees of membership.
Example: In the fuzzy set of "tall people", someone 5’10” might have a
membership value of 0.7, indicating they are "somewhat tall".
Membership Function
The membership function 𝜇𝐴(𝑥) represents the degree of membership of
element 𝑥 in set 𝐴.
It assigns each element a value between 0 and 1.
Formula: (𝐴 𝑥):𝑋→[0,1]
Where 𝑋 is the universal set and [0,1] represents the range of membership
values.
Example: If 𝐴 is the fuzzy set "tall people":
𝜇𝐴(person 1)=0.8,(person
𝐴 2)=0.3
Example of a Fuzzy Set
Fuzzy set of "warm temperatures".
Membership Function:
Interpretation:
At 60°F, the membership is 0 (not warm).
At 80°F, the membership is 1 (fully warm).
Between 60°F and 80°F, temperatures are "partially warm."