Top Banner
Lecture 2.1: Sets and Set Operations CS 250, Discrete Structures, Fall 2014 Nitesh Saxena Adopted from previous lectures by Cinda Heeren
19

Lecture 2.1: Sets and Set Operations CS 250, Discrete Structures, Fall 2014 Nitesh Saxena Adopted from previous lectures by Cinda Heeren.

Jan 20, 2016

Download

Documents

Cameron Booth
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Lecture 2.1: Sets and Set Operations CS 250, Discrete Structures, Fall 2014 Nitesh Saxena Adopted from previous lectures by Cinda Heeren.

Lecture 2.1: Sets and Set Operations

CS 250, Discrete Structures, Fall 2014

Nitesh Saxena

Adopted from previous lectures by Cinda Heeren

Page 2: Lecture 2.1: Sets and Set Operations CS 250, Discrete Structures, Fall 2014 Nitesh Saxena Adopted from previous lectures by Cinda Heeren.

04/21/23Lecture 2.1 -- Sets and Set

Operations

Course Admin HW1 Due

11am 09/18/14 – this Thursday Please follow all instructions Recall: late submissions will not be

accepted

Page 3: Lecture 2.1: Sets and Set Operations CS 250, Discrete Structures, Fall 2014 Nitesh Saxena Adopted from previous lectures by Cinda Heeren.

04/21/23Lecture 2.1 -- Sets and Set

Operations

Outline

Set Definitions and Theory Set Operations

Page 4: Lecture 2.1: Sets and Set Operations CS 250, Discrete Structures, Fall 2014 Nitesh Saxena Adopted from previous lectures by Cinda Heeren.

04/21/23Lecture 2.1 -- Sets and Set

Operations

Set Theory - Definitions and notation

A set is an unordered collection of elements.

Some examples:

{1, 2, 3} is the set containing “1” and “2” and “3.”{1, 1, 2, 3, 3} = {1, 2, 3} since repetition is irrelevant.{1, 2, 3} = {3, 2, 1} since sets are unordered.{1, 2, 3, …} is a way we denote an infinite set (in this

case, the natural numbers).

= {} is the empty set or null set, or the set containing no elements.

U: is the set of all possible elements in the universe

Note: {}

Page 5: Lecture 2.1: Sets and Set Operations CS 250, Discrete Structures, Fall 2014 Nitesh Saxena Adopted from previous lectures by Cinda Heeren.

04/21/23Lecture 2.1 -- Sets and Set

Operations

Set Theory - Definitions and notation

x S means “x is an element of set S.”x S means “x is not an element of set

S.”

A B means “A is a subset of B.”

Venn Diagram

or, “B contains A.”or, “every element of A is also in

B.”or, x ((x A) (x B)).

A

B

Page 6: Lecture 2.1: Sets and Set Operations CS 250, Discrete Structures, Fall 2014 Nitesh Saxena Adopted from previous lectures by Cinda Heeren.

04/21/23Lecture 2.1 -- Sets and Set

Operations

Set Theory - Definitions and notation

A B means “A is a subset of B.”A B means “A is a superset of B.”

A = B if and only if A and B have exactly the same elements.

iff, A B and B Aiff, A B and A B iff, x ((x A) (x B)).

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

• A B• B A

Page 7: Lecture 2.1: Sets and Set Operations CS 250, Discrete Structures, Fall 2014 Nitesh Saxena Adopted from previous lectures by Cinda Heeren.

04/21/23Lecture 2.1 -- Sets and Set

Operations

Set Theory - Definitions and notation

A B means “A is a proper subset of B.” A B, and A B. x ((x A) (x B)) x ((x B) (x A)) x ((x A) (x B)) x ((x B) v (x A)) x ((x A) (x B)) x ((x B) (x A)) x ((x A) (x B)) x ((x B) (x A))

A

B

Page 8: Lecture 2.1: Sets and Set Operations CS 250, Discrete Structures, Fall 2014 Nitesh Saxena Adopted from previous lectures by Cinda Heeren.

04/21/23Lecture 2.1 -- Sets and Set

Operations

Set Theory - Definitions and notation

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

Is {1,2,3}?Yes! x (x ) (x {1,2,3})

holds, because (x ) is false.Is {1,2,3}?No Is {,1,2,3}? Yes

Is {,1,2,3}?Yes

Page 9: Lecture 2.1: Sets and Set Operations CS 250, Discrete Structures, Fall 2014 Nitesh Saxena Adopted from previous lectures by Cinda Heeren.

04/21/23Lecture 2.1 -- Sets and Set

Operations

Set Theory - Definitions and notation

Quiz time:

Is {x} {x}?

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

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

Is {x} {x}?

Yes

Yes

Yes

No

Page 10: Lecture 2.1: Sets and Set Operations CS 250, Discrete Structures, Fall 2014 Nitesh Saxena Adopted from previous lectures by Cinda Heeren.

04/21/23Lecture 2.1 -- Sets and Set

Operations

Set Theory - Ways 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.

Ex. Let D(x,y) denote “x is divisible by y.”Give another name for

{ x : y ((y > 1) (y < x)) D(x,y) }.

: and | are read “such that” or

“where”

Primes

Page 11: Lecture 2.1: Sets and Set Operations CS 250, Discrete Structures, Fall 2014 Nitesh Saxena Adopted from previous lectures by Cinda Heeren.

04/21/23Lecture 2.1 -- Sets and Set

Operations

Set Theory - Cardinality

If S is finite, then the cardinality of S, |S|, is the number of distinct elements in S.

If S = {1,2,3}, |S| = 3.

If S = {3,3,3,3,3},

If S = ,

If S = { , {}, {,{}} },

|S| = 1.

|S| = 0.

|S| = 3.

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

Page 12: Lecture 2.1: Sets and Set Operations CS 250, Discrete Structures, Fall 2014 Nitesh Saxena Adopted from previous lectures by Cinda Heeren.

04/21/23Lecture 2.1 -- Sets and Set

Operations

Set Theory - Power sets

If S is a set, then the power set of S is 2S = { x : x S }.

If S = {a},

aka P(S)

If S = {a,b},

If S = ,

If S = {,{}},

We say, “P(S) is the set of all subsets of S.”

2S = {, {a}}.

2S = {, {a}, {b}, {a,b}}.2S = {}.

2S = {, {}, {{}}, {,{}}}.

Fact: if S is finite, |2S| = 2|S|. (if |S| = n, |2S| = 2n)

Page 13: Lecture 2.1: Sets and Set Operations CS 250, Discrete Structures, Fall 2014 Nitesh Saxena Adopted from previous lectures by Cinda Heeren.

04/21/23

Set Theory - Cartesian Product

The Cartesian Product of two sets A and B is:

A x B = { <a,b> : a A b B}If A = {Charlie, Lucy, Linus},

and B = {Brown, VanPelt}, then

A,B finite |AxB| = ?

A1 x A2 x … x An = {<a1, a2,…, an>: a1 A1, a2 A2, …, an An}

A x B = {<Charlie, Brown>, <Lucy, Brown>, <Linus, Brown>, <Charlie, VanPelt>, <Lucy, VanPelt>, <Linus, VanPelt>}

We’ll use these special

sets soon!

a) AxBb) |A|+|B|c) |A+B|d) |A||B|

Lecture 2.1 -- Sets and Set Operations

Page 14: Lecture 2.1: Sets and Set Operations CS 250, Discrete Structures, Fall 2014 Nitesh Saxena Adopted from previous lectures by Cinda Heeren.

04/21/23Lecture 2.1 -- Sets and Set

Operations

Set Theory - Operators

The union of two sets A and B is:A B = { x : x A v x B}

If A = {Charlie, Lucy, Linus}, and B = {Lucy, Desi}, thenA B = {Charlie, Lucy, Linus, Desi}

AB

Page 15: Lecture 2.1: Sets and Set Operations CS 250, Discrete Structures, Fall 2014 Nitesh Saxena Adopted from previous lectures by Cinda Heeren.

04/21/23Lecture 2.1 -- Sets and Set

Operations

Set Theory - Operators

The 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

Page 16: Lecture 2.1: Sets and Set Operations CS 250, Discrete Structures, Fall 2014 Nitesh Saxena Adopted from previous lectures by Cinda Heeren.

04/21/23Lecture 2.1 -- Sets and Set

Operations

Set Theory - Operators

The intersection of two sets A and B is:A B = { x : x A x B}

If 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} =

ABSets whose

intersection is empty are called

disjoint sets

Page 17: Lecture 2.1: Sets and Set Operations CS 250, Discrete Structures, Fall 2014 Nitesh Saxena Adopted from previous lectures by Cinda Heeren.

04/21/23Lecture 2.1 -- Sets and Set

Operations

Set Theory - Operators

The complement of a set A is:A = { x : x A}

If A = {x : x is bored}, then

A = {x : x is not bored}

A

=

= U and U =

U

Page 18: Lecture 2.1: Sets and Set Operations CS 250, Discrete Structures, Fall 2014 Nitesh Saxena Adopted from previous lectures by Cinda Heeren.

04/21/23Lecture 2.1 -- Sets and Set

Operations

Set Theory - Operators

The set difference, A - B, is:

AU

B

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

A - B = A B

Page 19: Lecture 2.1: Sets and Set Operations CS 250, Discrete Structures, Fall 2014 Nitesh Saxena Adopted from previous lectures by Cinda Heeren.

04/21/23Lecture 2.1 -- Sets and Set

Operations

Today’s Reading Rosen 2.1