set and sets operations

43
1 Lecturer: Shaykhah

Upload: amanda-hatfield

Post on 02-Jan-2016

51 views

Category:

Documents


5 download

DESCRIPTION

Set and Sets Operations. Set definition. Set is the fundamental discrete structure on which all other discrete structures are built. Sets are used to group objects together. Often, the objects in a set have similar properties. A set is an unordered collection of objects . - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Set and Sets Operations

1Lecturer: Shaykhah

Page 2: Set and Sets Operations

Set definitionSet is the fundamental discrete structure on

which all other discrete structures are built.

Sets are used to group objects together. Often, the objects in a set have similar properties.

A set is an unordered collection of objects.

The objects in a set are called the elements, or members, of the set

2Lecturer: Shaykhah

Page 3: Set and Sets Operations

Some Important Sets The set of natural numbers: N = {0, 1, 2, 3, . . .}The set of integers: Z = {. . . ,−2,−1, 0, 1, 2, . . .}The set of positive integers: Z+ = {1, 2, 3, . . .}The set of fractions: Q = {0,½, –½, –5, 78/13,…} Q ={p/q | pЄ Z , qЄZ, and q≠0 }The set of Real: R = {–3/2,0,e,π2,sqrt(5),…}

3Lecturer: Shaykhah

Page 4: Set and Sets Operations

Notation used to describe membership in sets a set A is a collection of elements. If x is an element of A, we write xA; If not: xA. xA Say: “x is a member of A” or “x is in A”.  Note: Lowercase letters are used for elements, capitals for

sets. Two sets are equal if and only if they have the same

elements A= B : x( x A x B)

also Two sets A and B are equal if A B and B

A. So to show equality of sets A and B, show:

A B B A

4Lecturer: Shaykhah

Page 5: Set and Sets Operations

How to describe a set?List all the members of a set, when this is

possible. We use a notation where all members of the set are listed between braces. { }

Example : {dog, cat, horse}Sometimes the brace notation is used to describe

a set without listing all its members. Some members of the set are listed, and then ellipses (. . .) are used when the general pattern of the elements is obvious.

Example: The set of positive integers less than 100 can be

denoted by {1, 2, 3, . . . , 99}.

5Lecturer: Shaykhah

Page 6: Set and Sets Operations

How to describe a set?Another way to describe a set is to use set

builder notation. We characterize all those elements in the set by stating the property or properties they must have to be members.

Example: the set O of all odd positive integers less than

10 can be written as: O = {x | x is an odd positive integer <10}

or, specifying the universe as the set of positive integers, as O = {x Z+ | x is odd and x<10}. 

6Lecturer: Shaykhah

Page 7: Set and Sets Operations

Sets

The Empty Set (Null Set)The Empty Set (Null Set) We use to denote the empty set, i.e. the set with no

elements. For example: the set of all positive integers that are greater than their

squares is the null set.

Singleton setSingleton setA set with one element is called a singleton set.

7Lecturer: Shaykhah

Page 8: Set and Sets Operations

Sets Computer ScienceComputer Science

Note that the concept of a datatype, or type, in computer science is built upon the concept of a set. In particular, a datatype is the name of a set, together with a set of operations that can be performed on objects from that set.

For example, Boolean is the name of the set {0, 1} together with operators on one or more elements of this set, such as AND, OR, and NOT.

8Lecturer: Shaykhah

Page 9: Set and Sets Operations

Module #3 - Sets

04/20/23 (c)2001-2003, Michael P. Frank

Computer Representation of Sets

• Let U = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}. The bit string (of length |U| = 10) that represents the set A = {1, 3, 5, 6, 9} has a one in the first, third, fifth, sixth, and ninth position, and zero elsewhere. It is

1 0 1 0 1 1 0 0 1 0.

Page 10: Set and Sets Operations

SetsVenn diagramsVenn diagrams 

Sets can be represented graphically using Venn diagrams.

In Venn diagrams the universal set U, which contains all the objects under consideration, is represented by a rectangle.

Inside this rectangle, circles or other geometrical figures are used to represent sets.

 Sometimes points are used to represent the particular elements of the set.

10Lecturer: Shaykhah

Page 11: Set and Sets Operations

SetsExample: A Venn diagram that represents V = {a, e, i,

o, u}, the set of vowels in the English alphabet

11Lecturer: Shaykhah

Page 12: Set and Sets Operations

Subset The 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 the notation A B to indicate that A is a subset of the set B.  

We see that A B if and only if the quantification x (x A → x B) is true. 

12Lecturer: Shaykhah

Page 13: Set and Sets Operations

SubsetsFor every set S,

1. S2. S S

Proper subset:When a set A is a subset of a set B but A ≠ B,

A B, and A B.We write A B and say that A is a proper subset of B

For A B to be true, it must be the case that x ((x A) (x B)) x ((x B) (x A))

13Lecturer: Shaykhah

Page 14: Set and Sets Operations

SubsetsQuick examples:{1,2,3} {1,2,3,4,5}{1,2,3} {1,2,3,4,5}

Is {1,2,3}?Is {1,2,3}?Is {,1,2,3}?Is {,1,2,3}?

No !

Yes !

Yes !

Yes !Because to conclude it isn’t a subset we have to find an

element in the null set that is not in the set {1,2,3}. Which is not the case

14Lecturer: Shaykhah

Page 15: Set and Sets Operations

SubsetsQuiz Time:

Is {x} {x,{x}}?

Is {x} {x,{x}}?

Is {x} {x}?

Is {x} {x}?

Yes !

Yes !

Yes !

No !

15Lecturer: Shaykhah

Page 16: Set and Sets Operations

Finite and Infinite SetsFinite setFinite set

Let S be a set. If there are exactly n distinct elements in S where n is a nonnegative integer, we say that S is a finite set and that n is the cardinality of S.

The cardinality of S is denoted by |S|. |A B| = |A| + |B| - |A B| Infinite setInfinite set

A set is said to be infinite if it is not finite. For example, the set of positive integers is infinite.

 

16Lecturer: Shaykhah

Page 17: Set and Sets Operations

CardinalityFindS = {1,2,3}, S = {3,3,3,3,3}, S = , S = { , {}, {,{}} },S = {0,1,2,3,…}, |S| is infinite

|S| = 3.

|S| = 1.

|S| = 0.

|S| = 3.

17Lecturer: Shaykhah

Page 18: Set and Sets Operations

SetsWays to Define Sets:

Explicitly: {John, Paul, George, Ringo}

Implicitly: {1,2,3,…}, or {2,3,5,7,11,13,17,…}

Set builder: { x : x is prime }, { x | x is odd }. In general { x :

P(x) is true }, where P(x) is some description of the set.

18Lecturer: Shaykhah

Page 19: Set and Sets Operations

The power of a set Many problems involve testing all combinations of

elements of a set to see if they satisfy some property. To consider all such combinations of elements of a set

S, we build a new set that has as its members all the subsets of S.

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

if a set has n elements , then the power has 2n elements

19Lecturer: Shaykhah

Page 20: Set and Sets Operations

The power of a set Example:What is the power set of the set {0, 1, 2}? P({0,1,2}) is the set of all subsets of {0, 1, 2} P({0,1,2})= { , {0},{1},{2},{0,1},{0,2},

{1,2},{0,1,2}}

What is the power set of the empty set? What is the power set of the set {}

P()= {} P({})= {,{}}

N.B. the power set of any subset has at least two

elementsThe null set and the set

itself20Lecturer: Shaykhah

Page 21: Set and Sets Operations

The Power SetQuick Quiz:Find the power set of the following:

S = {a},

S = {a,b},

S = ,

S = {,{}},

P(S)= {, {a}}.

P(S) = {, {a}, {b}, {a,b}}.

P(S) = {}.

P(S) = {, {}, {{}}, {,{}}}.

21Lecturer: Shaykhah

Page 22: Set and Sets Operations

Cartesian Products The order of elements in a collection is

often important. Because sets are unordered, a different

structure is needed to represent ordered collections.

This is provided by ordered n-tuples. The ordered n-tuple (a1, a2, . . . , an) is the

ordered collection that has a1 as its first element, a2 as its second element, . . . , and an as its nth element.

22Lecturer: Shaykhah

Page 23: Set and Sets Operations

Cartesian ProductsLet A and B be sets. The Cartesian product of

A and B, denoted by A×B, is the set of all ordered pairs (a, b), where aA and bB.

A×B = {(a, b) | a A b B}.

A1×A2×…×An=

{(a1, a2,…, an) | aiAi for i=1,2,…,n}.

A×B not equal to B×A

23Lecturer: Shaykhah

Page 24: Set and Sets Operations

Cartesian ProductsExample:

What is the Cartesian product A × B × C, where

A = {0, 1}, B = {1, 2}, and C = {0, 1, 2}?Solution:AxBxC = {(0,1,0), (0,1,1), (0,1,2), (0,2,0),

(0,2,1), (0,2,2), (1,1,0), (1,1,1), (1,1,2), (1,2,0), (1,2,1), (1,2,2)}

24Lecturer: Shaykhah

Page 25: Set and Sets Operations

Notation with QuantifiersWhenever we wrote xP(x) or xP(x), we

specified the universe of using explicit English language

Now we can simplify things using set notation!

ExamplexR (x20) xZ (x2=1)Also mixing quantifiers:

a,b,cR xC(ax2+bx+c=0)25Lecturer: Shaykhah

Page 26: Set and Sets Operations

Sets Operations

26Lecturer: Shaykhah

Page 27: Set and Sets Operations

UNIONThe union of two sets A and B is:

A B = { x : x A v x B}If A = {1, 2, 3}, and B = {2, 4}, thenA B = {1,2,3,4}

AB

27Lecturer: Shaykhah

Page 28: Set and Sets Operations

IntersectionThe intersection of two sets A and B is:

A B = { x : x A x B}If A = {Charlie, Lucy, Linus}, and B = {Lucy,

Desi}, thenA B = {Lucy}

AB

28Lecturer: Shaykhah

Page 29: Set and Sets Operations

IntersectionIf A = {x : x is a US president}, and

B = {x : x is deceased}, then

A B = {x : x is a deceased US president}

AB

29Lecturer: Shaykhah

Page 30: Set and Sets Operations

DisjointIf A = {x : x is a US president}, and B = {x : x is in this room},

then

A B = {x : x is a US president in this room} =

Sets whose intersection is empty are

called disjoint sets

AB

30Lecturer: Shaykhah

Page 31: Set and Sets Operations

ComplementThe complement of a set A is:

A = A’ = { x : x A}If A = {x : x is bored}, thenA = {x : x is not bored} =

AU

= Uand

U =

A B = B A

31Lecturer: Shaykhah

Page 32: Set and Sets Operations

Module #3 - Sets

04/20/23 (c)2001-2003, Michael P. Frank

Example

Let A and B are two subsets of a set E such that AB = {1, 2}, |A|= 3, |B| = 4, A = {3, 4, 5, 9} and B = {5, 7, 9}. Find the sets A, B and E.

E

A = {1, 2, 7}, B = {1, 2, 3, 4},

E = {1, 2, 3, 4, 5, 7, 9}

A 7 1 3 B 2 4 5 9

Page 33: Set and Sets Operations

DifferenceThe set difference, A - B, is:

A - B = { x : x A x B }A - B = A B

A

U

B

33Lecturer: Shaykhah

Page 34: Set and Sets Operations

Symmetric DifferenceThe symmetric difference, A B, is:

A B = { x : (x A x B) v (x B x

A)}

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

U

B

Like“ exclusive or”

34Lecturer: Shaykhah

Page 35: Set and Sets Operations

Symmetric DifferenceExampleLet A = {1,2,3,4,5,6,7}

B = {3,4,p,q,r,s}Then we have

A U B = {1,2,3,4,5,6,7,p,q,r,s}A B = {3,4}

We getA B = {1,2,5,6,7,p,q,r,s}

35Lecturer: Shaykhah

Page 36: Set and Sets Operations

Proving Set Equivalences• Recall that to prove such identity, we must

show that:1. The left-hand side is a subset of the right-hand

side2. The right-hand side is a subset of the left-hand

side3. Then conclude that the two sides are thus equal

• The book proves several of the standard set identities.

• We will give a couple of different examples here.

36Lecturer: Shaykhah

Page 37: Set and Sets Operations

Proving Set Equivalences: Example A (1)Let

A={x|x is even} B={x|x is a multiple of 3}C={x|x is a multiple of 6}

Show that AB=C

37Lecturer: Shaykhah

Page 38: Set and Sets Operations

Proving Set Equivalences: Example A (2)AB C: x AB

x is a multiple of 2 and x is a multiple of 3 we can write x=2.3.k for some integer k x=6k for some integer k x is a multiple of 6 x C

CAB: x C x is a multiple of 6 x =6k for some integer k x=2(3k)=3(2k) x is a multiple of 2 and of 3 x AB

38Lecturer: Shaykhah

Page 39: Set and Sets Operations

Proving Set Equivalences: Example B (1)An alternative prove is to use membership

tables where an entry is1 if a chosen (but fixed) element is in the set0 otherwise

Example: Show that

A B C = A B C

39Lecturer: Shaykhah

Page 40: Set and Sets Operations

Proving Set Equivalences: Example B (2)A B C ABC ABC A B C ABC

0 0 0 0 1 1 1 1 1

0 0 1 0 1 1 1 0 1

0 1 0 0 1 1 0 1 1

0 1 1 0 1 1 0 0 1

1 0 0 0 1 0 1 1 1

1 0 1 0 1 0 1 0 1

1 1 0 0 1 0 0 1 1

1 1 1 1 0 0 0 0 0

• 1 under a set indicates that an element is in the set

• If the columns are equivalent, we can conclude that indeed the two sets are equal

40Lecturer: Shaykhah

Page 41: Set and Sets Operations

TABLE 1: Set Identities

Identity Name

A U = AA U = A Identity laws

A U U = UA =

Domination laws

A U A = AA A = A Idempotent laws

(A) = A Complementation laws

A U B = B U AA B = B A

Commutative laws

A U (B U C) = (A U B) U CA (B C) = (A B) C

Associative laws

A (B U C) = (A B)U(A C)A U(B C) = (A U B) (A U C)

Distributive laws

A U B = A BA B = A U B

De Morgan’s laws

A U (A B) = AA (A U B) = A

Absorption laws

A U A = UA A = Complement laws

41Lecturer: Shaykhah

Page 42: Set and Sets Operations

Let’s proof one of the Identities Using a Membership Table

TABLE 2: A Membership Table for the Distributive Property

A B C B U C A (B U C)

A B A C (A B) U (A C)

1 1 1 1 1 1 1 1

1 1 0 1 1 1 0 1

1 0 1 1 1 0 1 1

1 0 0 0 0 0 0 0

0 1 1 1 0 0 0 0

0 1 0 1 0 0 0 0

0 0 1 1 0 0 0 0

0 0 0 0 0 0 0 0

42Lecturer: Shaykhah

A (B U C) = (A B)U(A C)

Page 43: Set and Sets Operations

ANY QUESTIONS???Refer to chapter 2 of the book for further

reading

43Lecturer: Shaykhah