Ch2 2 Set Operations

16
1 Discrete Mathematics Ch2.2 Set Operations Dr. Talal Bonny March 13, 2014

Transcript of Ch2 2 Set Operations

Page 1: Ch2 2 Set Operations

1

Discrete Mathematics

Ch2.2 Set Operations

Dr. Talal Bonny

March 13, 2014

Page 2: Ch2 2 Set Operations

Set operations: Union Formal definition for the union of two sets:

A U B = { x | x ∈ A or x ∈ B }

Further examples o {1, 2, 3} U {3, 4, 5} =

{1, 2, 3, 4, 5} o {a, b} U {3, 4} =

{a, b, 3, 4} o {1, 2} U ∅ =

{1, 2} Properties of the union operation

o A U ∅ = A Identity law o A U U = U Domination law o A U A = A Idempotent law o A U B = B U A Commutative law o A U (B U C) = (A U B) U C Associative law 2

Page 3: Ch2 2 Set Operations

Set operations: Intersection Formal definition for the intersection of two sets: A ∩ B = { x | x ∈ A and x ∈ B }

Examples

o {1, 2, 3} ∩ {3, 4, 5} = {3}

o {a, b} ∩ {3, 4} = ∅

o {1, 2} ∩ ∅ = ∅

Properties of the intersection operation o A ∩ U = A Identity law o A ∩ ∅ = ∅ Domination law o A ∩ A = A Idempotent law o A ∩ B = B ∩ A Commutative law o A ∩ (B ∩ C) = (A ∩ B) ∩ C Associative law 3

Page 4: Ch2 2 Set Operations

Disjoint sets Formal definition for disjoint sets: two sets are disjoint if

their intersection is the empty set Further examples

o {1, 2, 3} and {3, 4, 5} are not disjoint

o {a, b} and {3, 4} are disjoint

o {1, 2} and ∅ are disjoint Their intersection is the empty set

o ∅ and ∅ are disjoint! Their intersection is the empty set

4

Page 5: Ch2 2 Set Operations

Set operations: Difference Formal definition for the difference of two sets:

A - B = { x | x ∈ A and x ∉ B } Further examples

o {1, 2, 3} - {3, 4, 5} = {1, 2}

o {a, b} - {3, 4} = {a, b}

o {1, 2} - ∅ = {1, 2} The difference of any set S with the empty set will be the set S

5

Page 6: Ch2 2 Set Operations

Complement sets Formal definition for the complement of a set: A = { x | x ∉ A } = Ac

o Or U – A, where U is the universal set

Further examples (assuming U = Z)

o {1, 2, 3}c = { …, -2, -1, 0, 4, 5, 6, … }

Properties of complement sets

o (Ac)c = A Complementation law o A U Ac = U Complement law o A ∩ Ac = ∅ Complement law

6

Page 7: Ch2 2 Set Operations

Set Identities (equivalence) Set identities is a term used to show equality of two

sets. It is similar to the logical equivalences discussed in

Section 1.2. The table in the next slide lists the most important set

identities. The set identities given can be proved directly from the

corresponding logical equivalences.

7

Page 8: Ch2 2 Set Operations

Set identities

A∪∅ = A A∩U = A

Identity Law A∪U = U A∩∅ = ∅

Domination law

A∪A = A A∩A = A

Idempotent Law (Ac)c = A Complement

Law

A∪B = B∪A A∩B = B∩A

Commutative Law

(A∪B)c = Ac∩Bc (A∩B)c = Ac∪Bc

De Morgan’s Law

A∪(B∪C) = (A∪B)∪C A∩(B∩C)

= (A∩B)∩C

Associative Law

A∩(B∪C) = (A∩B)∪(A∩C) A∪(B∩C) =

(A∪B)∩(A∪C)

Distributive Law

A∪(A∩B) = A A∩(A∪B) = A

Absorption Law

A ∪ Ac = U A ∩ Ac = ∅

Complement Law

8

Page 9: Ch2 2 Set Operations

Example Let A, B, and C be sets. Show that

Solution: We have

9

Page 10: Ch2 2 Set Operations

Membership Tables Set identities can also be proved using membership

tables. Consider each combination of sets that an element can

belong to To indicate that an element is in a set, a 1 is used; To indicate that an element is not in a set, a 0 is used. Notice the similarity between membership tables and

truth tables.

10

Page 11: Ch2 2 Set Operations

Membership Tables (cont.)

11

Page 12: Ch2 2 Set Operations

Computer Representation of Sets One way is to use bitmap First, specify an arbitrary ordering of the elements of U,

for instance . 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.

12

Page 13: Ch2 2 Set Operations

Example 1 U is the set of all students in the class. U = {a,b,c,d,e,f,g,h,i,j,k,l,m} We need to represent

o The students who are in the basketball team {c,d,f,k,m}. Basketball team B = {0011010000101}

o Honor students who have high CGPA {a,d,j,k,m}. Honor list H = {1001000001101}

Basketball team won the tournament and department is doing a party for which both the basketball players and honor students will be invited o B U H

13

Page 14: Ch2 2 Set Operations

0011010000101 1001000001101 ------------------- 1011010001101

What if we only invite those members in the team who are also in

the honor list o B ∩ H

0011010000101 1001000001101 ------------------- 0001000000101

14

{c,d,f,k,m} {a,d,j,k,m}

Example 1- cont’d

Page 15: Ch2 2 Set Operations

Example 2

15

Page 16: Ch2 2 Set Operations

Open Book Problem 2 Write a program, in your preferred language, that takes

two finite sets and lists all elements in the Cartesian product of these two sets. o For simplicity, you can assume all elements are integers

16