Download presentation
Presentation is loading. Please wait.
Published byRoss Elliott Modified over 8 years ago
1
Sets, Permutations, and Combinations
2
Lecture 4-1: Sets Sets: Powerful tool in computer science to solve real world problems. A set is a collection of elements or objects, and an element is a member of a set. Traditionally, sets are described by capital letters, and elements by lower case letters. –The symbol means “belongs to”. a A means that element a belongs to set A. –b A implies that b is not an element of A. –Braces {} are used to indicate a set. Example –A = {2, 4, 6, 8, 10} 3 A and 2 A
3
Set theory Ordering –not imposed on the set elements Unique elements –listing elements twice or more is redundant. Two sets are equal if and only if they contain the same elements. –Hence, A == B means ( x)[(x A x B) Λ (x B x A)] Finite and infinite set: described by number of elements in a set –A = {1, 2, 3, 4, …, 100} //finite set; –B={all positive integers} //infinite set
4
Infinite Sets Members of infinite sets cannot be listed, but a pattern for listing elements could be indicated. – e.g. S = {x x is a positive even integer} Can use predicate notation to represent sets –e. g. S = {x P(x)} means ( x)[(x S P(x)) Λ (P(x) x S)] –Hence, every element of S has the property P and everything that has a property P is an element of S.
5
Set Theory Examples Describe each of the following sets by listing the elements: –{x | x is a month with exactly thirty days} {April, June, September, November} –{x | x is an integer and 4 < x < 9} {5, 6, 7, 8} What is the predicate for each of the following sets? –{1, 4, 9, 16} {x | x is one of the first four perfect squares} –{2, 3, 5, 7, 11, 13, 17, ….} {x | x is a prime number}
6
Set Theory Basics Set of sets –Set elements can be a set –e.g. S = {{Andre, Kyle, Jack}, {Amy, Betty}}; A={{1,3,5,…},{2,4,…}} A set with no member –null or empty set (represented by or {}) –Note that is different from { }. The latter is a set with 1 element, which is the empty set. Some notations used for convenience of defining sets –N = set of all nonnegative integers (note that 0 N) –Z = set of all integers –Q = set of all rational numbers –R = set of all real numbers –C = set of all complex numbers
7
Open and closed interval Open interval –e.g.{x R | -2 < x < 3} –Denotes the set containing all real numbers between - 2 and 3. This is an open interval, meaning that the endpoints -2 and 3 are not included. Closed interval – e.g. {x R | -2 x 3} –Similar set but on a closed interval It includes all the numbers in the open interval described above, plus the endpoints.
8
Subsets For sets S and M, M is a subset of S if, and only if, every element in M is also an element of S. –Symbolically: M S ( x), if x M, then x S. Subset Example Question –Is S a subset of itself?, i.e. S S ? If M S and M S, then there is at least one element of S that is not an element of M, then M is a proper subset of S. –Symbolically, denoted by M S
9
Subset Example Say S is the set of all people, M is the set of all male humans, and C is the set of all computer science students. Subsets –M and C are both subsets of S, because all elements of M and C are also elements of S. –M is not a subset of C since there are elements of M that are not in C (specifically, all males who are not studying computer science).
10
Supersets A superset is the opposite of subset. If M is a subset of S, then S is a superset of M. –Symbolically, denoted S M. Likewise, if M is a proper subset of S, then S is a proper superset of M. –Symbolically, denoted S M.
11
Cardinality Cardinality of a set is simply the number of elements within the set. The cardinality of S is denoted by |S|. If M is a subset of S, then M S |M| |S| If S is a superset of M, then S M |M| |S|
12
Exercise A = {x | x N and x 5} {5, 6, 7, 8, 9, …… } B = {10, 12, 16, 20} C = {x | ( y)(y N and x = 2y)} {0, 2, 4, 6, 8, 10, …….} What statements are true? B C B A A C26 C {11, 12, 13} A {11, 12, 13} C {12} B{12} B {x | x N and x < 20} B 5 A { } B A
13
More Exercise For the following sets, prove A B. –A = { x | x R such that x 2 – 4x + 3 = 0} A = {1, 3} –B = { x | x N and 1 x 4} B = {1, 2, 3, 4} –All elements of A exist in B, hence A B (incomplete proof).
14
Power Set Set of sets From every set, many subsets can be generated. A set whose elements are all such subsets is called the power set. For a set S, (S) is termed as the power set. For a set S = {1, 2, 3} ; (S) = { ,{1}, {2}, {3}, {1,2}, {1,3}, {2,3}, {1,2,3}} For a set with n elements, the power set has 2 n elements.
15
Operations on Sets The union of set A and B, denoted by A B is the set that contains all elements in either set A or set B, i.e. A B = {x | x A or x B}. The intersection of set A and B, denoted by A B contain all elements that are common to both sets i.e. A B = {x | x A and x B} If A = { 1,3,5,7,9} and B = {3,7,9,10,15} ; A B = {1, 3, 5, 7, 9, 10, 15} and A B = {3, 7, 9}.
16
More Set Operations The complement of set A, denoted as ~A or A, is the set of all elements that are not in A. A = {x | x S and x A } The difference of A-B is the set of elements in A that are not in B. This is also known as the complement of B relative to A. A - B = {x | x A and x B } Note A – B = A B B – A
17
Disjoint Sets Given set A and set B, if A B = , then A and B are disjoint sets. In other words, there are no elements in A that are also in B.
18
Class Exercise Let A = {1, 2, 3, 5, 10} B = {2, 4, 7, 8, 9} C = {5, 8, 10} be subsets of S = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}. Find A B A – C B (A C) A B C (A B) C
19
Cartesian Product The cartesian product (cross product) of A and B denoted symbolically by A B is defined by A B = {(x,y) | x A and y B } –i.e. the set of all combinations of ordered pairs produced from the elements of both sets. –|AxB| = |A| x |B| Example, A = {a, b, c} and B = {1, 2, 3}, A B = {(a, 1), (a, 2), (a, 3), (b, 1), (b, 2), (b, 3), (c, 1), (c, 2), (c, 3)} Is A B = B A? –Cross-product of a set with itself is represented as A A or A 2
20
Cartesian Product Illustration 123 a(a, 1)(a, 2)(a, 3) b(b, 1)(b, 2)(b, 3) c(c, 1)(c, 2)(c, 3)
21
Cartesian Product Example Application –Relational database –Can extend to A1 x A2 x … x An Example –Students S = {Jean, Jack, John} –Courses C = {130, 140} S x C = ? –Let R = {0, 1} with 0 represents not registered and 1 represents registered. S x C x R = ?
22
Basic Set Identities Given sets A, B, and C, and a universal set S and a null/empty set , the following properties hold: –Commutative property (cp) A B = B A A B = B A –Associative property (ap) A (B C) = (A B) C A (B C) = (A B) C –Distributive properties (dp) A (B C) = (A B) (A C) A (B C) = (A B) (A C) –Identity properties(ip) A = A = A S A = A S = A –Complement properties (comp) A A = S A A =
23
More Set Identities Double Complement Law (A) = A Idempotent Laws A A = A A A = A Absorption properties A (A B) = A A (A B) = A Alternate Set Difference Representation A - B = A B Inclusion in Union A A B B A B Inclusion in Intersection A B A A B B Transitive Property of Subsets
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.