100% found this document useful (1 vote)
401 views57 pages

Basic Discrete Structure

Uploaded by

Ahmed Iqbal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
401 views57 pages

Basic Discrete Structure

Uploaded by

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

Basic Discrete Structure : Set

Lecture 4

1
Basic Discrete Structure
Discrete math =
– study of the discrete structures used to represent discrete objects

Many discrete structures are built using sets


– Sets = collection of objects

Examples of discrete structures built with the help of sets:


• Combinations
• Relations
• Graphs

2
Set
Definition:

A set is a (unordered) collection of objects.

These objects are sometimes called elements or members


of the set.

• Examples:
– Vowels in the English alphabet
V = { a, e, i, o, u }

– First seven prime numbers.


X = { 2, 3, 5, 7, 11, 13, 17 }
3
Representing Set
Representing a set by:
1) Listing (enumerating) the members of the set.
2) Definition by property, using the set builder notation
{x| x has property P}.

Example:
• Even integers between 50 and 63.
1) E = {50, 52, 54, 56, 58, 60, 62}
2) E = {x| 50 <= x < 63, x is an even integer}

If enumeration of the members is hard we often use ellipses.


Example: a set of integers between 1 and 100
• A= {1,2,3 …, 100}
4
Important set in discrete math
• Natural numbers:
– N = {0,1,2,3, …}

• Integers
– Z = {…, -2,-1,0,1,2, …}

• Positive integers
– Z+ = {1,2, 3.…}

• Rational numbers

• Real numbers
–R 5
Equality of Set
Definition: Two sets are equal if and only if they have the
same elements.

Example:
• {1,2,3} = {3,1,2} = {1,2,1,3,2}

Note: Duplicates don't contribute anything new to a set, so


remove them. The order of the elements in a set doesn't
contribute anything new.

Example: Are {1,2,3,4} and {1,2,2,4} equal?


No! 6
Universal set
Special sets:

– The universal set is denoted by U: the set of all objects


under the consideration.

– The empty set is denoted as Ø or { }.

7
Venn Diagram
A set can be visualized using Venn Diagrams:

– V={ A, B, C }

8
A subset
Definition: A set A is said to be a subset of B if and only
if every element of A is also an element of B. We use
to indicate A is a subset of B.

Alternate way to define A is a subset of B:

9
Empty set/subset property
Theorem :

• Empty set is a subset of any set.


Proof:
•Recall the definition of a subset: all elements of a set A must
be also elements of B:

•We must show the following implication holds for any

•Since the empty set does not contain any element, is


always False
•Then the implication is always True. (F → T/F =T)
End of proof 10
Venn diagram of Empty set
Theorem :

• Empty set is a subset of any set.

U
A

11
Subset property
Theorem:
• Any set S is a subset of itself

Proof:
• the definition of a subset says: all elements of a set A must
be also elements of B:

• Applying this to S we get:


• which is trivially True

• End of proof

Note on equivalence:
• Two sets are equal if each is a subset of the other set. 12
A proper Subset
Definition:

A set A is said to be a proper subset of B if and only if


and . We denote that A is a proper
subset of B with the notation .

Example: A={1,2,3} B ={1,2,3,4,5}


Is: ? 13
A proper Subset
Definition:

A set A is said to be a proper subset of B if and only if


and . We denote that A is a proper
subset of B with the notation .

Example: A={1,2,3} B ={1,2,3,4,5}


Is: ? Yes. 14
Cardinality
Definition: Let S be a set. If there are exactly n distinct
elements in S, where n is a nonnegative integer, we say S is
a finite set and that n is the cardinality of S. The cardinality of
S is denoted by | S |.

Examples:
• V={1 2 3 4 5}
|V|=5

• A={1,2,3,4, …, 20}
|A| =20

•|Ø|=0
15
Infinite set
Definition: A set is infinite if it is not finite.

Examples:
• The set of natural numbers is an infinite set.
• N = {1, 2, 3, ... }

• The set of real numbers is an infinite set.

16
Power set
Definition: Given a set S, the power set of S is the set of all
subsets of S. The power set is denoted by P(S).

Example

• What is the power set of Ø ? P(Ø ) = {Ø}


• What is the cardinality of P(Ø) ? | P(Ø) | = 1.

Assume {1,2,3}
• P({1,2,3}) = {Ø, {1}, {2}, {3}, {1,2}, {1,3}, {2,3}, {1,2,3} }
• |P({1,2,3} | = 8

If S is a set with |S| = n then | P(S) | = ? 2n 17


N-tuple
Sets are used to represent unordered collections.

• Ordered-n tuples are used to represent an ordered


collection.

Definition: An ordered n-tuple (x1, x2, ..., xN) is the ordered


collection that has x1 as its first element, x2 as its second
element, ..., and xN as its N-th element, N ˃= 2.

Example: Coordinates of a point in the 2-D plane (12, 16) 18


Cartesian Product
Definition: Let S and T be sets. The Cartesian product of S
and T, denoted by S x T, is the set of all ordered pairs (s,t),
where s ϵ S and t ϵ T. Hence,

• S x T = { (s,t) | s ϵ S ˄ t ϵ T}.

Examples:
• S = {1,2} and T = {a,b,c}

• S x T = { (1,a), (1,b), (1,c), (2,a), (2,b), (2,c) }


• T x S = { (a,1), (a, 2), (b,1), (b,2), (c,1), (c,2) }

• Note: S x T ≠ T x S !!!!
19
Cardinality of a Cartesian Product
• |S x T| = |S| * |T|.

Example:
• A= {John, Peter, Mike}
• B ={Jane, Ann, Laura}

• A x B= {(John, Jane),(John, Ann) , (John, Laura), (Peter, Jane),


(Peter, Ann) , (Peter, Laura) , (Mike, Jane) , (Mike, Ann) ,
(Mike, Laura)}

• |A x B| = 9
• |A|=3, |B|=3 → |A| |B|= 9

Definition: A subset of the Cartesian product A x B is called a relation from


the set A to the set B.

20
Set Operation
Definition: Let A and B be sets. The union of A and B,
denoted by A U B, is the set that contains those elements that
are in both A andB.

• Alternate: A U B = { x | x ϵ A V x ϵ B }.

Example:
• A = {1,2,3,6} and B = { 2,4,6,9}

• A U B = { 1,2,3,4,6,9 } 21
Set Operation
Definition: Let A and B be sets. The intersection of A and B,
denoted by A ∩ B, is the set that contains those elements that
are in both A andB.

• Alternate: A ∩ B = { x | x ϵ A ˄ x ϵ B }.

Example:
• A = {1,2,3} and B = { 2,4,6,9}

•A∩ B={2} 22
Disjoin Set
Definition: Two sets are called disjoint if their intersection is
empty.

• Alternate: A and B are disjoint if and only if A ∩ B = Ø.

Example:
• A={1,2,3,6} B={4,7,8} Are these disjoint?
• Yes.
•A∩B=Ø 23
Cardinality of set union
Cardinality of the set union.

• |AU B| = |A| + |B| - |A ∩ B|

Why this formula? Correct for an over-count.

24
Set Difference
Definition: Let A and B be sets. The difference of A and B,
denoted by A - B, is the set containing those elements that
are in but not in B. The difference of A and B is also called
the complement of B with respect to A.

• Alternate:

Example: A= {1,2,3,5,7} B = {1,5,6,8}


• A - B ={2,3,7} 25
Complement of a Set
Definition: Let U be the universal set: the set of all objects
under the consideration.
Definition: The complement of the set A, denoted by Ã, is the
complement of A with respect to U.
• Alternate: Alternate:

Example: U={1,2,3,4,5,6,7,8} A ={1,3,5}


• Ã={2,4,6,7,8} 26
Generalized union
Definition: The union of a collection of sets is the set that
contains those elements that are members of at least one set
in the collection.

Example:
A1 = {1}
• Let Ai= {1,2,...,i} i =1,2,...,n
A2= {1,2}
A3= {1,2,3}
…………..
…………..
An {1,2,3,4,...,n} 27
Generalized intersection
Definition: The intersection of a collection of sets is the set
that contains those elements that are members of all sets in
the collection.

Example:
• Let Ai= {1,2,...,i} i =1,2,...,n
A1 = {1}
A2= {1,2}
A3= {1,2,3}
…………..
…………..
An {1,2,3,4,...,n} 28
Computer representation of set
How to represent sets in the computer?
• One solution: Data structures like a list

• A better solution: Assign a bit in a bit string to each element


in the universal set and set the bit to 1 if the element is
present otherwise use 0

Example:
All possible elements: U={1 2 3 4 5}
• Assume A={2,5}
– Computer representation: A = 01001

• Assume B={1,5}
– Computer representation: B = 10001 29
Computer representation of set
Example:
• A = 01001
• B = 10001

• The union is modeled with a bitwise or


• A U B = 11001

• The intersection is modeled with a bitwise and


• A ∩ B = 00001

• The complement is modeled with a bitwise negation


• Ã =10110

30
Basic Discrete Structure :
Set and Function

31
Quiz Problem 1
1. Suppose the following two statements are true.
I love Dad or I love Mum
If I love Dad then I love Mum
Does it necessarily follow that I love Dad? Does it necessarily follow that I
love Mum? Use propositional logic to answer the questions.
P Q P˅Q P→Q
(I love dad) (I love mum)

F F F T

F T T T

T F T F

T T T T
32
Quiz Problem 1
1. Suppose the following two statements are true.
I love Dad or I love Mum
If I love Dad then I love Mum
Does it necessarily follow that I love Dad? Does it necessarily follow that I
love Mum? Use propositional logic to answer the questions.
P Q P˅Q P→Q
(I love dad) (I love mum)

F F F T

F T T T

T F T F

T T T T
33
Quiz Problem 2
2. Consider the following specification with
two predicate symbols p1≡(<), p2≡(=)
two function symbols f1≡(+), f2≡(×)
two constant symbols c1 ≡(0), c2≡(1)
Let domain of discourse be <Z+ ∪ {0}> where Z+={1,2,….}
What are the truth values of the following statements?
i.∀x p1(c1,x)
ii.∀x∀y∃z (p1(x,z) ∧ p1(z,y))
iii.∃x∀yp1(x,y)
iv.∀x∀y p2(f2(f1(x,c2),y), f1(f2(x,y),y))

i. False 0<x

34
Quiz Problem 2
2. Consider the following specification with
two predicate symbols p1≡(<), p2≡(=)
two function symbols f1≡(+), f2≡(×)
two constant symbols c1 ≡(0), c2≡(1)
Let domain of discourse be <Z+ ∪ {0}> where Z+={1,2,….}
What are the truth values of the following statements?
i.∀x p1(c1,x)
ii.∀x∀y∃z (p1(x,z) ∧ p1(z,y))
iii.∃x∀yp1(x,y)
iv.∀x∀y p2(f2(f1(x,c2),y), f1(f2(x,y),y))

i. False 0<x
ii. False x< z ∧ z<y

35
Quiz Problem 2
2. Consider the following specification with
two predicate symbols p1≡(<), p2≡(=)
two function symbols f1≡(+), f2≡(×)
two constant symbols c1 ≡(0), c2≡(1)
Let domain of discourse be <Z+ ∪ {0}> where Z+={1,2,….}
What are the truth values of the following statements?
i.∀x p1(c1,x)
ii.∀x∀y∃z (p1(x,z) ∧ p1(z,y))
iii.∃x∀yp1(x,y)
iv.∀x∀y p2(f2(f1(x,c2),y), f1(f2(x,y),y))

i. False 0<x
ii. False x< z ∧ z<y
iii. False x<y

36
Quiz Problem 2
2. Consider the following specification with
two predicate symbols p1≡(<), p2≡(=)
two function symbols f1≡(+), f2≡(×)
two constant symbols c1 ≡(0), c2≡(1)
Let domain of discourse be <Z+ ∪ {0}> where Z+={1,2,….}
What are the truth values of the following statements?
i.∀x p1(c1,x)
ii.∀x∀y∃z (p1(x,z) ∧ p1(z,y))
iii.∃x∀yp1(x,y)
iv.∀x∀y p2(f2(f1(x,c2),y), f1(f2(x,y),y))

i. False 0<x
ii. False x< z ∧ z<y
iii. False x<y
iv True xy +y = xy+y
37
Quiz Problem 3
3. Let A be the set of English words that contains x, and B be the set of
English words that contain the letter q. Express each of these sets as
a combination of A and B.
i. The set of English words that do not contain the letter x.
ii. The set of English words that contain an x but not a q.
iii. The set of English words that do not contain either an x or a q.

i. U–A

38
Quiz Problem 3
3. Let A be the set of English words that contains x, and B be the set of
English words that contain the letter q. Express each of these sets as
a combination of A and B.
i. The set of English words that do not contain the letter x.
ii. The set of English words that contain an x but not a q.
iii. The set of English words that do not contain either an x or a q.

i. U–A
ii. A –B

39
Quiz Problem 3
3. Let A be the set of English words that contains x, and B be the set of
English words that contain the letter q. Express each of these sets as
a combination of A and B.
i. The set of English words that do not contain the letter x.
ii. The set of English words that contain an x but not a q.
iii. The set of English words that do not contain either an x or a q.

i. U–A
ii. A –B
iii. U – (A ∩ B)

40
Quiz Problem 4
4. Let A = {a, b, c}, B = {x, y} and C= {0, 1}. Find C × B × A.

C×B {{0,x}{0,y},{1,x}{1,y}}

41
Quiz Problem 4
4. Let A = {a, b, c}, B = {x, y} and C= {0, 1}. Find C × B × A.

C×B {{0,x}{0,y},{1,x}{1,y}}
C×B×A {{0,x,a}, {0,x,b}, {0,x,c},{0,y,a}, {0,y,b},
{0,y,c},{1,x,a}, {1,x,b}, {1,x,c},{1,y,a}, {1,y,b},
{1,y,c}}

42
Quiz Problem 5
5. Let f be the function from R to R defined by y=f(m,n)=2m-n.
Write a method signature in C with appropriate return type and
parameter list that could be used to realize the function.

double f(double m, double n);

43
Definitions and notation

Check these:

Is {x} ⊆ {x}?

Is {x} ∈ {x,{x}}? Yes

Is {x} ⊆ {x,{x}}? Yes

Is {x} ∈ {x}? No

44
Operators

like
“exclusive or”

The symmetric difference, A ⊕ B, is:


A ⊕ B = { x : (x ∈ A ∧ x ∉ B) v (x ∈ B ∧ x ∉ A)}

= (A - B) U (B - A)

U
A
B

45
Operators

Proof: { x : (x ∈ A ∧ x ∉ B) v (x ∈ B ∧ x ∉ A)}
= (A - B) U (B - A)

A ⊕ B = { x : (x ∈ A ∧ x ∉ B) v (x ∈ B ∧ x ∉ A)}
= { x : (x ∈ A - B) v (x ∈ B - A)}
= { x : x ∈ ((A - B) U (B - A))}
= (A - B) U (B - A)

46
Famous Identities

A∩U=A
• Identity AU∅=A

AUU=U
• Domination A∩∅=∅

AUA=A
• Idempotent
A∩A=A

47
Famous Identities

• Excluded Middle AUA=U

• Uniqueness A∩A=∅

• Double complement A=A

48
Famous Identities

AUB= BUA
• Commutativity
A∩B= B∩A

(A U B) U C = A U (B U C)
• Associativity
(A ∩ B) ∩ C = A ∩ (B ∩ C)

• Distributivity A U (B ∩ C) = (A U B) ∩ (A U C)
A ∩ (B U C) = (A ∩ B) U (A ∩ C)

49
Famous Identities

• DeMorgan’s I (A U B) = A ∩ B

• DeMorgan’s II (A ∩ B) = A U B

50
Inclusion/Exclusion
Example:
How many people are wearing a watch?
How many people are wearing sneakers?

How many people are wearing


a watch OR sneakers?

What’s wrong?
|A ∪ B| = |A| + |B| 7
B A
|A ∪ B| = |A| + |B| - |A ∩ B| 6

51
Inclusion/Exclusion

Example:
There are 217 cs majors. 125
157 are taking cs125. 173
145 are taking cs173.
98 are taking both.

How many are taking neither?

217 - (157 + 145 - 98) = 13

52
Generalized Inclusion/Exclusion
Suppose we have:
A = {0, 2, 4, 6, 8},
B B = {0, 1, 2, 3, 4},
A
C = {0, 3, 6, 9}.

And I want to know |A U B U C|

|A U B U C| = |A| + |B| + |C|


- |A ∩ B| - |A ∩ C| - |B ∩ C|
+ |A ∩ B ∩ C|
|A ∪ B ∪ C| = 5+5+4-3-2-2+1 ≡ 8 ≡{0, 1, 2, 3, 4, 6, 8, 9}. 53
Functions - examples

Suppose f: R+ → R+, f(x) = x2.

Is f one-to-one? yes
Is f onto? yes
Is f bijective?
yes

54
Functions - examples

Suppose f: R → R+, f(x) = x2.

Is f one-to-one? no
Is f onto? yes
Is f bijective? no

55
Functions - examples

Suppose f: R → R, f(x) = x2.

Is f one-to-one? no
Is f onto? no
Is f bijective?
no

56
Thank You

57

You might also like