Power Set of a set and Relations 1
Power Set (1) Definition: The power set of a set S, denoted P(S), is the set of all subsets of S. Examples Let A={a,b,c}, P(A)={,{a},{b},{c},{a,b},{b,c},{a,c},{a,b,c}} Let A={{a,b},c}, P(A)={,{{a,b}},{c},{{a,b},c}} Note: the empty set and the set itself are always elements of the power set.
Power Set (2) The power set is a fundamental combinatorial object useful when considering all possible combinations of elements of a set Fact: Let S be a set such that S =n, then P(S) = 2 n
Proof of P(A) =2^ A Proof: ( By induction) Base case holds: A =0, then A={} and P(A)={ }. Induction Hypothesis: Assume to be true for all sets of cardinality n-1, i.e. A =n-1 implies P(A) =2^{n-1}. For A =n Let A={a_1,a_2,,a_n}. Any subset not containing a_n is a subset of B=A\{a_n}. How many subsets of A are there not containing a_n? This is nothing but the set of all subsets of B. The number is 2^{n-1} by induction hypothesis. 4
Proof of P(A) =2^ A Contd How to get a subset of A containing a_n? Take a subset S of B. Let S =S {a_n}. Now S is a subset of A containing a_n. Can any subset of A containing a_n be obtained in this way? Answer is Yes!! Let S be any subset of A containing a_n. Let S=S \{a_n}. Now S is a subset of A not containing a_n. 5
Proof of P(A) =2^ A Contd Let X_1 be the set of all subsets of A not containing a_n Let X_2 be the set of all subsets of A containg a_n. Now P(A)= X_1 X_2 and X_1 X_2 =. Also S S =S {a_n} is a bijection. This implies S = S =2^{n-1} by induction hypothesis So P(A)) = S + S = 2^{n-1} +2^{n-1}=2^{n}. 6
How to generate all subsets of a Set of n elements? 7
Computer Representation of Sets (1) There really aren t ways to represent infinite sets by a computer since a computer has a finite amount of memory If we assume that the universal set U is finite, then we can easily and effectively represent sets by bit vectors Specifically, we force an ordering on the objects, say: U={a 1, a 2,,a n } For a set A U, a bit vector can be defined as, for i=1,2,,n b i =0 if a i A b i =1 if a i A
Computer Representation of Sets (2) Examples Let U={0,1,2,3,4,5,6,7} and A={0,1,6,7} The bit vector representing A is: 1100 0011 How is the empty set represented? How is U represented? Set operations become trivial when sets are represented by bit vectors Union is obtained by making the bit-wise OR Intersection is obtained by making the bit-wise AND
BITWISE OPERATOR (IN C) Operators & Meaning of operators Bitwise AND Bitwise OR ^ Bitwise exclusive OR ~ Bitwise complement << Shift left >> Shift right
Computer Representation of Sets (3) Let U={0,1,2,3,4,5,6,7}, A={0,1,6,7}, B={0,4,5} What is the bit-vector representation of B? Compute, bit-wise, the bit-vector representation of A B Compute, bit-wise, the bit-vector representation of A B What sets do these bit vectors represent?
Computer Representation of Sets Array representations: U={1,2,.n} S can be represented by an array A such that A[i]=1 if i S else A[i]=0. Disjoint Set operations: Union, j=find(i) if I in S_j. 12
Programming Question Using bit vector, we can represent sets of cardinality equal to the size of the vector What if we want to represent an arbitrary sized set in a computer (i.e., that we do not know a priori the size of the set)? What data structure could we use? Tree representation of disjoint Set: To be discussed after Graphs are introduced.
Relations 14
Relations and Their Properties To represent relationships between elements of sets Ordered pairs: binary relations Definition 1: Let A and B be sets. A binary relation from A to B is a subset of A B. a R b: (a,b) R a is related to b by R R a b: (a,b) R Ex.1-3 Functions as relations Relations are generalization of functions
FIGURE 1 (8.1) FIGURE 1 Displaying the Ordered Pairs in the Relation R from Example 3.
Relations on a Set Definition 2: a relation on the set A is a relation from A to A. How many relations are there on a set with n elements? ( Such questions will be discussed in Counting and advanced counting)
FIGURE 2 Displaying the Ordered Pairs in the Relation R from Example 4.
Properties of Relations Definition 3: A relation R on a set A is called reflexive if (a,a) R for every element a A. a((a,a) R) Definition 4: A relation R on a set A is called symmetric if (b,a) R whenever (a,b) R, for all a,b A. A relation R on a set A such that for all a,b A, if (a,b) R and (b,a) R, then a=b is called antisymmetric. a b((a,b) R (b,a) R) a b(((a,b) R (b,a) R) (a=b)) Not opposites
Definition 5: A relation R on a set A is called transitive if whenever (a,b) R and (b,c) R, then (a,c) R, for all a,b,c A. a b c(((a,b) R (b,c) R) (a,c) R)
Combining Relations Two relations can be combined in any way two sets can be combined Definition 6: R: relation from A to B, S: relation from B to C. The composite of R and S is the relation consisting of ordered pairs (a,c), where a A, c C, and there exists an element b B such that (a,b) R and (b,c) S. (denoted by S R)
Definition 7: Let R be a relation on the set A. The powers R n, n=1,2,3,, are defined recursively by R 1 =R, and R n+1 =R n R. Theorem 1: The relation R on a set A is transitive iff R n R for n=1,2,3, Proof.
Representing Relations To represent binary relations Ordered pairs Tables Zero-one matrices Directed graphs
Representing Relations Using Matrices Suppose that R is a relation from A={a 1,a 2,,a m } to B={b 1,b 2,,b n }. R can be represented by the matrix M R =[m ij ], where m ij =1 if (a i,b j ) R, or 0 if (a i,b j ) R.
FIGURE 1 The Zero-One Matrix for a Reflexive Relation.
FIGURE 2 (8.3) FIGURE 2 The Zero-One Matrices for Symmetric and Antisymmetric Relations.
Representing Relations Using Digraphs Definition 1: A directed graph (digraph) consists of a set V of vertices (or nodes) and a set E of ordered pairs of elements of V called edges (or arcs). The vertex a is called the initial vertex of the edge (a,b), and the vertex b is called the terminal vertex of this edge.
FIGURE 3 The Directed Graph.
FIGURE 4 (8.3) FIGURE 4 The Directed Graph of the Relations R.
FIGURE 5 (8.3) FIGURE 5 The Directed Graph of the Relations R.
FIGURE 6 (8.3) FIGURE 6 The Directed Graph of the Relations R and S.
Closures of Relations Ex. Telephone line connections Let R be a relation on a set A. R may or may not have some property P. If there is a relation S with property P containing R such that S is a subset of every relation with property P containing R, then S is called the closure of R with respect to P. S: the smallest relation that contains R
Closures Reflexive closure Ex: R={(1,1),(1,2),(2,1),(3,2)} on the set A={1,2,3} The smallest relation contains R? The reflexive closure of R=R, where ={(a,a) a A} Symmetric closure The symmetric closure of R=R R -1, where R -1 ={(b,a) (a,b) R} Transitive closure
Paths in Directed Graphs Definition 1: A path from a to b in the directed graph G is a sequence of edges (x0,x1), (x1,x2),,(xn-1,xn) in G, where n is a nonnegative integer, and x0=a and xn = b. The path denoted by x0,x1,,xn-1, xn has length n. A path of length n >=1 that begins and ends at the same vertex is called a circuit or cycle. There is a path from a to b in R if there is a sequence of elements a, x1, x2,, xn-1, b with (a,x1) R, (x1,x2) R,, and (xn-1,b) R.
FIGURE 1 A Directed Graph.
Theorem 1: Let R be a relation on a set A. There is a path of length n, where n is a positive integer, from a to b iff (a,b) R n. Proof. (by mathematical induction)
Transitive Closures Definition 2: Let R be a relation on a set A. The connectivity relation R* consists of pairs (a,b) such that there is a path of length at least one from a to b in R. R*= n=1.. R n.
Theorem 2: The transitive closure of a relation R equals the connectivity relation R*. Proof. Lemma 1: Let A be a set with n elements, and R be a relation on A. If there is a path of length at least one in R from a to b, then there is such as path with length not exceeding n. When a b, if there is a path of length at least one in R from a to b, then there is such as path with length not exceeding n-1. Proof.
FIGURE 2 Producing a Path with Length Not Exceeding n.
Theorem 3: Let M R be the zero-one matrix of the relation R on a set with n elements. Then the zero-one matrix of the transitive closure R* is M R* = M R M R [2] M R [3] M R [n].
Algorithm 1: A procedure for computing the transitive closure. Procedure transitive closure (M R : zero-one n*n matrix) A:= M R B:=A for i:=2 to n begin A:=A M R B:=B A end O(n 4 ) bit operations
Warshall s Algorithm Named after Stephen Warshall in 1960 2n 3 bit operation Also called Roy-Warshall algorithm, Bernard Roy in 1959 Interior vertices W0, W1,, Wn Wk=[w ij (k) ], where w ij (k) =1 if there is a path from v i to v j such that all interior vertices of this path are in the set [v1, v2,, vk]. Wn= M R*
FIGURE 3 The Directed Graph of the Relations R.
Observation: we can compute Wk directly from Wk-1 Two cases (Fig. 4) There is a path from vi to vj with its interior vertices among the first k-1 vertices w ij (k-1) =1 There are paths from vi to vk and from vk to vj that have interior vertices only among the first k-1 vertices w ik (k-1) =1 and w kj (k-1) =1
FIGURE 4 Adding v k to the Set of Allowable Interior Vertices.
Lemma 2: Let Wk=w ij (k) be the zero-one matrix that has a 1 in its (i,j)th position iff there is a path from vi to vj with interior vertices from the set {v1, v2,, vk}. Then w ij (k) =w ij (k-1) (w ik (k-1) w kj (k-1) ), whenever I, j, and k are positive integers not exceeding n.
Algorithm 2: Warshall Algorithm Procedure Warshall(M R : n*n zero-one matrix) W:= M R for k:=1 to n begin for i:=1 to n begin for j:=1 to n wij:=wij (wik wkj) end end
Equivalence Relations Definition 1: A relation on a set A is called an equivalence relation if it is reflexive, symmetric, and transitive. Definition 2: Two elements a and b are related by an equivalence relation are called equivalent. The notation a~b: to denote that a and b are equivalent elements with respect to a particular equivalence relation
Equivalence Classes Definition 3: Let R be an equivalence relation on a set A. The set of all elements that are related to an element a of A is called the equivalence class of a. Denoted by [a] R or [a] [a] R = {s (a,s) R} If b [a] R, then b is called a representative of the equivalence class
Equivalence Classes and Partitions Theorem 1: Let R be an equivalence relation on a set A. These statements for elements a and b of A are equivalent: a R b [a]=[b] [a] [b] Proof.
Observations a A [a] R =A [a] [b]= when [a] R [b] R The equivalence classes form a partition of A A partition of a set S is a collection of disjoint nonempty subsets of S that have S as their union Ai for i I, Ai Aj= when i j i I Ai=S
FIGURE 1 A Partition of a Set.
Theorem 2: Let R be an equivalence relation on a set S. Then the equivalence classes of R form a partition of S. Conversely, given a partition {Ai i I} of the set S, there is an equivalence relation R that has the sets Ai, i I, as its equivalence classes.
Partial Orderings Definition 1: A relation R on a set S is called a partial ordering or partial order if it is reflexive, antisymmetric, and transitive. A set S together with its partial ordering R is called a partially ordered set, or poset, (S, R). Proof. Ex.1-3:,, Ex.4: older than Notation: : a b, but a b
Definition 2: The elements a and b of a poset (S, ) are called comparable if either a b or b a. If neither a b nor b a, a and b are incomparable. ( partial ) Ex. 5 When every two elements in the set are comparable, the relation is called a total ordering
Definition 3: If (S, ) is a poset and every two elements of S are comparable, S is called a totally ordered or linearly ordered set (or a chain), and is called a total order or a linear order. Ex.6: (Z, ) Ex.7: (Z+, ) Definition 4: (S, ) is a well-ordered set if it is a poset such that is a total ordering and every nonempty subset of S has a least element. Ex.8
Theorem 1: (The Principle of Well-Ordered Induction) Suppose that S is a well-ordered set. Then P(x) is true for all x S, if (inductive step): For every y S, if P(x) is true for all x S with x y, then P(y) is true. Proof.
Lexicographic Order (a 1, a 2 ) (b 1, b 2 ) (A 1, 1), (A 2, 2) Either if a 1 1 b 1 Or if a 1 =b 1 and a 2 2 b 2 n-tuples (Fig. 1)
FIGURE 1 The Ordered Pairs Less Than (3,4) in Lexicographic Order.
Hasse Diagrams Hasse Diagrams: some edges do not have to be shown Reflexive: loops can be removed Transitive: if (a,b) and (b,c), then (a,c) can be removed Remove all the arrows
FIGURE 2 Constructing the Hasse Diagram for ({1,2,3,4}, ).
FIGURE 3 (8.6) FIGURE 3 Constructing the Hasse Diagram of ({1,2,3,4,6,8,12}, ).
FIGURE 4 The Hasse Diagram of (P({a,b,c}), ).
Maximal and Minimal Elements a is maximal in the poset (S, ) if there is no b S such that a b. a is minimal in the poset (S, ) if there is no b S such that b a.
FIGURE 5 The Hasse Diagram of a Poset.
FIGURE 6 Hasse Diagrams of Four Posets. FIGURE 6 (8.6)
In a subset A of a poset (S, ), if u is an element of S such that a u for all a A, then u is an upper bound of A. In a subset A of a poset (S, ), if l is an element of S such that l a for all a A, then l is an lower bound of A.
FIGURE 7 The Hasse Diagram of a Poset.
Lattices A partially ordered set in which every pair of elements has both a least upper bound and a greatest lower bound is called a lattice
FIGURE 8 Hasse Diagrams of Three Posets. FIGURE 8 (8.6)
Topological Sorting Topological sorting: constructing a compatible total ordering from a partial ordering A total ordering is said to be compatible with the partial ordering R if a b whenever a R b. Lemma 1: Every finite nonempty poset (S, ) has at lease one minimal element.
Algorithm 1: topological sorting Procedure topological sort(s, : finite poset) k:=1 while S begin ak:=a minimal element of S S:=S-{ak} k:=k+1 end
FIGURE 9 (8.6) FIGURE 9 A Topological Sort of ({1,2,4,5,12,20}, ).
FIGURE 10 The Hasse Diagram for Seven Tasks.
FIGURE 11 A Topological Sort of the Tasks. FIGURE 11 (8.6)