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

CS202 CH 2

The document discusses sets and basic set operations like union, intersection, difference, and complement. It defines these operations and gives examples to illustrate them. The document also covers concepts like disjoint sets, identities for set operations, and using quantifiers with sets.

Uploaded by

Badr
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views

CS202 CH 2

The document discusses sets and basic set operations like union, intersection, difference, and complement. It defines these operations and gives examples to illustrate them. The document also covers concepts like disjoint sets, identities for set operations, and using quantifiers with sets.

Uploaded by

Badr
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 78

CS202

Discrete Maths

Chapter 2, Section 2.1


Sets

These class notes are based on material from our


textbook, Discrete Mathematics and Its
Applications, 6th ed., by Kenneth H. Rosen. They are
intended for classroom use only and are not a
substitute for reading the textbook.
Sets

• A set is an unordered collection of objects.


• The set is the fundamental discrete
structure on which all other discrete
structures are built.
• The objects in a set are called its elements,
or members.
• A set is said to contain its elements.
Set Notation

• We normally use upper-case letters to


represent the names of sets, and lower-case
letters to represent their elements.
• To denote that a is an element of set S we
write: a  S
• To denote that a is not an element of set S
we write: a  S
How to Describe a Set

• We can describe a set in two ways:


– List all of its elements
– Give a set of rules that characterize all of
the members of the set (set builder
notation)
Listing the Elements of a Set
• To list the members of a set, we use curly braces,
separating each element from the next with a
comma.
• Example: the set of all vowels in the English
language is the set
V = {a, e, i, o, u}
• We can use ellipses to keep us from having to list
all of the elements individually, provided the
meaning is obvious: H = {1, 2, 3, 4, …, 100}
Using Set Builder Notation
• Often we are dealing with sets where it is
impossible to list all of their elements.
• In set builder notation, we give a rule that
characterizes all members of a set.
• Example:
S = {x | x is the square of an integer}
• This can be read, “S is the set of all x such
that x is the square of an integer”.
Using Set Builder Notation
• In studying computer theory, we find it
useful to remember the following sets:
N = {0, 1, 2, 3, …}, the set of natural numbers
Z = {…, -2, -1, 0, 1, 2, …}, the set of integers
Z+ = {1, 2, 3, …}, the set of positive integers
Q = {p/q | p  Z, q  Z, and q  0}, the set of
rational numbers
Q+ = the set of positive rational numbers
R = the set of real numbers
What Can Constitute a Set?

• Note that anything within a set of curly


braces can be considered a set. The
elements of a set don’t necessarily have to
have anything to do with one another.
• Example: {Boston, “7”, iPod, 2.7, Sleepy}
is a legal set.
What Can Constitute a Set?

• Two sets are equal if and only if they have


the same elements.
• Consider sets A and B. Then A = B
(A and B are equal) iff:
x ((x  A)  (x  B))
The Elements of a Set
The order in which elements occur in sets is
irrelevant. For example, the following two
sets are equal:
{a, b, c, d, e}
{c, e, a, d, b}
The Elements of a Set
It does not matter if an element of a set is
listed more than once. For example,
{a, a, a, b, c}
and
{a, b, c}
are equivalent. We ignore any duplicates.
What Can Constitute a Set?
• The elements of a set can themselves be
sets. For example,
S = {N, Z, Q, R}
• Question: Does set S have any duplicate
elements?
• Answer: No. Set S has only 4 elements,
none of which is equivalent to any of the
others.
What Can Constitute a Set?
• A set that has no elements is called the empty set
or null set.
• Yes, it is still considered a real set, even though
it has no elements.
• It is denoted by , or by { }.
• Since the empty set is a set, another set can
contain the empty set as one of its elements:
A ={, a} This set has 2 elements
B = {} This set has 1 element
C= This set has 0 elements
Venn Diagrams
• Sets can be represented graphically using
Venn diagrams.
• In Venn diagrams:
– A rectangle represents the universal set
(universe of discourse)
– Circles (and other geometric figures)
represents sets
– Points (or words) represent elements
Venn Diagrams
• Assistant professors at Blivet State
University who have taught CSE 2813:

U
Smith Green

Jones
Brown Moore
Subset
The set A is said to be a subset of set B if and
only if every element of set A is also an
element of set B.
We use this notation: A  B
A  B is true if and only if the following
quantification is true:
x ((x  A)  (x  B))
Subset
Obviously, according to the preceding
definition, if A = B, it must be true that:
A  B, and
B  A.
Moreover, it should be self-evident that every
set is a subset of itself. That is:
AA
Proper Subset
However, if all of A’s elements are also in B,
but B has some elements in it that A does
not have (that is, A  B), then we can be a
more precise and say that A is a proper
subset of B.
We use this notation: A  B
A is a proper subset of B iff:
x (x  A  x  B)  x(x  B  x  A)
Proper Subset
We can represent the subset relationship
using a Venn diagram. The following
diagram represents A  B:

U
B

A
Subset
Interestingly enough, the empty set, , is a
subset of every other set (or, more
precisely, every nonempty set).
Your book gives a formal proof, but you
might think of it this way instead: if set S =
{a, b}, then it has 4 subsets –
{{a}, {b}, {ab}, }
Properties of Sets
One way to show that two sets are equal is to
show that each set is a subset of the other.
The Cardinality of a Set
Given a set S, and n  N (that is, n is an
element of the set of natural numbers -- the
integers from 0 on up),
if there are exactly n distinct elements in S,
then:
S is a finite set, and
n is the cardinality of S
The cardinality of S is represented by |S|.
Properties of Sets
We now can see that every nonempty set S
must have at least two subsets:
 and S
This is given as Theorem 1 in your book: For
every set S,
Part i: S
Part ii: S  S
Powerset

The powerset of S is the set of all subsets of S.


The powerset of S is represented by P(S), or
by the symbol 2|S|
For example, if S = {a, b}, then:
P(S) = {{a}, {b}, {a, b}, }
Powerset
Remember that |S| represents the cardinality
of S (the number of elements in S).
Here S has two elements, a and b. So 2|S| can
be understood as 22, which is 4.
And 4 is the number of subsets of S, or the
cardinality of the powerset of S.
Powerset
The powerset of the empty set is a special
case.
The powerset of the empty set is:
P() = {, {}}
Cartesian Product
The Cartesian product, or cross product, of two sets
is the set of ordered pairs of elements of the two
sets. To represent the cross product of sets A
and B we use the symbol , as in A  B.
For example, given:
set A = {a, b} and
set Y = {x, y}
The Cartesian product A  Y = {ax, ay, bx, by}
Set Notation with Quantifiers
xS(P(x)) means “ for all x that are
elements of S, P(x) is true”. This is
referred to as the universal quantification of
P(x) over all elements in the set S. It is
shorthand for: x(x  S P(x))
 xS(P(x)) is the existential quantification
of P(x) over all elements in the set S. It is
shorthand for: x(x  S P(x))
Truth Sets of Quantifiers
Given a predicate, P, and a domain, D, the
truth set of P is defined as the set of
elements in D for which P(x) is true.
The truth set of P(x) is is denoted by {x  D |
P(x)}: “those elements of domain D such
that P(x) is true”
CS202
Discrete Maths

Chapter 2, Section 2.2


Set Operations
Set Union
• Union of two sets A and B is denoted by AB
 AB contains elements that are either in A or in B or in both.
AB
 AB = {x | x  A  x  B}
 A = {1,3,5}, B = {2,3,4}
 AB = {1, 2, 3, 4, 5}

A B
Set Intersection
• Intersection of two sets A and B is denoted
by AB
 AB contains elements that are in both A
and B
 AB = {x | x  A  x  B} AB
 A = {1,3,5}, B = {1,2,3}
 AB = {1, 3} AA B
Disjoint Sets

• Two sets are called disjoint if their


intersection is the empty set.
 A = {1,3,5}, B = {1,2,3}, C = {6,7,8}
 Are A and B disjoint? NO
 Are A and C are disjoint? YES

A C
Cardinality of the Union of Sets
How many elements does AB have?
The number of elements in A plus the
number of elements in B, minus the
number of elements in both sets.
This can be written:
|AB| = |A|+|B|-|A  B|
Set Difference
• Difference of two sets A and B is denoted
by AB
 AB contains elements that are in A but not
in B.
 AB = {x | x  A  x  B} A-B
 A = {1,3,5}, B = {1,2,3}
 AB = {5}
A B
Complement of a Set

• Complement of a set A is denoted by A


• Done with respect to a Universal set U
• A contains elements which are not in A,
but are in U.
U
• A= U  A
A
• A = {x | xU  xA}
Set Identities

AA Identity
AUA
AUU Domination
A
AAA Idempotent
AAA
A =A Double Complement
Set Identities (Cont.)
ABBA Commutative
ABBA
A  (B  C)  (A  B)  C Associative
A  (B  C)  (A  B)  C
A  (B  C)  (A  B)  (A  C) Distributive
A  (B  C)  (A  B)  (A  C)
A  (A  B)  A Absorption
A  (A  B)  A
A B  A B De Morgan's
A B  A B
Examples
• Use set builder notation to prove that:

A B  A B

• Use set identities to prove that

( A  B)  C  B  B  C
More Exercises
• Describe the following sets using the set builder
notation:
1. The set of all positive integers between 1 and 99.
2. A  B
3. A  B
4. A  B
5. ( A  B )  C
• Use set builder notation to prove .

A B  A B
CS202
Discrete Maths

Chapter 2, Section 2.3


Functions
Recap 2.1
• Set – an UNORDERED collection of objects
– Element /member - an object in a set
– Notation - {a,b,c,d}
• Cardinality
– The number of distinct elements in a set
• Power Set
– The set of all subsets of a set
• Cartesian product of two sets A and B A  B
AB = {(a, b) | a  A  b  B}
Recap 2.2

• Union: AB = {x | x  A  x  B}
ABBA Commutative
• Intersection:
ABBA
AB = {x | x  A  x  B}
• Difference:
A  (B  C)  AB
(A  B)= C{x | x  Associative
A  x  B}
A  (B  C)  (A  B)  C
• Complement: ĀB)=U
A  (B  C)  (A  - C)
(A  A Distributive
A  (B  C)  (A  B)  (A  C)
• Identities similar
A  (A  B) A to those from logic, e.g.
Absorption
A  (A  B)  A
A B  A B De Morgan's
A B  A B
Definitions
• Let A and B be sets. A function f from A to
B is an assignment of exactly one element
of B to each element of A.
• We write f(a) = b if b is the unique element
of B assigned by the function f to the
element of A.
• If f is a function from A to B, we write
f:AB
Definitions
• If f : A  B, we say that A is the domain
of f and B is the codomain of f.
• If f(a) = b, we say that b is the image of a.
• The range of f is the set of all images of
elements of A.
Example
• Suppose that each student in a class is assigned a
letter grade from the set {A, B, C, D, F}. Let g
be the function that assigns a grade to a student.

Domain Codomain
Chavez • •A
Stokes • •B
Range
Dees • •C
Dozier • •D
Holland • •F
Example
• Consider a function f : Z  Z that assigns the
square of an integer to this integer.
• How can you write this function? f(x) =
x2
• What is the domain of f ? The integers
• What is the codomain of f ? The integers
• What is the range of f ? The nonnegative
integers {0,1,4,9,..}
One-to-One Functions (injective)
• No value in the range is used by more than one
value in the domain.
• If f(x) = f(y), then x = y for all x and y in the
domain of f.
•1
a•
•2
b•
•3
c•
•4
• In other words x y (f(x) = f(y)  x = y),
or using the contrapositive
x y (x ≠ y  f(x) ≠ f(y))
One-to-One Functions
• Is the function f(x) = x2 from the set of integers
to the set of integers one-to-one?
x y (x2 = y2  x = y)?
• 12 = (-1)2 but 1 ≠ -1
• NO
• Is the function f(x) = x + 1 one-to-one?
x y (x + 1 = y + 1  x = y)?
• (x + 1) ≠ (y + 1) only when x ≠ y
• YES
Onto Functions (surjective)
• For every value in the codomain, there is a
value in the domain that is mapped to it.
•1
a•
•2
b•
•3
c•
d•

• In other words, y x (f(x) = y)


• Codomain = range!
Onto Functions
• Is the function f(x) = x2 from the set of integers
to the set of integers onto?
• Is it true that y x (x2 = y)?
• -1 is one of the possible values of y, but there
does not exists an x such that x2 = -1
• NO
• Is the function f(x) = x + 1 onto?
• Is it true that y x (x + 1 = y)?
• For every y, some x exists such that x = y - 1.
• YES
One-to-One Correspondence
(bijection)
• If a function f is both one-to-one and onto,
then it is a one-to-one correspondence.
•1
•1 a• a• •1
a• •2
•2 b• b• •2
b• •3
•3 c• c• •3
c• d• d• •4
•4
One-to-One Onto, but One-to-One
but not Onto Not One-to-One Correspondence
Monotonic Functions
• A monotonic function is
– either monotonically (strictly) increasing
– or monotonically (strictly) decreasing
• Consider a function f : R  R
• f is monotonically increasing
– if f(x) ≤ f(y) whenever x < y
• f is monotonically decreasing
– if f(x)  f(y) whenever x < y
Inverse Functions
• Let f : A  B be one-to-one correspondence
such that f(a) = b.
• The inverse of the function f is denoted by
f -1(b) = a.
f 1

a  f 1(b) b  f(a)

A f B
F needs to be bijection
• If f is not a bijection (one-to-one correspondence)
– f is not injective (one-to-one)
– f is not surjective (onto)
• Why can’t we invert such a function?
We cannot assign to each element b in the
codomain a unique element a in the domain
such that f(a) = b, because:
– For some b there is either
• More than one a
• No such a
Inverse Functions
• Let f : Z  Z be a function with f(x) = x + 1
• Is f invertible? Is f a bijection?
 Is f one-to-one? YES
 Is f onto? YES
 So f is a one-to-one correspondence and is

therefore invertible.
• Then, what is its inverse? f(y) = y - 1
Inverse Functions
• Let f : Z  Z be a function with f(x) = x2.
• Is f invertible?
• Is f a one-to-one correspondence. NO
• So f is not a one-to-one, and
• therefore, f is not invertible.
Compositions of Functions
• Let g : A  B and f : B  C.
• The composition of the functions f and g,
denoted by f  g, is defined by:
f  g(a) = f (g(a))
• f  g can’t be defined unless the range of g
is a subset of the domain of f.
Example
• Let:
f(x) = 2x + 3
g(x) = 3x + 2
• Find f  g(x):
2(3x +2) + 3
• Find g  f(x):
3(2x + 3) + 2
Composition of Inverses

Let:
f(a) = b , so
f -1(b) = a
• Find f -1  f (a) :
a
• f  f -1 (b)
b
Important functions – Floor
• Let x be a real number. The floor function
is the closest integer less than or equal to x.
• Examples:
½ =0
 –½  = ?
 3.1  = ?
7 =?
Important functions – Ceiling
• Let x be a real number. The ceiling function
is the closest integer greater than or equal to
x.
• Examples:
½ =1
 –½  = ?
 3.1  = ?
7=?
Ceiling

http://mathworld.wolfram.com/CeilingFunction.html
CS202
Discrete Maths

Chapter 2, Section 2.4


Sequences and Summations
Sequence
• If the domain of a function is restricted to
integers, the function is called a sequence.
• The domain is specifically the set N or the
set Z+.
• an denotes the image of n
– called a term of the sequence
• Notation for whole sequence: {an}
Example
• Let {an} be a sequence, where
an = 1/n and n  Z+
• What are the terms of the sequence?
a1 = 1
a2 = 1/2
a3 = 1/3
a4 = 1/4
... ... ...
Sequence Notation
• Unless stated to the contrary, we will
assume the domain of a sequence to be
the set of all positive integers.
• an is called the nth term or general term.
Geometric/Arithmetic Progression
• Geometric Progression:
– A sequence of the form a, ar, ar2, …, arn
– aR and rR
– a is the initial term and r is the common ratio
• Arithmetic Progression:
– A sequence of the form a, a+d, a+2d, …, a+nd
– aR and dR
– a is the initial term and d is the common
difference
Example
• Let {bn} be a sequence, where bn = (-1)n
– What type of progression is this?
(Geometric)
– What is the initial term?
(1)
– What is the common ratio/difference?
(-1)
– What are the terms of the sequence?
(1, -1, 1, -1, 1, …)
Example
• Let {dn} be a sequence, where dn = 6 • (1/3)n
– What type of progression is this?
(Geometric)
– What is the initial term?
(6)
– What is the common ratio/difference?
(1/3)
– What are the terms of the sequence?
(6, 2, 2/3, 2/9, 2/27, …)
Example
• Let {sn} be a sequence, where sn  1 + 4n
– What type of progression is this?
(Arithmetic)
– What is the initial term?
(-1)
– What is the common ratio/difference?
(4)
– What are the terms of the sequence?
(-1, 3, 7, 11, …)
Example
• Let {tn} be a sequence, where tn  7  3n
– What type of progression is this?
(Arithmetic)
– What is the initial term?
(7)
– What is the common ratio/difference?
(-3)
– What are the terms of the sequence?
(7, 4, 1, -2, …)
Example
• Find a formula for this sequence:
1, 1/2, 1/3, 1/4, 1/5, ...
– What type of progression is this?
(Arithmetic)
– What is the initial term?
(1)
– What is the common ratio/difference?
(1)
What is the formula?
(an = 1/n)
Summations
• A summation denotes the sum of the terms
of a sequence.
• Example:
Upper limit
5
2 2 2 2 2 2
Index of
Summation
 j 1  2  3  4  5
j 1

Lower limit
 1  4  9  16  25
 55
Geometric Series
• The sum of a geometric progression is
called a geometric series
• Commonly used
n
j 0 1 2 n
S   ar  ar  ar  ar  ...  ar
j 0
Double Summation
3 2

 (i  j )
i 1 j 1
2

 (i  j )  (i  1)  (i  2)  2i  3
j 1

 (2i  3)  (2 1  3)  (2 2  3)  (2  3  3)
i 1

 1  1  3  3
Useful Summation Formulae
Conclusion
• In this chapter we have covered:
– Introduction to sets
– Set operations
– Functions
– Sequences and summations

You might also like