Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS100: Discrete structures

Similar presentations


Presentation on theme: "CS100: Discrete structures"— Presentation transcript:

1 CS100: Discrete structures
Computer Science Department Lecture 1: Set and Sets Operations

2 Lecture Contents 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. Sets Operations. Exercises. 12-Nov-18 Computer Science Department

3 Sets and sets operations
12-Nov-18 Computer Science Department

4 Sets 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. The objects in a set are called the elements or members of the set 12-Nov-18 Computer Science Department

5 Some Important Sets: The set of natural numbers: 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),…} 12-Nov-18 Computer Science Department

6 Notation used to describe membership in sets
a set A is a collection of elements. If x is an element of A, we write xA; If not: xA. xA 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 12-Nov-18 Computer Science Department

7 Notation used to describe membership in sets
The sets {1,3,5} and {3,5,1} are equal , because they have the same elements. Is {1,3,3,3,5,5,5,5} = {1,3,5} ?! Yes , because they have the same elements. 12-Nov-18 Computer Science Department

8 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} The set O of odd positive integers less than 10 can be expressed by O={1,3,5,7,9} 12-Nov-18 Computer Science Department

9 How to describe a set? 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 100 can be denoted by A={1, 2, 3, , 99} 12-Nov-18 Computer Science Department

10 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}.  12-Nov-18 Computer Science Department

11 Sets: 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. 12-Nov-18 Computer Science Department

12 Sets: 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 {0, 1} together with operators on one or more elements of this set, such as AND, OR, and NOT. 12-Nov-18 Computer Science Department

13 Venn 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. 12-Nov-18 Computer Science Department

14 Venn diagrams: Example:
A Venn diagram that represents V = {a, e, i, o, u} the set of vowels in the English alphabet 12-Nov-18 Computer Science Department

15 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. Examples: The set of all odd positive integers less than 10 is subset of the set of all positive integers . The set of rational numbers is subset of the set of real numbers . 12-Nov-18 Computer Science Department

16 x ((x  A)  (x  B))  x ((x  B)  (x  A))
Subsets: 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)) 12-Nov-18 Computer Science Department

17 Subsets: Quick 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}? Yes! No! Yes! Yes! 12-Nov-18 Computer Science Department

18 Subsets: Quiz Time: Is {x}  {x,{x}}? Is {x}  {x,{x}}? Is {x}  {x}?
Yes! Yes! Yes! No! 12-Nov-18 Computer Science Department

19 Finite and Infinite Sets:
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 12-Nov-18 Computer Science Department

20 Cardinality: Find S = {1,2,3}, S = {3,3,3,3,3}, S = ,
|S| is infinite 12-Nov-18 Computer Science Department

21 Sets: 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. 12-Nov-18 Computer Science Department

22 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. 12-Nov-18 Computer Science Department

23 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 elements The null set and the set itself 12-Nov-18 Computer Science Department

24 P(S) = {, {}, {{}}, {,{}}}.
The Power Set: Quick 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) = {, {}, {{}}, {,{}}}. 12-Nov-18 Computer Science Department

25 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. 12-Nov-18 Computer Science Department

26 Cartesian Products: 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}. A1×A2×…×An={(a1, a2,…, an) | aiAi for i=1,2,…,n}. A×B not equal to B×A Example : A={1,2} , B={3,4} A×B={(1,3),(1,4),(2,3),(2,4)} B×A={(3,1),(3,2),(4,1),(4,2)} 12-Nov-18 Computer Science Department

27 Cartesian Products: Example: What is the Cartesian product A × B × C, where A = {0, 1}, B = {1, 2}, and C = {0, 1, 2}? 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)} 12-Nov-18 Computer Science Department

28 Sets and sets operations
12-Nov-18 Computer Science Department

29 UNION: A  B = { x : x  A v x  B} The union of two sets A and B is:
If A = {1, 2, 3}, and B = {2, 4}, then A  B = {1,2,3,4} A B 12-Nov-18 Computer Science Department

30 Intersection: A  B = { x : x  A  x  B}
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 A  B = {Lucy} A B 12-Nov-18 Computer Science Department

31 Intersection: If A = {x : x is a US president}, and
B = {x : x is deceased}, then A  B = {x : x is a deceased US president} A B 12-Nov-18 Computer Science Department

32 Sets whose intersection
Disjoint: 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} = Sets whose intersection is empty are called disjoint sets A B 12-Nov-18 Computer Science Department

33 Complement: 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 and U =  A U 12-Nov-18 Computer Science Department

34 Difference: The set difference, A - B, is:
A - B = { x : x  A  x  B } A - B = A  B A U B 12-Nov-18 Computer Science Department

35 Symmetric Difference:
The symmetric difference, A  B, is: A  B = { x : (x  A  x  B) v (x  B  x  A)} = (A - B)  (B - A) Like “exclusive or” A U B 12-Nov-18 Computer Science Department

36 Symmetric Difference:
Example: Let A = {1,2,3,4,5,6,7} B = {3,4,p,q,r,s} Then we have A  B = {1,2,3,4,5,6,7,p,q,r,s} A  B = {3,4} We get A  B = {1,2,5,6,7,p,q,r,s} 12-Nov-18 Computer Science Department

37 TABLE 1: Set Identities Name Identity Identity laws A U  = A
Domination laws A U U = U A   =  Idempotent laws A  A = A A  A = A Complementation laws (A) = A Commutative laws A  B = B  A A  B = B  A Associative laws A  (B  C) = (A  B)  C A  (B  C) = (A  B)  C Distributive laws A  (B U C) = (A  B)  (A  C) A  (B  C) = (A U B)  (A U C) De Morgan’s laws A U B = A  B A  B = A U B Absorption laws A  (A  B) = A A  (A  B) = A Complement laws A  A = U A  A =  12-Nov-18 Computer Science Department

38 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 1 12-Nov-18 Computer Science Department

39 Exercise 1: List the members of these sets:
a) {x | x is a real number such that x² = 1} {-1, 1} b) {x | x is a positive integer less than 12} {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11} c) {x | x is the square of an integer and x < 100} {0, 1, 4, 9, 16, 25, 36, 49, 64, 81} d) {x | x is an integer such that x² = 2} 12-Nov-18 Computer Science Department

40 Exercise 2: Determine whether each of these pairs of sets are equal:
Yes b) {{1}}, {1, {2}} No c) , {} 12-Nov-18 Computer Science Department

41 Exercise 3: Determine whether these statements are true or false.
b) ∅∈{0} c) {0} ⊂∅ d) ∅⊂ {0} e) {0} ∈ {0} f) {0} ⊂ {0} g) {∅}⊆{∅} False False False True False False True 12-Nov-18 Computer Science Department

42 Exercise 4: Use a Venn diagram to illustrate the relationships 𝐀⊂𝑩 𝒂𝒏𝒅 𝑩⊂𝑪 . A B C U 12-Nov-18 Computer Science Department

43 Exercise 5: What is the cardinality of each of these sets? a) {a} 1
b) {{a}} c) {∅, {∅}} 2 d) {a, {a}, {a, {a}}} 3 12-Nov-18 Computer Science Department

44 Exercise 6: Let A = {1, 2, 3, 4, 5} and B = {0, 3, 6}. Find : a) A ∪ B
{0, 1, 2, 3, 4, 5, 6} b) A ∩ B {3} c) A – B {1, 2, 4, 5} d) B – A {0, 6} 12-Nov-18 Computer Science Department

45 Exercise 7: For U = {1, 2,3, 4,5,6,7,8,9,10} let A = {1, 2,3,4,5} , B = {1,2, 4,8}, C = {1, 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 = {1,2,3,5} {1,2,3,4,5} {1, 2,3, 4, 5, 6, 7, 8} {4,8} {1,2,3,4,5,8} {} {2,4,8} {1,3,4,5,8} {3,5,8} 12-Nov-18 Computer Science Department

46 Exercise 8: Draw the VENN DIAGRAM of these sets and find (A∪B)−C and B′ A B C B 12-Nov-18 Computer Science Department

47 Exercise 9: Given the Universal set U={positive integers not larger than 12}, and the sets : A={positive integers not more than 6} B={3,4,6,7} , C={5,6,7,8,9,10} , Find : i) A U B = ii) | A−B |= iii) P(A‐B)=Power set of (A‐B)= {1,2,3,4,5,6,7} 3 {ф,{1},{2},{5},{1,2},{1,5},{2,5},{1,2,5}} 12-Nov-18 Computer Science Department

48 Refer to Chapter 2 for further reading
12-Nov-18 Computer Science Department


Download ppt "CS100: Discrete structures"

Similar presentations


Ads by Google