0% found this document useful (0 votes)
19 views34 pages

Sets and Relation

Uploaded by

Brandon Tay
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)
19 views34 pages

Sets and Relation

Uploaded by

Brandon Tay
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/ 34

COMP2121

Discrete Mathematics

Big-O Notation,
Sets and Relations
Hubert Chan (Chapter 2.1, 2.2, 8)

[O1 Abstract Concepts]

1
Big O Notation

[O1 Abstract Concepts]

2
Big O Notation:
How fast is a function growing
• Suppose that A, B, C, D are 4 programs. And the running
times are 400log2 n, 100n, 5n2 and 2n on input size n
• What’s the running time for the following input size:

400log2 n 100 n 5n2 2n


2 400 200 20 4
16 1600 1600 1280 65536
1024 4000 10240 5242880 NA
• How fast a function grows is more important than the
factors.

3
4
Complexity [O1]
• Two functions T(n) and f(n) from Z+ to R+, then

• T(n)=O(f(n)) if there exists a positive constant c and a


positive integer N such that
 for all n ≥ N, T(n) ≤ c·f(n)

• Example:
T(n)=10n+n2=O(n2)

5
Example
• T(n)=10n+n2=O(n2)
Let N=10, c=2
For n ≥ N
T(n)=10n+n2 ≤n2+n2=c·n2

• More Examples:
 T(n)=2n2=O(n2), T(n)=2n2=O(n3)
 T(n)=3log2n=O(log2n), T(n)=3log2n=O(n)
 T(n)=n+5log2n=O(n)

6
The meaning of c
• Consider the following groups of functions:
 A: f(n)=n, f(n)=2n, f(n)=3n
 B: f(n)=n2, f(n)=2n2, f(n)=3n2
• A: B:

• The curves in the same group have the same shape up to scaling.
• The curves in group A and the curves in group B are quite different.

7
The meaning of N
• Consider the following functions:

• It’s easy to see that when x gets large they are almost the same. But when x
is small, they differ a lot.

8
More Examples
• Define functions from Z+ to R+ such that
 f(n) = 10n
 g(n) = 2log2n
 h(n) = 2n3 - n + 5log2n
• Then we have:
 f(n)=O(n)
 g(n)=O(log2n)
 h(n)=O(n3)
 f(n)=O(n2)
 g(n)=O(n)
 h(n)=O(n4)
9
Complexity
• T(n)=Ω(f(n))
 If there exists a positive constant c and a positive
integer N such that for all n ≥ N, T(n) ≥ c·f(n).
 T(n)=Ω(f(n)) ↔ f(n)=O(T(n))

• T(n)=Ɵ(f(n))
 if there exists two positive constant c1, c2 (c1<c2) and a
positive integer N such that for all n ≥ N,
c1·f(n) ≤ T(n) ≤ c2·f(n).
 T(n)=Ɵ(f(n)) ↔ ( T(n)= Ω(f(n)) ˄ T(n)=O(f(n)) )

10
Examples on  and £
• Define functions from Z+ to R+ such that
 f(n) = 10n
 g(n) = 2log2n
 h(n) = 2n3 - n + 5log2n
• Then we have:
 f(n)=Ω(n), f(n)=Ɵ(n)
 g(n)=Ω(log2n), g(n)=Ɵ(log2n)
 h(n)=Ω(n3), h(n)=Ɵ(n3)
 f(n)=Ω(log2n)
 g(n)=Ω(log2log2n)
 h(n)=Ω(n)
11
Sets and Relations

12
Sets – Definition & Notation [O1]
A set is a collection of objects.

Example:
A = {apple, orange, mango, pear}
B = {policeman, fireman, manager, doctor, lawyer}
C = {1, 2}
D = {1, house, john, apple, salmon}
E = {1, 2, C} = {1, 2, {1, 2}}
F = {F, 1}

13
Elements of a Set
The objects are called elements or members of the set.
A set is said to contain its elements.

Notations:
x  S : x is an element of the set S.
2  { 5, 7, , “apple”, 2, 2.718 }
 {1}  { {1}, {a, b}, a, 1 }
 Given F = {F, 1}, F  F ?
x  S : x is not an element of the set S.
 apple  { 5, 7, , “apple”, 2, 2.718 }
b  { {1}, {a, b}, a, 1 }

14
The Empty Set & The Universal Set
• The set that has no elements is called the empty set or
the null set, and is denoted by { } or .
 Note that mathematically, there is only one empty set.

• A question: Is this, {  } , the empty set?


 Answer: No, this is a set containing 1 element, the
empty set.

• A set with 1 element is called a singleton.


 e.g. { x }, { 1 }

15
Finite and Infinite Sets
S is a finite set:
S contains exactly n elements (n  0)
| S | is the cardinality or the size of S
|S|=n

Example: A = {1, 2, 3}, |A|=?


B = {1, {2}, {3, 4}, 5}, |B|=?
||=? | {} | = ? | {, {}} | = ?

S is an infinite set if S is not finite.

16
Examples of Infinite Sets
Ex: natural numbers (non-negative integers) N = {0, 1, 2, 3,
…}
integers Z = {…, -2, -1, 0, 1, 2, …}
positive integers Z+ = { 1, 2, 3, … }
rational numbers Q = { p / q | p  Z, q  Z, q  0 }
real numbers R

How can a set be defined?


by listing the elements in the set
by properties (predicate),
i.e., only those element x which predicate P(x) is true.
e.g., E = {x  N  x is even}; P(x) = x is even
Set builder notation:
{ x | ….. } means the set of x such that …
17
Russell’s Paradox
Note that not everything is well-defined as a set.
Russell’s paradox:
Consider the set S = { x | x is a set and x  x }.
Does S contain itself?
If yes, what happens?
If no, what happens?
Similar paradox: The Barber paradox
A town has only 1 male barber. A man in the town is shaved by
the barber if and only if he does not shave himself.
Let S(x) = set of people shaved by x
So S(b) = { x | x  S(x) } where b = the male barber
Is b  S(b),? i.e, Does b shave himself?
18
Subsets
The set A is a subset of B if and only if every element of
A is also an element of B.
Notation: A  B
How to prove A  B ?
To show that x ( x  A  x  B )

For every set A, we have   A and A  A.


If A is a subset of B, but A  B, then we say that A is a
proper subset of B. (logical formula?)
Notation: A B
How to prove A B ?
To show that A  B and x ( x  B  x  A )

19
Equal Sets
Two sets are equal if they have the same elements.

Example:
 { 1, 3, 5 } and { 1, 3, 5 } are equal
 { 1, 3, 5 } and { 3, 5, 1 } are equal

 { 1, 3, 5 } and { 1, 2, 3 } are not equal


 R = { x | x is a real number} is not equal to N = { 0, 1, 2, 3, … }

A = B implies x (( x  A  x  B ) ˄ ( x  B  x  A ))

Hence A = B iff (A  B ˄ B  A)

20
The Power Set
Given a set S, the power set of S is the set of all subsets of
the set S.
Notation: P(S) or 2S.

Example: What is the power set of S = { 1, 2 } ?


Solution:
The elements of P(S) are , {1}, {2}, and {1, 2}.
Hence, P(S) = { , {1}, {2}, {1, 2} }.

Another example: P({a, b, c}) = {, {a}, {b}, {c}, {a,b}, {b,c}, {c,a}, {a,b,c}}

Question 1: P() = ? P( {  } ) = ?

Question 2: If |S| = n, then | P(S) | = ?


21
P(S)= 2S
Theorem: If Sn = {x1, …, xn} then P(Sn)= 2n

Proof:
Each element of Sn may x1 x2 x3
appear or not appear in a subset 0 0 0 = 
of Sn. Hence there are 2 0 1 0
1 0 0
possibilities for each element. 1 1 0
0 0 1
0 1 1
Hence, P(Sn)= 2*2*…*2=2n 1 0 1
1 1 1 = S

22
Set Operations
Union: A  B contains all elements that are either in A or in B, or both.
AB={x|xAxB}
U

Example: First year Computer courses A B


Venn Diagram

CS = { CP, CPA, FCS, MO}


CE = { CP, CPA, EM, MO, EC}
CS  CE = {CP, CPA, FCS, MO, EM, EC} U

Intersection: A  B contains those elements in both A and B.


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

Two sets A and B are said to be disjoint if A  B = 


Example: CS  CE = {CP, CPA, MO}
U

Difference: A  B contains those elements in A but not in B.


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

Example: CS  CE = {FCS}; CE  CS = {EM, EC}


U

Complement: A is the complement of A w.r.t. a set U.


A

A=UA={x|xA}
23
Set Identities

Identity

A=A AB=BA
AU=A AB=BA
AU=U A  (B  C) = (A  B)  C
A= A  (B  C) = (A  B)  C
AA=A A  (B  C) = (A  B)  (A  C)
AA=A A  (B  C) = (A  B)  (A  C)

24
Capturing Binary Relationship

25
Relations
Consider C={HK, Beijing, Shanghai, Guangzhou, Nanjing}
Each city builds a road to the nearest city. This information
(relationship among cities) can be represented by a set of 2-tuples
(ordered pairs)

R = { (HK, Guangzhou), (Beijing, Nanjing),


(Shanghai, Nanjing), (Guangzhou, HK),
(Nanjing, Shanghai) }
(A,B) means A’s nearest city is B.

Ordered pairs are used to indicate


relationship between 2 objects.
Note that the ordering of the elements
are important!

26
Notation
Given a relation R on A, two elements a, b in A
a R b iff (a, b)  R
a is said to be related to b by R
e.g. A = { 1, 2, 3, 4 }. R = { (a, b) | a divides b }
What are the elements of R?

R 1 2 3 4 1
2
1 √ √ √ √
2 × √ × √
3 × × √ ×
3 4
4 × × × √
Table Representation Graph Representation
27
Properties of Relations – Reflexive
A relation R on a set A is called reflexive
if (a,a)  R for all a  A.
I.e., a  A ((a,a)  R )

Example:
R = { (a, b) | a divides b }
R = { (a,b) | a  b } as a  a

In contrasts, the following relations are not reflexive:


“Parents” as a relation
R = { (a, b) | a = b + 1 }
R = { (a,b) | a < b }

28
Properties of Relations – Symmetric

A relation R on a set A is called symmetric


if (b,a)  R whenever (a,b)  R for all a,b  A.
i.e.  a,b  A ((a,b)  R  (b,a)  R )

Example: (Symmetric)
R = { (a,b) | a + b  3 }
R = { (a,b) | a × b = 24 }

29
Representing Relation with Graph
A graph G = (V, E) consists of
 V, the set of vertices (nodes, points), and
 E, the set of edges (lines)
Undirected graphs are graphs where edges have no d
direction (symmetric relation on V). a c
Example:
V = {a, b, c, d, e}
E = {{a,b}, {a, c}, {c, d}, {c, e}, {d, e}} b e
Directed graphs are graphs where edges have directions,
i.e., E consists of ordered pairs of V x y
Example:
V = {u, x, y, z}
E = {(x, y), (x, z), (y, u), (z, x), (z, u)}
z u
30
Properties of Relations – Transitive
A relation R on a set A is called transitive
if whenever (a,b)  R and (b,c)  R then (a,c)  R for all
a,b,c  A.
i.e.  a,b,c  A (((a,b)R(b,c)R)  (a,c)R)

Example:
R = { (a,b) | a > b }
R = { (a,b) | a divides b }

31
Examples
1
Properties: 2
Reflexive?
Symmetric?
Transitive?
3 4

Does there exist a relation which


has all these 3 properties? 1
2

4
3

32
Equivalence Relations
A relation on A is called an equivalence relation
if it is reflexive, symmetric and transitive.

Example:
 Suppose R is the relation on the set of people with the same
family name
 a R b : a sits in the same row as b
 reflexive?
 symmetric?
 transitive?
 Is R an equivalence relation?

33
Equivalence Classes
Let R be an equivalence relation on a set A.
The set of all elements that are related to an element
a of A is called the equivalence class of a.
[a]R = { s | (a, s)  R }
The equivalence class of a w.r.t. R is denoted by [a]R
(or [a] if there is only 1 relation under consideration)
Any element of an equivalence class is called a representative of
the equivalence class.
b [a] = {a}
a e [b] = {b,c,d} = [c] = [d]

d [e] = [f] = {e,f}


f
c
34

You might also like