Download presentation
1
CPCS 222 Discrete Structures I
King ABDUL AZIZ University Faculty Of Computing and Information Technology CPCS 222 Discrete Structures I Set Theory Dr. Eng. Farag Elnagahy Office Phone: 67967
2
Set Theory 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.
3
Set Theory For example, all the students who are currently enrolled in your school make up a set. Likewise, all the students currently taking a course in discrete mathematics at any school make up a set. In addition, those students enrolled in your school who are taking a course in discrete mathematics form a set, that can be obtained by taking the elements common to the first two collections.
4
Set Theory The language of sets is a means to study
such collections in an organized fashion. A set is an unordered collection of objects. The objects in a set are called the elements, or members, of the set. A set is said to contain its elements.
5
Some Important Sets The set of natural numbers N = {0, 1, 2, 3, . . .}
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,…} The set of reals R = {–3/2,0,e,π2,5,…} These sets, each denoted using a boldface letter, play an important role in discrete mathematics
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 xA; if not: xA. Say: “x is a member of A” or “x is in A”. Note : Lowercase letters are used for elements, capitals for sets.
7
There are several ways to describe a set
one way is to 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. For example, the notation {dog, cat, horse} represents the set with the three elements dog, cat,and horse.
8
There are several ways to describe a set
A = {dog, cat, horse} dog A rat A Order of elements is meaningless A = {cat, dog, horse} It does not matter how often the same element is listed. A = {cat, horse, dog, dog}
9
There are several ways to describe a set
Although sets are usually used to group together elements with common properties, there is nothing that prevents a set from having seemingly unrelated elements. For instance, {a, 2, Ahmed, Car} is the set containing the four elements a, 2, Ahmed, and Car.
10
There are several ways 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. For example: The set of positive integers less than 100 can be denoted by {1, 2, 3, , 99}.
11
There are several ways 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. For example, the set O of all odd positive integers less than 10 can be written as: O = {x | x is an odd positive integer less than 10} or, specifying the universe as the set of positive integers, as O = {x ∈ Z+ | x is odd and x < 10}.
12
There are several ways to describe a set
We often use this type of notation to describe sets when it is impossible to list all the elements of the set. For instance, the set Q+ of all positive rational numbers can be written as Q+ = {x ∈ R | x = p/q, for some positive integers p and q.}
13
The Empty Set (Null Set)
We use Æ to denote the empty set, i.e. the set with no elements. For example, the set of all positive integers that are greater than their squares is the null set. For any element x, we have that x Ï Æ. Examples: Æ { } {Æ} {{ }} {Æ, {Æ}}
14
The singleton set A set with one element is called a singleton set.
A common error is to confuse the empty set Æ with the set {Æ}, which is a singleton set. The single element of the set {Æ} is the empty set itself! A useful analogy for remembering this difference is to think of folders in a computer file system. empty folder empty set Æ folder with exactly one folder inside {Æ}
15
Computer Science Note that the concept of a datatype, or type, in computer science is built upon the concept of a set. In particular, a datatype or type is the name of a set, together with a set of operations that can be performed on objects from that set. For 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.
16
Set Equality Two sets are equal if and only if they have the same elements. That is, if A and B are sets, then A and B are equal if and only if ∀x(x ∈ A ↔ x ∈ B). We write A = B if A and B are equal sets. A = {9, 2, 7, -3}, B = {7, 9, -3, 2} : A = B A = {dog, cat, horse}, B = {cat, horse, elephant, dog} : A B A = {dog, cat, horse}, B = {cat, horse, dog, dog} : A = B
17
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. (Note that the universal set varies depending on which objects are of interest.) 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.
18
Venn diagrams a Venn diagram that represents V, the set of vowels in the English alphabet. U o u e i a V V = {a, e, i, o, u}
19
Subsets 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.
20
Subsets A ⊆ B “ A is a subset of the set B”. U B A
Venn Diagram Showing that A Is a Subset of B.
21
Subsets A ⊆ B “ A is a subset of the set B”. Examples:
A = {3, 9}, B = {5, 9, 1, 3} A B ? true A = {3, 3, 3, 9}, B = {5, 9, 1, 3} A B ? true A = {1, 2, 3}, B = {2, 3, 4} A B ? false
22
Subsets A ⊆ B “ A is a subset of the set B”. Examples:
A = {3, 9}, B = {5, 9, 1, 3} A B ? true A = {3, 3, 3, 9}, B = {5, 9, 1, 3} A B ? true A = {1, 2, 3}, B = {2, 3, 4} A B ? false
23
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|.
24
finite set A set is said to be infinite if it is not finite.
The set of positive integers is infinite.
25
The Power 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).
26
The Power Set What is the power set of the set {0, 1, 2}?
{1, 2}, {0, 1, 2}}. Note that the empty set and the set itself are members of this set of subsets.
27
The Power Set What is the power set of the empty set?
If a set has n elements, then its power set has 2n elements.
28
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.
29
Cartesian Products We say that two ordered n-tuples are equal if and only if each corresponding pair of their elements is equal. In other words, (a1, a2, , an) = (b1, b2, , bn) if and only if ai = bi , for i = 1, 2, , n. In particular, 2-tuples are called ordered pairs. The ordered pairs (a, b) and (c, d) are equal if and only if a = c and b = d. Note that (a, b) and (b, a) are not equal unless a = b.
30
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. Hence, A × B = {(a, b) | a ∈ A ∧ b ∈ B}.
31
Cartesian Products Let A represent the set of all students at a university, and let B represent the set of all courses offered at the university. What is the Cartesian product A × B? The Cartesian product A × B consists of all the ordered pairs of the form(a, b), where a is a student at the university and b is a course offered at the university. The set A × B can be used to represent all possible enrollments of students in courses at the university.
32
Cartesian Products What is the Cartesian product of
A = {1, 2} and B = {a, b, c}? A × B = {(1, a), (1, b), (1, c), (2, a), (2, b), (2, c)}. What is the Cartesian product of B = {a, b, c}? And A = {1, 2} B × A = {(a, 1), (a, 2), (b, 1), (b, 2), (c, 1), (c, 2)}. A × B B × A
33
Cartesian Products The Cartesian products A × B and B × A are not equal, unless A = ∅ or B = ∅ (so that A × B = ∅) or A = B
34
Cartesian Products The Cartesian product of
the sets A1, A2, , An, denoted by A1 × A2 ×・ ・ ・× An, is the set of ordered n-tuples (a1, a2, . . , an), where ai belongs to Ai for i = 1, 2, , n. In other words, A1 × A2 ×・ ・ ・× An = {(a1, a2, , an) | ai ∈ Ai for i = 1, 2, , n}.
35
Cartesian Products What is the Cartesian product A × B × C, where A = {0, 1}, B = {1, 2}, and C = {0, 1, 2}? The Cartesian product A × B × C consists of all ordered triples (a, b, c), where a ∈ A, b ∈ B, and c ∈ C. Hence, A × B × C = {(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)}.
36
Exercises PP. 9-10 1 a,c 2 a,c 3-5 7-12 14 17-24 26-32
37
Set Operations Two sets can be combined in many different ways.
For example, starting with the set of mathematics majors at your school and the set of computer science majors at your school, we can form the set of students who are mathematics majors or computer science majors, the set of students who are joint majors in mathematics and computer science, the set of all students not majoring in mathematics, and so on.
38
Set Operations (union)
Let A and B be sets. The union of the sets A and B, denoted by A ∪ B, is the set that contains those elements that are either in A or in B, or in both. An element x belongs to the union of the sets A and B if and only if x belongs to A or x belongs to B. This tells us that A ∪ B = {x | x ∈ A ∨ x ∈ B}
39
Set Operations (union)
The Venn diagram shown represents the union of two sets A and B. The area that represents A ∪ B is the shaded area within either the circle representing A or the circle representing B. U B A
40
Set Operations (union)
The union of the sets A={1, 3, 5} and B={1, 2, 3} A ∪ B = {1, 3, 5} ∪ {1, 2, 3} ={1, 2, 3, 5}
41
Set Operations (intersection)
Let A and B be sets. The intersection of the sets A and B, denoted by A ∩ B, is the set containing those elements in both A and B. An element x belongs to the intersection of the sets A and B if and only if x belongs to A and x belongs to B. This tells us that A ∩ B = {x | x ∈ A ∧ x ∈ B}
42
Set Operations (intersection)
The Venn diagram shown represents the intersection of two sets A and B. The area that represents A ∩ B is the shaded area within either the circle representing A or the circle representing B. U B A
43
Set Operations (intersection)
The intersection of the sets A={1, 3, 5} and B={1, 2, 3} is the set {1, 3} A ∩ B ={1, 3, 5} ∩ {1, 2, 3} ={1, 3}.
44
Set Operations (intersection)
Two sets are called disjoint if their intersection is the empty set. Let A = {1, 3, 5, 7, 9} and B = {2, 4, 6, 8, 10}. Because A ∩ B = ∅, A and B are disjoint.
45
Set Operations (cardinality of a union of two finite sets)
to find the cardinality of a union of two finite sets A and B. counts each element that is in A but not in B or in B but not in A exactly once, and each element that is in both A and B exactly twice. Thus, if the number of elements that are in both A and B is subtracted from |A| + |B|, elements in A ∩ B will be counted only once. Hence, |A ∪ B| = |A| + |B| − |A ∩ B|.
46
Set Operations (difference )
Let A and B be sets. The difference of A and B, denoted by A − B, is the set containing those elements that are in A but not in B. The difference of A and B is also called the complement of B with respect to A. An element x belongs to the difference of A and B if and only if x ∈ A and x B. This tells us that A − B = {x | x ∈ A ∧ x B}
47
Set Operations (difference )
The Venn diagram shown represents the difference of the sets A and B. The shaded area inside the circle that represents A and outside the circle that represents B is the area that represents A − B. U A B
48
Set Operations (difference )
The difference of A={1, 3, 5} and B={1, 2, 3} is the set {5} A - B= {1, 3, 5} − {1, 2, 3} = {5} B - A= {1, 2, 3} - {1, 3, 5} ={2}.
49
Set Operations (complement )
Once the universal set U has been specified, the complement of a set can be defined. Let U be the universal set. The complement of the set A, denoted by Ā , is the complement of A with respect to U. In other words, the complement of the set A is U − A. An element belongs to Ā if and only if x A. This tells us that Ā = {x | x A}
50
Set Operations (complement )
The Venn diagram shown represents the complement of the sets A. the shaded area outside the circle representing A is the area representing Ā . U A
51
Set Operations (complement )
Let A = {a, e, i, o, u} (where the universal set is the set of letters of the English alphabet). Then Ā = {b, c, d, f, g, h, j, k, l, m, n, p, q, r, s, t, v,w, x, y, z} Let A be the set of positive integers greater than 10 (with universal set the set of all positive integers). Then Ā = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
52
Set Identities Identity laws A ∪ ∅ = A A ∩ U = A Domination laws
A ∪ U = U A ∩ ∅ = ∅ Idempotent laws (unchanged) A ∪ A = A A ∩ A = A
53
Set Identities Complementation law (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 ∪ C) = (A ∩ B) ∪ (A ∩ C) A ∪ (B ∩ C) = (A ∪ B) ∩ (A ∪ C)
54
Set Identities De Morgan’s laws A ∪ B = A ∩ B A ∩ B = A ∪ B
Absorption laws A ∪ (A ∩ B) = A A ∩ (A ∪ B) = A Complement laws A ∪ Ā = U A ∩ Ā = ∅
55
Set Identities prove that A ∩ B = A ∪ B First method
if A and B are sets, then A and B are equal if and only if ∀x(x ∈ A ↔ x ∈ B). We write A = B if A and B are equal sets. Fist step Second step Suppose Suppose x ∈ A ∩ B x ∈ A ∪ B (x ∈ A ∧ x ∈ B ) x ∈ A ∨ x ∈ B x A ∨ x B (x ∈ A) ∨ (x ∈ B) x ∈ A ∨ x ∈ B (x ∈ A ∧ x ∈ B ) x ∈ A ∪ B (x ∈ A ∩ B ) A ∩ B ⊆ A ∪ B x ∈ A ∩ B A ∪ B ⊆ A ∩ B
56
Set Identities prove that A ∩ B = A ∪ B
Second method (Using builder notation) A ∩ B = { x | x A ∩ B } = { x | (x ∈ A ∩ B) } = { x | (x ∈ A ∧ x ∈ B) } = { x | (x ∈ A) ∨ (x ∈ B) } = { x | x A ∨ x B } = { x | x ∈ A ∨ x ∈ B } = { x | x ∈ (A ∪ B) } = A ∪ B
57
Set Identities prove that A ∩ B = A ∪ B
Third method (Using membership table) A B A∩B /A∩B A∪B 1
58
Set Identities prove that A ∪ (B ∩ C) = (C ∪ B) ∩ A
A ∪ (B ∩ C) = A ∩ (B ∩ C) = A ∩ ( B ∪ C ) = ( B ∪ C ) ∩ A = ( C ∪ B ) ∩ A
59
Generalized Unions and Intersections
A ∪ B ∪ C The set contains those elements that are in at least one of the sets A, B, and C. A U B U C is shaded
60
Generalized Unions and Intersections
A ∩ B ∩ C The set contains those elements that are in all of A, B, and C. A ∩ B ∩ C is shaded
61
Generalized Unions and Intersections
Example Let A = {0, 2, 4, 6, 8}, B = {0, 1, 2, 3, 4}, and C = {0, 3, 6, 9}. What are A∪B∪C and A∩B∩C ? The set A∪B∪C contains those elements in at least one of A, B, and C. Hence, A∪B∪C = {0, 1, 2, 3, 4, 6, 8, 9}. The set A∩B∩C contains those elements in all three of A, B, and C. Thus, A∩B∩C = {0}.
62
Generalized Unions and Intersections
The union of a collection of sets is the set that contains those elements that are members of at least one set in the collection. We use the notation to denote the union of the sets A1, A2, , An. The intersection of a collection of sets is the set that contains those elements that are members of all the sets in the collection. to denote the intersection of the sets A1, A2, …, An.
63
Generalized Unions and Intersections
Example
64
Generalized Unions and Intersections
We can extend the notation we have introduce for unions and intersections to other families of sets. In particular, we can use the notation to denote the union of the sets A1, A2, , An, … Similarly, the intersection of these sets can be denoted by to denote the intersection of the sets A1, A2,.. , An, …
65
Generalized Unions and Intersections
Example Suppose that Ai = {1, 2, 3, , i } for i = 1, 2, 3, ... Then,
66
Computer Representation of Sets
There are various ways to represent sets using a computer. One method is to store the elements of the set in an unordered fashion. However, if this is done, the operations of computing the union, intersection, or difference of two sets would be time-consuming, because each of these operations would require a large amount of searching for elements. We will present a method for storing elements using an arbitrary ordering of the elements of the universal set. This method of representing sets makes computing combinations of sets easy.
67
Computer Representation of Sets
Assume that the universal set U is finite (and of reasonable size so that the number of elements of U is not larger than the memory size of the computer being used). First, specify an arbitrary ordering of the elements of U, for instance a1, a2, , an. Represent a subset A of U with the bit string of length n, where the ith bit in this string is 1 if ai belongs to A and is 0 if ai does not belong to A. The following example illustrates this technique.
68
Computer Representation of Sets
Example Let U = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, and the ordering of elements of U has the elements in increasing order; that is, ai = i . What bit strings represent the subset of all odd integers in U, the subset of all even integers in U, and the subset of integers not exceeding 5 in U? The set of all odd integers in U is {1, 3, 5, 7, 9}, The bit string is The set of all even integers in U is {2, 4, 6, 8, 10} The bit string is The set of integers not exceeding 5 in U is {1, 2, 3, 4, 5}, The bit string is
69
Computer Representation of Sets
Example (complement ) the bit string for the set {1, 3, 5, 7, 9} (with universal set {1, 2, 3, 4,5, 6, 7, 8, 9, 10}) Is What is the bit string for the complement of this set? The bit string for the complement of this set is obtained by replacing 0s with 1s and vice versa. This yields the string , which corresponds to the set {2, 4, 6, 8, 10}.
70
Computer Representation of Sets
Example (union and intersection ) The bit strings for the sets {1, 2, 3, 4, 5} is {1, 3, 5, 7, 9} is , Use bit strings to find the union and intersection of these sets. The bit string for the union of these sets is ∨ = which corresponds to the set {1, 2, 3, 4, 5, 7, 9}. The bit string for the intersection of these sets is ∧ = which corresponds to the set {1, 3, 5}.
71
Exercises PP. 119-121 2 4, 6, 8, 12, 14, 16(a, e), 18(a,c), 22, 24
26(a,c), 28(a,b), 50(a,c), 51, 52
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.