0% found this document useful (0 votes)
34 views

4 Sets

Sets are fundamental discrete structures that represent collections of objects. Sets can be represented using roster notation or set-builder notation. Standard set operations include union, intersection, difference, and complement. Venn diagrams provide a visual representation of relationships between sets using regions to represent elements contained in each set. Set identities can be used to prove relationships between operations on sets.

Uploaded by

Umar Draz
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)
34 views

4 Sets

Sets are fundamental discrete structures that represent collections of objects. Sets can be represented using roster notation or set-builder notation. Standard set operations include union, intersection, difference, and complement. Venn diagrams provide a visual representation of relationships between sets using regions to represent elements contained in each set. Set identities can be used to prove relationships between operations on sets.

Uploaded by

Umar Draz
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/ 53

Sets

Introduction
• In this section, we study the fundamental discrete structure on which all other
discrete structures are built, namely, the set.

Why to study sets?


• Data structures should be thought of as implementations of sets with
particular focus on efficient implementations of set operations

• In database theory, the notion of a relational database is that of seeing a


database as a relation over sets.

• In formal language theory, a language is a set of strings and the study of


operations on languages is central.
• Some of these are the usual set operations of intersection, union and complement

• In programming language semantics, semantic domains are sets with structure


Sets Theory
• Set: Collection of ordered or unordered objects (called elements)
• aA “a is an element of A”
“a is a member of A”
• aA “a is not an element of A”

• A = {a1, a2, …, an} “A contains a1, …, an”


• Order of elements is insignificant
• It does not matter how often the same element is listed (repetition
doesn’t count).
Set Theory
• It is common for sets to be denoted using uppercase letters.

• Lowercase letters are usually used to denote elements of sets.


Methods to represent Sets
Roster method
• use a notation where all members of the set are listed between braces.
• For example; set of vowels. V = {a, e, i, o, u}.

• Although sets are usually used to group together elements with common
properties, there is nothing that prevents a set from having seemingly
unrelated elements.

• For instance, {a, 2, Fred, New Jersey} is the set containing the four elements a, 2,
Fred, and New Jersey.
Methods to represent Sets
set builder notation
• characterize all those elements in the set by stating the property or
properties they must have to be members.

• the set O of all odd positive integers less than 10 can be written as
O = {x | x is an odd positive integer less than 10},
Examples for Sets
Standard” Sets:
• Natural numbers N = {0, 1, 2, 3, …}
• Integers Z = {…, -2, -1, 0, 1, 2, …}
• Positive Integers Z+ = {1, 2, 3, 4, …}
• Real Numbers R = {47.3, -12, , …}
• Rational Numbers Q = {1.5, 2.6, -3.8, 15, …}
Set Equality
•Sets A and B are equal if and only if they contain exactly the
same elements.
Examples:
•A = {9, 2, 7, -3}, B = {7, 9, -3, 2} : A=B

• A = {dog, cat, horse},


A≠B
B = {cat, horse, rabbit, dog} :

•A = {dog, cat, horse}, A=B


B = {cat, horse, dog, dog} :

8
Cartesian Product

Example:
•A = {good, bad}, B = {student, prof}
•AB = {
(good, student), (good, prof), (bad, student), (bad, prof)}

(prof, good), (student, bad), (prof, bad)}


B  A = { (student, good),

Example:

A = {x, y}, B = {a, b, c}

A  B = {(x, a), (x, b), (x, c), (y, a), (y, b), (y, c)} 9
Example
What is the Cartesian product of A = {1, 2} and B = {a, b, c}?
Solution: The Cartesian product A × B is
A × B = {(1, a), (1, b), (1, c), (2, a), (2, b), (2, c)}.

Show that the Cartesian product B × A is not equal to the Cartesian


product A × B, where A and B are as in above Example.

Solution: The Cartesian product B × A is

B × A = {(a, 1), (a, 2), (b, 1), (b, 2), (c, 1), (c, 2)}. This is not equal to A × B
Example
• What is the Cartesian product A × B × C, where A = {0, 1}, B = {1, 2},
and C = {0, 1, 2} ?

Solution: The Cartesian product A × B × C

A × B × C = {(0, 1, 0), (0, 1, 1), (0, 1, 2), (0, 2, 0), (0, 2, 1), (0, 2, 2),
(1, 1, 0), (1, 1, 1), (1, 1, 2), (1, 2, 0), (1, 2, 1), (1, 2, 2)}.
Empty Set and Singleton Set
• There is a special set that has no elements. This set is called the
empty set, or null set, and is denoted by ∅.

• The empty set can also be denoted by { }

• A set with one element is called a singleton set. A common error is to


confuse the empty ∅ with the set {∅}, which is a singleton set.

• The single element of the set {∅} is the empty set itself
Cardinality of Sets

• If a set S contains n distinct elements, we call S a finite set with cardinality n.


Examples:
A = {Mercedes, BMW, Porsche},
|A| = 3
B = {1, {2, 3}, {4, 5}, 6},
|B| = 4
C = Ø or {}
|C| = 0
D = { x  N | x ≤ 7000 }
|D| = 7001
E = { x  N | x ≥ 7000 }
E is infinite!
The Power Set
• P(A) “power set of A” (also written as 2A)

Examples:

• A = {x, y, z}
P(A) = {, {x}, {y}, {z}, {x, y}, {x, z}, {y, z}, {x, y, z}}
Example
• What is the power set of the set {0, 1, 2}?

Sol:
P({0, 1, 2}) = {∅, {0}, {1}, {2}, {0, 1}, {0, 2}, {1, 2}, {0, 1, 2}}.

• What is the power set of the empty set?


Sol:
P({∅}) = {∅, {∅}}.
Subsets
• Useful rules:
• A = B  (A  B)  (B A)
• (A  B) (B  C)  A  C (see Venn Diagram)

B
A C

16
Example
List the members of these sets.
a) {x | x is a real number such that X2 = 1}
b) {x | x is a positive integer less than 12}
c) {x | x is the square of an integer and x < 100}
d) {x | x is an integer such that X2 = 2}
Sol:

a) {1,-1}
b) {1,2,3,4,5,6,7,8,9,10,11}
c) { 1, 4, 9, 16, 25, 36, 49, 64, 81}
d) ∅( √2 is not an integer)
Example
Use set builder notation to give a description of each of these sets.
a) {0, 3, 6, 9, 12}
b) {−3,−2,−1, 0, 1, 2, 3}
c) {m, n, o, p}
Sol:
Example
For each of these pairs of sets, determine whether the first is a subset of the
second, the second is a subset of the first, or neither is a subset of the other.
a) the set of airline flights from NewYork to New Delhi, the set of nonstop
airline flights from New York to New Delhi
b) the set of people who speak English, the set of people who speak Chinese
c) the set of flying squirrels, the set of living creatures that can fly.
Example
For each of these pairs of sets, determine whether the first is a subset of the
second, the second is a subset of the first, or neither is a subset of the other.
a) the set of people who speak English, the set of people who speak English
with an Australian accent
b) the set of fruits, the set of citrus fruits
c) the set of students studying discrete mathematics, the set of students
studying data structures
Sol:
Example
Determine whether each of these pairs of sets are equal.
a) {1, 3, 3, 3, 5, 5, 5, 5, 5}, {5, 3, 1}
b) {{1}}, {1, {1}}
c) ∅, {∅}

Sol:
a) Yes; order and repetition do not matter.
b) No; the first set has one element, and the second has two elements.
c) No; the first set has no elements, and the second has one element
(namely the empty set).
Example
Suppose that A = {2, 4, 6}, B = {2, 6}, C = {4, 6}, and D = {4, 6, 8}.
Determine which of these sets are subsets of which other of these
sets.

Sol:

B is subset of A
C is subset of both A and D
Example
For each of the following sets, determine whether 2 is an element of
that set.
a) {x ∈ R | x is an integer greater than 1}
b) {x ∈ R | x is the square of an integer}
c) {2,{2}}
d) {{2},{{2}}}
e) {{2},{2,{2}}}
f ) {{{2}}}
Example (class Test)
Suppose that A × B = ∅, where A and B are sets. What can you conclude?

Find A2 if:
a) A = {0, 1, 3}.
b) A = {1, 2, a, b}.
Find A3 if:
a) A = {a}.
b) A = {0, a}.
What is the cardinality of each of these sets?
a) {a}
b) {{a}}
c) {a, {a}}
d) {a, {a}, {a, {a}}}
Example (class Test)
Determine whether each of these sets is the power set of a set,
where a and b are distinct elements.
a) ∅
b) {∅, {a}}
c) {∅, {a}, {∅, a}}
d) {∅, {a}, {b}, {a, b}}
Set Operations
• Union
• Intersection
• Disjoint
• Compliment
• Difference
• Venn diagram representations
• Set identities
Set Operations
Union: AB = {x | xA  xB}

Example: A = {a, b}, B = {b, c, d}


AB = {a, b, c, d}

Intersection: AB = {x | xA  xB}

Example: A = {a, b}, B = {b, c, d}


AB = {b}
Cardinality: |AB| = |A| + |B| - |AB|
Venn diagram of Union & Intersection
Set Operations
Disjoint: Two sets are called disjoint if their intersection is
empty, that is, they share no elements: AB = 

Example :
Let A = {1, 3, 5, 7, 9} and B = {2, 4, 6, 8, 10}

A∩B=∅
Set Operations

Difference: The difference between two sets A and B contains exactly


those elements of A that are not in B:

A-B = {x | xA  xB}

Example: A = {a, b}, B = {b, c, d}


A-B = {a}
B-A= {c,d}

Cardinality: |A-B| = |A| - |AB|


Set Operations
Complement: The complement of a set A contains exactly those elements under
consideration that are not in A: denoted Ac

Example: B = {250, 251, 252, …}


Bc = {0, 1, 2, …, 248, 249}

Let U be the universal set. The complement of the set A, denoted by A, is the
complement of A with respect to U. Therefore, the complement of the set A is U - A.

Example: U = {3, 5, 7, 8, 9, 10, 12}


A = {8, 9, 10, 12}
Ac = {3, 5, 7}
Example
• Let A = {a, e, i, o, u} (where the universal set is the set of letters of the
English alphabet). Find A compliment.
Practice Task

Find:
a) A – B
b) B – A
c) A – C
d) C –A
e) A –A
f) U –A
Practice Task
• Let A be the set of students who live within one mile of school and let
B be the set of students who walk to classes. Describe the students in
each of these sets.
a) A ∩ B
b) A ∪ B
c) A – B
d) B - A
Set Proof
• Use a membership table to show that A ∩ (B ∪ C) = (A ∩ B) ∪ (A ∩ C).
Set Identities
Set Identities
Proof by Set Identities
Example
• Let A, B, and C be sets. Show that

Solution: We have
Generalized Unions and Intersections
• Because unions and intersections of sets satisfy associative laws, the sets A
∪ B ∪ C and A ∩ B ∩ C are well defined

• we do not have to use parentheses to indicate which operation comes first


because A ∪ (B ∪ C) = (A ∪ B) ∪ C and A ∩ (B ∩ C) = (A ∩ B) ∩ C.

Note that A ∪ B ∪ C contains those elements that are in at least one of the
sets A, B, and C, and that A ∩ B ∩ C contains those elements that are in all of
A, B, and C.
Venn representation of Generalized Unions and Intersections
Example

• Let A = {0, 2, 4, 6, 8}, B = {0, 1, 2, 3, 4}, and C = {0, 3, 6, 9}. What are A ∪ B ∪ C
and A ∩ B ∩ C?

The set A ∪ B ∪ C contains those elements in at least one of A, B, and C. Hence,

A ∪ B ∪ C = {0, 1, 2, 3, 4, 6, 8, 9}.

The set A ∩ B ∩ C contains those elements in all three of A, B, and C. Thus,

A ∩ B ∩ C = {0}
Computer Representation of Sets
• There are various ways to represent sets using a computer.

• One method is to store the elements of the set in an unordered fashion.


• However, if this is done, the operations of computing the union, intersection,
or difference of two sets would be time consuming,
• because each of these operations would require a large amount of searching for
elements.
• Specify an arbitrary ordering of the elements of U, for instance a1, a2, . . . ,
an. Represent a subset A of U with the bit string of length n,
• where the ith bit in this string is 1 if ai belongs to A and is 0 if ai does not belong to A.
Example 18 illustrates this technique.
Example
Let U = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, and the ordering of elements of U has the elements in
increasing order; that is, ai = i.
a) What bit strings represent the subset of all odd integers in U?
b) What is subset of all even integers in U?
c) What is subset of integers not exceeding 5 in U?
Sol:
d) The bit string that represents the set of odd integers in U, namely, {1, 3, 5, 7, 9}, has a one
bit in the first, third, fifth, seventh, and ninth positions, and a zero elsewhere. It is 10 1010
1010.
e) we represent the subset of all even integers in U, namely, {2, 4, 6, 8, 10}, by the string 01
0101 0101.
f) The set of all integers in U that do not exceed 5, namely, {1, 2, 3, 4, 5}, is represented by
the string 11 11100000.
Example
• We have seen that the bit string for the set {1, 3, 5, 7, 9} (with universal set
{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}) is 10 1010 1010.
What is the bit string for the complement of this set?
Sol:

The bit string for the complement of this set is obtained by replacing 0s with
1s and vice versa. This yields the string 01 0101 0101, which corresponds to
the set {2, 4, 6, 8, 10}.
Example
• The bit strings for the sets {1, 2, 3, 4, 5} and {1, 3, 5, 7, 9} are 11 1110 0000 and
10 1010 1010, respectively. Use bit strings to find the union and intersection of
these sets.

Sol:
• The bit string for the union of these sets is
11 1110 0000 ∨ 10 1010 1010 = 11 1110 1010 , which corresponds to the set {1, 2, 3,
4, 5, 7, 9}.

• The bit string for the intersection of these sets is


11 1110 0000 ∧ 10 1010 1010 = 10 1010 0000 , which corresponds to the set {1, 3, 5}.
Venn Diagrams Example
Set of ten Friends {a, b, c, d, e, f, g, h, i, j}
• Each friend is an "element" (or "member") of the set.
• Soccer = {a, c, d, h}
• Tennis = {c, d, j}

Soccer Tennis

a,c,d,h C,d,j
Example Cont… Union

Soccer ∪ Tennis = {a, c, d, h, j}

Soccer Tennis Soccer Tennis


c,d
a,c,d,h C,d,j a,h j
Example Cont… Intersection
• Soccer = {a, c, d, h}
• Tennis = {c, d, j}
Soccer ∩ Tennis = {c, d}

Soccer Tennis Soccer c,d Tennis

a,c,d,h C,d,j
Example Cont… Difference
• Soccer = {a, c, d, h}
• Tennis = {c, d, j}
Soccer - Tennis = {a, h}

Soccer
Soccer Tennis Tennis
a, h
a,c,d,h C,d,j
Example
• Prove the first absorption law by showing that if A and B are sets,
then A ∪ (A ∩ B) = A.

• Let A= {1,2,3,4}, B= {4,5,6,7}


A ∩ B = { 4 }
A ∪ (A ∩ B) = {1,2,3,4}

Hence, A ∪ (A ∩ B) = A.
Example
• Find the sets A and B if A - B = {1, 5, 7, 8}, B - A = {2, 10}, and A ∩ B = {3, 6, 9}.

Sol:

A= { 1, 3, 5, 6, 7, 8, 9}
B= { 2, 3 , 6 , 9 , 10}
Example
• Prove the second De Morgan law by showing that if A and B are sets,
then (by showing each side is a subset of the other
side).
Thank You

You might also like