CS: DISCRETE STRUCTURES Computer Science Department Lecture : Set and Sets Operations (Ch2)
Lecture Contents 2 Sets Definition. Some Important Sets. Notation used to describe membership in sets. How to describe a set? Sets. Venn diagrams. Subset. Finite and Infinite Sets. Cardinality.
Lecture Contents 3 Sets Definition. Sets. The power of a set. Cartesian Products. Sets Operations. Exercises.
4 Sets and sets operations Sets Reading: Ch:2./ Pages: -9
Sets Definition: 5 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. The objects in a set are called the elements or members of the set
Some Important Sets: 6 The set of natural numbers: N = {,, 2, 3,...} The set of integers: Z = {..., 2,,,, 2,...} The set of positive integers: Z + = {, 2, 3,...} The set of fractions: Q = {,½, ½, 5, 78/3, } Q ={p/q pє Z, qєz, and q } The set of Real: R = { 3/2,,e,π2,sqrt(5), }
Notation used to describe membership in sets 7 o a set A is a collection of elements. o If x is an element of A, we write xîa; If not: xïa. o xîa Say: x is a member of A or x is in A. o Note: Lowercase letters are used for elements, capitals for sets. o Two sets are equal if and only if they have the same elements A= B : "x( x ÎA «x ÎB) also o Two sets A and B are equal if A Í B and B Í A. o So to show equality of sets A and B, show: A Í B B Í A
Notation used to describe membership in sets 8 The sets {,3,5} and {3,5,} are equal, because they have the same elements.
How to describe a set? 9. 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} The set O of odd positive integers less than can be expressed by O={,3,5,7,9}
How to describe a set? 2. 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 A of positive integers less than can be denoted by A={, 2, 3,..., 99}
How to describe a set? 3. 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 can be written as: n O = {x x is an odd positive integer <} or, specifying the universe as the set of positive integers, as n O = {x Î Z+ x is odd and x<}.
Sets: 2 The Empty Set (Null Set) We use Æ to denote the empty set and can also be denoted { }, i.e. the set with no elements. Example: the set of all positive integers that are greater than their squares is the null set. Singleton set A set with one element is called a singleton set.
Sets: 3 Computer Science Note that the concept of a data type, or type, in computer science is built upon the concept of a set. In particular, a data type is the name of a set, together with a set of operations that can be performed on objects from that set. Example: Boolean is the name of the set {, } together with operators on one or more elements of this set, such as AND, OR, and NOT.
Venn diagrams: 4 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.
Venn diagrams: 5 Example: A Venn diagram that represents V = {a, e, i, o, u} the set of vowels in the English alphabet
Subset: 6 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. Examples: The set of all odd positive integers less than is subset of the set of all positive integers. The set of rational numbers is subset of the set of real numbers.
Subsets: 7 For every set S, Æ Í S 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))
Subsets: 8 Quick Examples: {,2,3} Í {,2,3,4,5} {,2,3} Ì {,2,3,4,5} Is Æ Í {,2,3}? Is Æ Î {,2,3}? Is Æ Í {Æ,,2,3}? Is Æ Î {Æ,,2,3}? Yes! No! Yes! Yes!
Subsets: 9 Quiz Time: Is {x} Î {x,{x}}? Is {x} Í {x,{x}}? Is {x} Í {x}? Is {x} Î {x}?
Finite and Infinite Sets: 2 Finite 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 set A set is said to be infinite if it is not finite. For example, the set of positive integers is infinite. N.B. We only count unrepeated elements
Cardinality: 2 Find S = {,2,3}, S = {3,3,3,3,3}, S = Æ, S = 3. S = S =. S = { Æ, {Æ}, {Æ,{Æ}} }, S = 3. S = {,,2,3, }, S is infinite
Sets: 22 Ways to Define Sets: Explicitly: {John, Paul, George, Ringo} Implicitly: {,2,3, }, or {2,3,5,7,,3,7, } 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.
The power of a set: 23 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 2 n elements.
The power of a set: 24 Example: What is the power set of the set {,, 2}? P({,,2}) is the set of all subsets of {,, 2} P({,,2})= {Æ, {},{},{2},{,},{,2},{,2},{,,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 elements The null set and the set itself
The Power Set: 25 Quick Quiz: Find the power set of the following: S = {a}, S = {a,b}, S = Æ, S = {Æ,{Æ}},
Cartesian Products: 26 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 (a, a2,..., a n ) is the ordered collection that has a as its first element, a 2 as its second element,..., and a n as its n th element.
Cartesian Products: 27 Let 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 aîa and bîb. A B = {(a, b) a Î A Ù b Î B}. A A 2 A n= {(a, a 2,, a n ) a i ÎA i for i=,2,,n}. A B not equal to B A Example : A={,2}, B={3,4} A B={(,3),(,4),(2,3),(2,4)} B A={(3,),(3,2),(4,),(4,2)}
Cartesian Products: 28 Example: What is the Cartesian product A B C, where A = {, }, B = {, 2}, and C = {,, 2}? AxBxC = {(,,), (,,), (,,2), (,2,), (,2,), (,2,2), (,,), (,,), (,,2), (,2,), (,2,), (,2,2)}
29 Sets and sets operations Sets Operations Reading: Ch:2.2/ Pages: 2-3
UNION: 3 The union of two sets A and B is: A È B = { x : x Î A v x Î B} If A = {, 2, 3}, and B = {2, 4}, then A È B = {,2,3,4} B A
Intersection: 3 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}, then B A Ç B = {Lucy} A
Intersection: 32 If A = {x : x is a US president}, and B = {x : x is deceased}, then A Ç B = {x : x is a deceased US president} B A
Disjoint: 33 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} = B A Sets whose intersection is empty are called disjoint sets
Complement: 34 The complement of a set A is: A" = A = { x : x Ï A} If A = {x : x is bored}, then A" = {x : x is not bored} = Æ A Í B = B Í A U A Æ = U and U = Æ
Difference: 35 The set difference, A - B, is: U B A A - B = { x : x Î A Ù x Ï B } A - B = A Ç B"
Symmetric Difference: 36 The symmetric difference, A Å B, is: A Å B = { x : (x Î A Ù x Ï B) v (x Î B Ù x Ï A)} = (A - B) È (B - A) U B A Like exclusive or
Symmetric Difference: 37 Example: Let A = {,2,3,4,5,6,7} B = {3,4,p,q,r,s} Then we have A È B = {,2,3,4,5,6,7,p,q,r,s} A Ç B = {3,4} We get A Å B = {,2,5,6,7,p,q,r,s}
38 TABLE : Set Identities Identity A U Æ = A A Ç U = A A U U = U A Ç Æ = Æ A È A = A A Ç A = A (A) = A A È B = B È A A Ç B = B Ç A A È (B È C) = (A È B) È C A Ç (B Ç C) = (A Ç B) Ç C A Ç (B U C) = (A Ç B) È (A Ç C) A È (B Ç C) = (A U B) Ç (A U C) A U B = A Ç B A Ç B = A U B A È (A Ç B) = A A Ç (A È B) = A A È A = U A Ç A = Æ Name Identity laws Domination laws Idempotent laws Complementation laws Commutative laws Associative laws Distributive laws De Morgan s laws Absorption laws Complement laws
39 Let s proof one of the Identities Using a Membership Table A Ç (B È C) = (A Ç B) È (A Ç C) TABLE 2: A Membership Table for the Distributive Property (A Ç B) È (A Ç C) A Ç C A Ç B A Ç (B È C) B È C C B A
Exercise : 4 List the members of these sets: a) {x x is a real number such that x² = } b) {x x is a positive integer less than 2} c) {x x is the square of an integer and x < } d) {x x is an integer such that x² = 2}
Exercise 2: 4 Determine whether each of these pairs of sets are equal: a) {4, 3, 3, 7, 4, 7, 7, 3}, {4, 3, 7} b) {{}}, {, {2}} c) Æ, {Æ}
Exercise 3: 42 Determine whether these statements are true or false. a) b) {} c) {} d) {} e) {} {} f) {} {} g) { } { }
Exercise 4: 43 Use a Venn diagram to illustrate the relationships A B and B C.
Exercise 5: 44 What is the cardinality of each of these sets? a) {a} b) {{a}} c) {, { }} d) {a, {a}, {a, {a}}}
Exercise 6: 45 Let A = {, 2, 3, 4, 5} and B = {, 3, 6}. Find : a) A B b) A B c) A B d) B A
Exercise 7: 46 For U = {, 2,3, 4,5,6,7,8,9,} let A = {, 2,3,4,5}, B = {,2, 4,8}, C = {, 2,3,5,7}, and D = {2, 4,6,8}. Determine each of the following: a) (A B) C = b) A (B C)= c) C D = d) (A B) C = e) A (B C)= f) (B C) D = g) B (C D)= h) (A B) (C D)= i) A B =
Exercise 8: 47 Draw the VENN DIAGRAM of these sets and find (A B) C and Bʹ
Exercise 9: 48 Given the Universal set U={positive integers not larger than 2}, and the sets : A={positive integers not more than 6} B={3,4,6,7}, C={5,6,7,8,9,}, Find : i) A U B = ii) A B = iii) P(A-B)=Power set of (A-B)=