sets - csc.villanova.edumap/1300/s20/02sets4up.pdf · csc 1300 –discrete structures 2. sets dr...

6
CSC 1300 – Discrete Structures 2. Sets Dr Papalaskari 1 Sets CSC 1300 – Discrete Structures Villanova University Villanova CSC 1300 - Dr Papalaskari 1 Major Themes Sets Ways of defining sets Set operations Powerset of a set Venn diagrams Set identities Cartesian product of two sets Partitions Villanova CSC 1300 - Dr Papalaskari 2 Basic terminology A set is an unordered collection of distinct objects called elements or members of the set. The notation x Î S means x is an element of SExample : S = {2, 4, 6, 8} 2 Î S 2 is an element of S3 Ï S 3 is not an element of SExample : S = {{2, 4},{ 6}, 8}, {2, 4} Î S {2,4} is an element of S2 Ï S 2 is not an element of SA multiset or a bag is an unordered collection of objects that are not necessarily distinct. Villanova CSC 1300 - Dr Papalaskari 3 Sets and cardinality The cardinality of a set S, denoted |S|, is the number of members of S. Example : Let A = {a, b, c}, B = {1, 2} |A| = 3 |B| = 2 Example : S = {2, 4, 6, 8} |S| = Example : S = {{2, 4},{ 6}, 8}, |S| = Villanova CSC 1300 - Dr Papalaskari 4

Upload: others

Post on 30-Sep-2020

7 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Sets - csc.villanova.edumap/1300/s20/02sets4up.pdf · CSC 1300 –Discrete Structures 2. Sets Dr Papalaskari 3 Set equality Two sets Sand Tare equal,denotedS = T,iff they have the

CSC 1300 – Discrete Structures 2. Sets

Dr Papalaskari 1

Sets

CSC 1300 – Discrete StructuresVillanova University

Villanova CSC 1300 - Dr Papalaskari

1

Major Themes

• Sets–Ways of defining sets – Set operations– Powerset of a set– Venn diagrams– Set identities– Cartesian product of two sets– Partitions

Villanova CSC 1300 - Dr Papalaskari

2

Basic terminology

A set is an unordered collection of distinct objects called elements or members of the set. The notation x Î S means “x is an element of S”Example: S = {2, 4, 6, 8}2 Î S — “2 is an element of S”

3 Ï S — “3 is not an element of S”

Example: S = {{2, 4},{ 6}, 8}, {2, 4} Î S — “{2,4} is an element of S”2 Ï S — “2 is not an element of S”

A multiset or a bag is an unordered collection of objects that are not necessarily distinct.

Villanova CSC 1300 - Dr Papalaskari

3

Sets and cardinality

The cardinality of a set S, denoted |S|, is the number of members of S.Example: Let A = {a, b, c}, B = {1, 2}

|A| = 3 |B| = 2

Example: S = {2, 4, 6, 8} |S| =

Example: S = {{2, 4},{ 6}, 8}, |S| =

Villanova CSC 1300 - Dr Papalaskari

4

Page 2: Sets - csc.villanova.edumap/1300/s20/02sets4up.pdf · CSC 1300 –Discrete Structures 2. Sets Dr Papalaskari 3 Set equality Two sets Sand Tare equal,denotedS = T,iff they have the

CSC 1300 – Discrete Structures 2. Sets

Dr Papalaskari 2

Some important sets

• ℕ = { 1, 2, 3, …} - the set of natural numbers• ℤ = {…, -2, -1, 0, 1, 2, …} - the set of integers• ℤ2 = {0, 1} - the binary digits• ℝ - the set of real numbers• ℚ = {x | x = p/q where p, q Î Z, q ¹ 0} - the set

of rational numbers• The empty (or null) set, denoted by Æ, or { }.

Villanova CSC 1300 - Dr Papalaskari

5

Describing sets

1. Informally: “The set of even positive integers less than ten”

2. Listing the elements: S = {2, 4, 6, 8}

3. By a property:A = { x | x is an even positive integer, x < 10}B = {x Î ℤ | x is even & 0 < x < 10} C = { x Î ℤ | x/2 Î ℤ and 0 < x < 10 }D = { 2x | x Î ℤ and 0 < x < 5 }

Villanova CSC 1300 - Dr Papalaskari

6

Subsets𝑆 is a subset of 𝑇, denoted 𝑆 ⊆ 𝑇 iff every element of 𝑆 is also an element of 𝑇.

Examples: {a, b} Í {a, b, c}{a, b, c} Í {a, b, c}ℤ Í ℚ𝑆 ⊆ 𝑆 (for every 𝑆) ∅ ⊆ 𝑆 (for every 𝑆)

𝑆 is a proper subset of 𝑇, denoted 𝑆 ⊂ 𝑇, iff 𝑆 ⊆ 𝑇, but T ⊈ 𝑆.

Examples: {a, b} Ì {a,b,c} {b} Ì {a, b, c} what about ÆÌ S ???

Villanova CSC 1300 - Dr Papalaskari

7

True or False?

Villanova CSC 1300 - Dr Papalaskari

! ∈ {!}! ⊆ {!}{!} ∈ {!}{!} ⊆ {!}∅ ∈ {!}∅ ⊆ {!}{∅} ⊆ {!}∅ ⊆ ∅∅ ∈ ∅

8

Page 3: Sets - csc.villanova.edumap/1300/s20/02sets4up.pdf · CSC 1300 –Discrete Structures 2. Sets Dr Papalaskari 3 Set equality Two sets Sand Tare equal,denotedS = T,iff they have the

CSC 1300 – Discrete Structures 2. Sets

Dr Papalaskari 3

Set equalityTwo sets S and T are equal, denoted S = T, iffthey have the same elements, i.e., for every x:

if x Î S then x Î T and if x Î T then x Î SIn other words:

S=T iff SÍT and TÍS

Villanova CSC 1300 - Dr Papalaskari

Examples: • {a,b} = {b,a}• {1, 2, 3} = {x | x is an integer and 0 < x < 4}• {2, 4, 6} = { x | x = 2*y, where y Î {1, 2, 3} }

9

The Power Set

Villanova CSC 1300 - Dr Papalaskari

The power set of a set S is the set of all subsets of S. The power set of S is denoted by P(S).

P(Æ) =

P({a}) =

P({a,b}) = {Æ, {a}, {b}, {a,b}}

P({0, 1, 2}) =

What can we say about |P(S)| ?

10

The Universal Set

Villanova CSC 1300 - Dr Papalaskari

What does this even mean????

We usually think of sets as subsets of a universal set U. Example: {a,b} and {b,d,e} è U = {a,b,c,d,e}

(or maybe U = {a,b,c,d,e,f,g,…,z} - often determined by context)

Two sets S and T are equal, denoted S = T, iffthey have the same elements, i.e., for every x::

if x Î S then x Î T and if x Î T then x Î Sfor every x

11

Venn diagrams

Villanova CSC 1300 - Dr Papalaskari

U

S T

SÍT

S T

disjoint sets

U

S T

Two sets (in general)

U

S

T

Three sets

U

X

12

Page 4: Sets - csc.villanova.edumap/1300/s20/02sets4up.pdf · CSC 1300 –Discrete Structures 2. Sets Dr Papalaskari 3 Set equality Two sets Sand Tare equal,denotedS = T,iff they have the

CSC 1300 – Discrete Structures 2. Sets

Dr Papalaskari 4

Villanova CSC 1300 - Dr Papalaskari

Venn Diagrams in popular culture

http://tothelabagain.blogspot.com/2011/10/rq-whats-difference-between-heaven-hell.htmlhttps://imgur.com/Cmc2EgUhttps://openlab.citytech.cuny.edu/mmerette-eportfolio/2017/11/01/funny-venn-diagram/

13

Set Union and Intersection

Villanova CSC 1300 - Dr Papalaskari

S È T = {x | xÎS or xÎT} S Ç T = {x | xÎS and xÎT}

S T S T

S È T is shaded S Ç T is shaded

Example: Let S={1,2,3,4} and T={2,3,5}. Then

S È T = S Ç T =

U U

14

Complement, set difference, symmetric difference

The complement of S, denoted S is the set of elements of U that are not in S.

Example: Let U = {a, b, c, d, e, f}.

{b,d,e} =

The set difference, denoted S – T (or S \ T ), is the set of elements of S that are NOT also in T.

Example: {c,d,e} – {a,b,d} =

The symmetric difference, denoted S ⊕ T, is the set of elements of S that are NOT also in T or in T and NOT also in S.

Example: {a,b,c} ⊕ {b,d,e} =

Villanova CSC 1300 - Dr Papalaskari

15

Set identities

Villanova CSC 1300 - Dr Papalaskari

SÈÆ = S IdentitySÇU = S laws

SÈU = U DominationSÇÆ = Æ laws

SÈS = S IdempotentSÇS = S laws

SÈT = TÈS CommutativeSÇT = TÇS laws

Complementation(S) = S law

SÈ(TÈR) = (SÈT)ÈR AssociativeSÇ(TÇR) = (SÇT)ÇR laws

SÇ(TÈR) = (SÇT)È(SÇR) DistributiveSÈ(TÇR) = (SÈT)Ç(SÈR) laws

S È T = S Ç T De Morgan’sS Ç T = S È T laws

|SÈT| = |S| + |T| - |SÇT| Inclusion-exclusion

16

Page 5: Sets - csc.villanova.edumap/1300/s20/02sets4up.pdf · CSC 1300 –Discrete Structures 2. Sets Dr Papalaskari 3 Set equality Two sets Sand Tare equal,denotedS = T,iff they have the

CSC 1300 – Discrete Structures 2. Sets

Dr Papalaskari 5

Illustrating the Distributive Law

Villanova CSC 1300 - Dr Papalaskari

Now try this: S Ç T = S È T (de Morgan’s Law for sets).

17

Generalized unions and intersections

Villanova CSC 1300 - Dr Papalaskari

S1 ÇS2 Ç... ÇSn denoted by ÇSii=1

n

S1 È S2 È... È Sn denoted by ÈSii = 1

n

i=1

n

ÇSi = and ÈSi = i=1

n

Example: Let Si = { i }.

18

Cartesian product

Let A = {a, b, c}, B = {1, 2}The cartesian product is the set of ordered pairs (x,y) where x ε A and y ε B:

A x B = { (a, 1), (a, 2), (b, 1), (b, 2), (c, 1), (c, 2) }

Product Principle: |A x B| = |A| · |B|

Villanova CSC 1300 - Dr Papalaskari

19

Ordered pairs and n-tuples

Villanova CSC 1300 - Dr Papalaskari

ordered pairs (a1, a2) and ordered n-tuples (a1, a2, …, an) represent sequences:• order of elements matters• repetitions are allowed

The Cartesian product of the sets S1, S2, …, Sn, denoted by S1 × S2 × … × Sn, is the set of all ordered n-tuples (s1,s2,…,sn) where s1Î S1, s2Î S2, …, snÎ Sn. In other words,

S1×S2×…×Sn = {(s1,s2,…,sn) | s1Î S1 and s2Î S2 and … and snÎ Sn}

20

Page 6: Sets - csc.villanova.edumap/1300/s20/02sets4up.pdf · CSC 1300 –Discrete Structures 2. Sets Dr Papalaskari 3 Set equality Two sets Sand Tare equal,denotedS = T,iff they have the

CSC 1300 – Discrete Structures 2. Sets

Dr Papalaskari 6

Exercise:

Villanova CSC 1300 - Dr Papalaskari

21

Partitions

Villanova CSC 1300 - Dr Papalaskari

A partition of a set X is a collection of disjoint nonemptysubsets of X that have X as their union.

XX1

The collectionX1, X2, X3, X4 X2 X4

is a partition of XX3

22

Partitions - Example

Villanova CSC 1300 - Dr Papalaskari

Let X = |A U B U C U D| whereA = {0, 4, 8}, B = {1, 5}, C = {2, 6}, D = {3, 7}

The sets A, B, C, D form a partition of X

XA

0 4 8

B1 5

C2 6

D3 7

23

Exercises:

Villanova CSC 1300 - Dr Papalaskari

Let A = {1, 2, 3, …, 15}.

• Give an example of a partition consisting of 5 subsets of A

• Give an example of a partition consisting of 3 subsets of A

List all partitions of the set B = {a, b, c}.

24