sets cslu 1100.003 fall 2007 cameron mcinally [email protected] fordham university
TRANSCRIPT
Sets
• When Georg Cantor invented sets he described them as...
“By a set we understand any collection S of definite, distinct objects s of our perception or of our thought into a whole.”
• What that means…“A set is a group of objects, with no duplicates.”
Sets• Set basics:
– Sets are always enclosed in curly brackets. E.g.{a}
– Objects in sets are separated by commas. E.g.{a,b,c,apple,e}
– Sets can contain other sets. E.g.{a,b,{joe,d},e}
– Sets can be empty. E.g.
{}
Sets
• 2 major rules:
1. Don’t list any object more than once in a set
2. The order of a set does not matter
Sets
• 2) The order of a set does not matter:
{a,b,c,d,e} != {e,d,c,a,f}{a,b,c,d,e} == {e,d,c,b,a}{a,b,c,d,e} == {b,e,d,a,c}
Sets
• To represent a set as a whole, we use capital letter names. E.g.
A = {x,y,z}
• So, we can say that set A contains elements x, y and z.
Sets
• Cardinality– Cardinality is the size of a set.– If set A contains 3 elements, we can write…
|A| = 3
Sets
• What is the size of each of these sets?
A = {a,b,c,d,e,f,g}B = {x,y,z}C = {{},{},10,11}D = {}E = {{a,b},{c,d}}
|A| = 7
|B| = 3
|C| = Not a Set!!|D| = 0|E| = 2
Sets
• Infinite Sets– “N” is the natural numbers {0, 1, 2, 3, 4, 5, …}– “Z” is the set of integers {…-2,-1,0,1,2,…}– “Q” is the set of rational numbers (any number
that can be written as a fraction– “R” is the set of real numbers (all the
numbers/fractions/decimals that you can imagine
Sets
• What is the cardinality?– A = {alpha, beta, gamma}– B = {-5,0,5,10}– C = {{a,{b}},{c,d}}– D = {{},{},10,11}– E = {}
|A| =
|B| + |C| =
|D| + |E| - |A| =
|B| + |D| =
3
6
1
7
Sets
• Set Builder Notation– How do we represent the elements in a set,
without specifically writing them out.
– This is read, “x, such that x is an element of N”. • In general;
– “:” means “such that”– “Є“ means “element of”
– Here, N is the set of Natural Numbers.
}:{ Nxx
Sets
• Set builder notation:
– Everything before the “:” gives a description of what values we want to include in our set
– Everything after the “:” places constraints on which of the values mentioned in the first half we will actually use.
}:{ Nxx
Sets
• Examples of Set Builder Notation
}3
&:{
}3,2,1{&2:{
}52:{
Nx
Nxx
kkxx
xx
}5.2{
}6,4,2{
,...}12,9,6,3,0{
Sets
• Understanding Set Builder Notation – http://storm.cis.fordham.edu/~kinley/classes/
summer06/cseu1100/flash/ch3/sec3_1/setNotation.html
Sets
{}
}15,10,5,0{
}8,6,4,2,0{
}5,4,3,2,1{
D
C
B
A
BAABDC)()( BDCA
}8,6,5,4,3,2,1,0{
}8,6,5,4,3,2,1,0{}15,10,5,0{
}15,10,8,6,5,4,3,2,1,0{
Sets
• Intersection ( )– This creates a new set that contains the elements
that both A and B have in common. Other elements are discarded.
BA
Sets
• Difference (-)– This creates a new set that contains the elements
of set A without any element in set B.
BA
Sets
{}
}15,10,5,0{
}8,6,4,2,0{
}5,4,3,2,1{
D
C
B
A
BA AB DC )()( BDCA
}3,2,1{
}8,6,0{}15,10,5,0{
}4,3,2,1{
Sets
• Practice– Set Operations• http://storm.cis.fordham.edu/~kinley/classes/
summer06/cseu1100/flash/ch3/sec3_1/setoperations.html
Sets
• Power Set (2S)– Given a set S, this creates a set which contains all
the subsets of S.– Power Sets include the empty set.– Power Sets include the set S.
– Power Sets are represented by 2S
– Power Sets can also be written as P(S)
Sets
• Power SetFor A = {1,2,3}
2a = P(A)= {{},{1},{2},{3},{1,2},{1,3},{2,3},{1,2,3}}
For B = {a,b,c,d} 2B = P(B) = {{},a,b,c,d,{a,b}, {a,c}, {a,d}, {b,c}, {b,d}, {c,d},{a,b,c}, {a,b,d}, {a,c,d}, {b,c,d}, {a,b,c,d}}
Sets
• Cartesian Product (X)
– Creates a set consisting of all coordinate pairs.
• Coordinate Pairs from a Cartesian Product– Every combination of one element from the first
set with one element from the second set.
AxB
Sets
• Cartesian Product
}5,1{
},,{
}3,2,1{
C
cbaB
A
AB
)},3(),,3(),,3(),,2(),,2(
),,2(),,1(),,1(),,1{(
cbacb
acbaBA
)}5,(),1,(
),5,(),1,(),5,(),1,{(
cc
bbaa
AC
)}3,(),2,(),1,(),3,(
),2,(),1,(),3,(),2,(),1,{(
cccb
bbaaa
CB
)}3,5(),2,5(
),1,5(),3,1(),2,1(),1,1{(