lecture 2 introduction to sets

23
Lecture 2 Introduction To Sets CSCI – 1900 Mathematics for Computer Science Fall 2014 Bill Pine

Upload: latham

Post on 07-Jan-2016

38 views

Category:

Documents


0 download

DESCRIPTION

Lecture 2 Introduction To Sets. CSCI – 1900 Mathematics for Computer Science Fall 2014 Bill Pine. Lecture Introduction. Reading Rosen - Section 2.1 Set Definition and Notation Set Description and Membership Power Set and Universal Set Venn Diagrams. Set Definition. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Lecture 2 Introduction To Sets

Lecture 2Introduction To Sets

CSCI – 1900 Mathematics for Computer Science

Fall 2014

Bill Pine

Page 2: Lecture 2 Introduction To Sets

CSCI 1900 Lecture 2 - 2

Lecture Introduction

• Reading– Rosen - Section 2.1

• Set Definition and Notation• Set Description and Membership• Power Set and Universal Set• Venn Diagrams

Page 3: Lecture 2 Introduction To Sets

CSCI 1900 Lecture 2 - 3

Set Definition

• Set: any well-defined collection of objects– The objects are called set members or elements– Well-defined - membership can be verified with a

Yes/No answer• Three ways to describe a set

– Describe in English• S is a set containing the letters a through k, inclusively

– Roster method - enumerate using { } ‘Curly Braces’• S = {a, b, c, d, e, f, g, h, i, j, k}

– Set builder method ; Specify common properties of the members• S = { x | x is a lower case letter between a and k, inclusively}

Page 4: Lecture 2 Introduction To Sets

CSCI 1900 Lecture 2 - 4

Set Description Examples

• Star Wars films• S = {car, cat, C++,

Java}• {a,e,i,o,u,y} • The 8 bit ASCII

character set

• Good SciFi Films• S = { 1, car, cat, 2.03,

…}• a,e,i,o,u & sometimes y• The capital letters of the

alphabet

Good Not So Good

Page 5: Lecture 2 Introduction To Sets

CSCI 1900 Lecture 2 - 5

Finite Set Examples

• Coins– C = {Penney, Nickel, Dime, Quarter,

Fifty‑Cent, Dollar}

• Data types– D = {Text, Integer, Real Number}

• A special set is the empty set, denoted by – Ø – { }

Page 6: Lecture 2 Introduction To Sets

CSCI 1900 Lecture 2 - 6

Infinite Set Examples

• The set of all integers Z – Z = { …, -3, - 2, -1, 0, 1, 2, 3, …}

• The set of positive Integers Z + (Counting numbers)– Z + = { 1, 2, 3, …}

• The set of whole numbers W – W = { 0, 1, 2, 3, …}

• The Real Numbers R – Any decimal number

• The Rational Numbers Q– Any number that can be written as a ratio of two integers

• Example of a number that is in R but not in Q ?

Page 7: Lecture 2 Introduction To Sets

CSCI 1900 Lecture 2 - 7

Additional Set Description

• The set of even numbers E – E is the set containing … -8, -6, -4, -2, 0, 2, 4, 6, 8, …– E = any x that is 2 * some integer– E = Set of all x | x = 2*y where y is an integer– E ={ x | x = 2*y where y is an integer }– E = { x | x = 2*y where y is in Z }– E = { x | x = 2*y where y Z }

Page 8: Lecture 2 Introduction To Sets

CSCI 1900 Lecture 2 - 8

Set Membership

• x is an element of A is written x A– Means that the object x is in the set A

• x is not an element of A is written x A• Given: S={1, -5, 9} and Z+ the positive

Integers– 1 S 1 Z+ – -5 S -5 Z+ – 2 S 2 Z+

Page 9: Lecture 2 Introduction To Sets

CSCI 1900 Lecture 2 - 9

Set Ordering and Duplicates

• Order of elements does not matter– {1, 6, 9} = {1, 9, 6} = {6, 9, 1}

• Repeated elements do not matter– {1, 1, 1, 1, 2, 3} = {1, 2, 3} = {1, 2, 2, 3}

Page 10: Lecture 2 Introduction To Sets

CSCI 1900 Lecture 2 - 10

Set Equality

• Two sets are equal if and only if they have the same elements– S1 = {1, 6, 9} – S2 = {1, 9, 6} – S3 = {1, 6, 9, 6}

• S1 = S2 - same elements just reordered• S2 = S3 - remember duplicates do not

change the set• Since S1= S2 and S2 = S3 then S1=S3

Page 11: Lecture 2 Introduction To Sets

CSCI 1900 Lecture 2 - 11

Subsets

• A is a subset of B, if and only if every element of set A is an element of set B– Denoted A B

• Examples– {Kirk, Spock} {Kirk, Spock, Uhura}– {Kirk, Spock} {Kirk, Spock}

• For any set S, S S is always true– {Kirk, Sulu} {Kirk, Spock, Uhura}

Page 12: Lecture 2 Introduction To Sets

CSCI 1900 Lecture 2 - 12

Proper Subsets

• If every element of set A is an element of set B, AND A≠B then A is a proper subset of B, denoted A B

• Examples– {1,2} {1,2,3}– {2} {1,2,3}– {3,3,3,1} {1,2,3}– {1,2,3} {1,2,3}

• But {1,2,3} {1,2,3}– {2,3,1} {1,2,3}

• But {2,3,1} {1,2,3}

Page 13: Lecture 2 Introduction To Sets

CSCI 1900 Lecture 2 - 13

Membership and Subset Exercise

Given: D = { 1, 2, {1}, {1,3}} • Is 1 D ?

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

?

Page 14: Lecture 2 Introduction To Sets

CSCI 1900 Lecture 2 - 14

Subsets and Equality

• Given: Two sets A and B– If you know that A B and B A then you can

conclude that A = B– If A B then it must be true that B A

Page 15: Lecture 2 Introduction To Sets

CSCI 1900 Lecture 2 - 15

Power Set

• The power set P of a set S is a set containing every possible unique subset of S– Written as P(S)

• P(S) always includes– S itself – The empty set

Page 16: Lecture 2 Introduction To Sets

CSCI 1900 Lecture 2 - 16

Power Set Example

• Given: S = {x,y,z}• P(S) = {, {x}, {y}, {z}, {x,y}, {y,z}, {x,z},

{x,y,z} }• Nota Bene

– If there are n elements in a set S then there are elements in the power set P(S)

Page 17: Lecture 2 Introduction To Sets

CSCI 1900 Lecture 2 - 17

Set Size

• The cardinality of set S, denoted |S|, is the number distinct elements of S.– if S = {1,3,4,1}, then |S|=3– |{1,3,3,4,4,1}| = 3– |{2, 3, {2}, 5} | = 4– |{ 2, 3, {2,3}, 5, { 2,{2,5} } }| = 5– |Z | = ∞– |Ø| = 0

• A set is finite if it contains exactly n elements– Otherwise the set is infinite

Page 18: Lecture 2 Introduction To Sets

CSCI 1900 Lecture 2 - 18

Universal Set

• There is no largest set containing everything• We will use a (different) Universal Set, U,

for each discussion– It is the set of all possible elements of the type

we want to discuss, for each particular problem

• For an example involving even and odd integers we might say U = Z

Page 19: Lecture 2 Introduction To Sets

CSCI 1900 Lecture 2 - 19

Venn Diagrams

– A graphic way to show sets and subsets, developed by John Venn in the 1880’s

– A set is shown as a Circle or Ellipse, and the Universal set as a rectangle or square

– This shows that S1 Z, and if x S1 then x Z

U = Z

S1 = Integers divisible by 2

Page 20: Lecture 2 Introduction To Sets

CSCI 1900 Lecture 2 - 20

Venn Diagrams: Subsets

U = Z

S1 = Integers divisible by 2

This shows that

S1 Z and S2 Z and S2 S1

If x S2 then x S1, if x S1 then x Z, if x S2 then x Z

S2 = Integers divisible by 4

Page 21: Lecture 2 Introduction To Sets

CSCI 1900 Lecture 2 - 21

Venn Diagrams: Subsets 2

U = Z

S1 = Integers divisible by 2S3 = Integers divisible by 5

This shows that S1 Z and S3 Z, if x S1 then x Z, if x

S3 then x Z, and there exists at least one element y such that

y Z and y S1 and y S3

Page 22: Lecture 2 Introduction To Sets

CSCI 1900 Lecture 2 - 22

Venn Diagram Exercise

• Draw a Venn Diagram representation for the following example:– U = { x | x W and x < 10 }– A= {1, 3, 5, 7, 9}– B = { 1, 5, 7}– C = {1, 5, 7, 8}

Page 23: Lecture 2 Introduction To Sets

CSCI 1900 Lecture 2 - 23

Key Concepts Summary

• Definition of a set• Ways of describing a set• Power sets and the Universal set• Set Cardinality• Draw and interpret Venn Diagrams