0% found this document useful (0 votes)
33 views39 pages

Lecture 02 - Set and Operations

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views39 pages

Lecture 02 - Set and Operations

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 39

Lecture – 03

Set and its Operations

Discrete Structures (CSAL-1213)


Course Instructor: Hina Alam
Cardinality of Set
Cardinality of set
“The number of distinct 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


Example

#include <iostream>
A= {1, 2, 3, 4…….99, 100} |A| #include <set>
=100 int main() {
// Define a set with some elements
B= {2, 4, 6}; |B| std::set<int> mySet = {10, 20, 30, 40};
=3
// Find the cardinality (size) of the set
C= {{1}}; | int cardinality = mySet.size();
C|=1
// Output the cardinality
D= {2, {21}}; std::cout << "The cardinality of the set is: " << cardinality <<
std::endl;
|D|=2
return 0;
}
The cardinality of the set is: 4
Here 2 and {21} are the two
elements of set D.
Activity

Teacher collects submissions from students but notices that some students submitted
more than once. How can the teacher determine the actual number of students who
submitted?

A store manager has a list of product IDs for every item on the shelves. How can the
manager determine the total number of different products in the store?
Activity
Activity - Solution

2^n

Example

If a set A={1,2,3} has n=3 elements, then the power set of A has:

2^3 = 8
subsets, which are:

{},{1},{2},{3},{1,2},{1,3},{2,3},{1,2,3}.

So, the power set of a set with n elements has 2^n subsets in total.
Cartesian Product
Cartesian Product
The Cartesian product of two sets A and B,
denoted by A × B,
The Cartesian Product of two sets A and B is the set of all possible ordered pairs where the first element is
from A and the second element is from B.

▪ Notation: 𝐴×𝐵 = {(𝑎,𝑏) ∣ 𝑎∈𝐴 and 𝑏∈𝐵}


Mathematically, it’s represented as:

▪ In simpler terms, the Cartesian Product combines every element of A with


every element of B in pairs.
Cartesian Product
****RULE: 𝐴×𝐵 is not equivalent to 𝐵
×𝐴
In the ordered pair (2,3), 2 is the first element, and 3 is the second element.

● Here, (2,3) ≠ (3,2)


A = {good, bad}, B = {student, prof}

A×B = { (good, student), (good, prof), (bad, student), (bad, prof) }

B×A = {(student, good), (student, bad), (prof, good), (prof, bad)}

● Here, (good ,student) ≠ (student, good)

****RULE: 𝐴×𝐵 is equivalent to 𝐵 × 𝐴 if


A==B
A = B= {1,2} or A = {1,2}, B = {1,2}

Cartesian Products

1. A×B ={(1,1),(1,2),(2,1),(2,2)}
2. B×A={(1,1),(1,2),(2,1),(2,2)}

● In this case, both products yield the same set of ordered pairs:

A×B = B×A= {(1,1),(1,2),(2,1),(2,2)}


Cartesian Product

𝐴={1,2}
𝐵={𝑥,𝑦,𝑧} then:
∣𝐴×𝐵∣ = ∣𝐴∣ × ∣𝐵∣
=2×3
=6
Cartesian Product - Example

▪ Let A = {1, 2} and B = {x, y}

▪ Cartesian product A × B is:


▪ 𝐴×𝐵={ (1,𝑥), (1,𝑦), (2,𝑥), (2,𝑦) }
Each pair consists of one element from set A and one element
from set B.

▪ Let A = {1, 2}.


▪ Cartesian product A × A is:
▪ A×A = { (1,1), (1,2), (2,1), (2,2) }
Activity - Cartesian Product

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).
Tuples
Cartesian Product
Tuples
▪ Unlike sets, Tuples are ordered
When we say that tuples are ordered, it means that the sequence in which the elements of the tuple are
arranged is important. The position of each element matters, and changing the order of the elements will result
in a different tuple.

▪ 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
Ordered pair v/s Tuples

Feature Ordered Pair Tuple

Number of Always contains exactly two elements (e.g., (a,b)) Can contain any number of elements (e.g., (a,b,c) or (a,b,c,d))
Elements

Notation Written as (a,b) Written as (a1,a2,a3,…,an) where n can vary

Dimensions Specifically a 2D structure Can represent n-dimensional structures (e.g., 1D, 2D, 3D, etc.)

Context of Often used in mathematics and coordinate systems Used in various fields, including programming and
Use
data representation
Order The order of the two elements is significant; changing The order of the elements is significant; changing
the order creates a different pair the order creates a different tuple
Example (3,4) (1,2,3) or (a,b,c,d)

Summary

● An ordered pair (a, b) is a specific case of a tuple that contains exactly two elements, while a tuple can contain any number of
elements.
● Ordered pair (a, b) represents a relationship between the two values
● Both are ordered, meaning that the arrangement of elements matters, but tuples are more versatile in terms of the number of elements
they can include.
Set Operators
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

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}.
Union of sets
Set Operators
• 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}.
Set Operators
• Difference (or Relative Difference) (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 ={x ∣ x ∈ A and x ∉ B}

Example:
If A = {1, 2, 3} and B = {3, 4, 5},
then A - B = {1, 2}
Draw Venn Diagram of B-A
Set operations: Symmetric Difference
▪ The symmetric difference of two sets A and B, denoted by A △ B or
A\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 Operators
Complement (A' or Ac):
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}

U A
Set operations: Complement of a
set
Class Activity


Set Identities
Set Identities - Self study
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

You might also like