Quick viewing(Text Mode)

Power Set of a Set and Relations

Power of a set and Relations

1 (1)

: The power set of a set , denoted P(S), is the set of all 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  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 of elements of a set • Fact: Let S be a set such that |S|=n, then |P(S)| = 2n Proof of |P(A)|=2^|A|

• Proof: ( By induction) – case holds: |A|=0, then A={} and P(A)={}. – Induction Hypothesis: Assume to be true for all sets of 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 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 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 . – 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 U is finite, then we can easily and effectively represent sets by bit vectors • Specifically, we force an ordering on the objects, say:

U={a1, a2,…,an} • For a set AU, a bit vector can be defined as, for i=1,2,…,n

– bi=0 if ai  A

– bi=1 if ai  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 – is obtained by making the bit-wise OR – Intersection is obtained by making the bit-wise AND

BITWISE OPERATOR (IN C)

Operators of operators

& Bitwise AND | Bitwise OR ^ Bitwise exclusive OR ~ Bitwise << 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? • 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 from A to B is a subset of AB. – a R b: (a,b)R • a is related to b by R – a R 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 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 Rn, n=1,2,3,…, are defined recursively by R1=R, and Rn+1=Rn ○R.

1: The relation R on a set A is transitive iff Rn 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={a1,a2,…,am} to B={b1,b2,…,bn}. R can be represented by the matrix MR=[mij], where mij=1 if (ai,bj)R, or 0 if (ai,bj)R.

FIGURE 1 The Zero-One Matrix for a . FIGURE 2 (8.3)

FIGURE 2 The Zero-One Matrices for Symmetric and Antisymmetric Relations. Representing Relations Using Digraphs

• Definition 1: A (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 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 of R with respect to P. – S: the smallest relation that contains R Closures

– 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} •

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 , 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)Rn. – Proof. (by )

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. n – R*=n=1..R .

• 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 MR 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 [2] [3] [n] MR*= MR  MR  MR …  MR .

• Algorithm 1: A procedure for computing the transitive closure.

– Procedure transitive closure (MR : zero-one n*n matrix) A:= MR B:=A for i:=2 to n begin A:=A ๏ MR B:=B  A end – O(n4) bit operations Warshall’s Algorithm

• Named after Stephen Warshall in 1960 – 2n3 bit operation – Also called Roy-Warshall algorithm, Bernard Roy in 1959 • vertices • W0, W1, …, Wn (k) (k) – Wk=[wij ], where wij =1 if there is a path from vi to vj such that all interior vertices of this path are in the set [v1, v2, …, vk].

– Wn= MR*

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 (k-1) – wij =1 • There are paths from vi to vk and from vk to vj that have interior vertices only among the first k-1 vertices (k-1) (k-1) – wik =1 and wkj =1

FIGURE 4

Adding vk to the Set of Allowable Interior Vertices. (k) • Lemma 2: Let Wk=wij 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 (k) (k-1) (k-1) (k-1) wij =wij  (wik  wkj ), whenever I, j, and k are positive not exceeding n. • Algorithm 2: Warshall Algorithm

– Procedure Warshall(MR: n*n zero-one matrix) W:= MR 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 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 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 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 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IAi=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 if it is reflexive, antisymmetric, and transitive. – A set S together with its partial ordering R is called a , 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 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. 

• (A1, 1), (A2, 2)

– (a1, a2) (b1, b2) • Either if a1 1 b1

• Or if a1=b1 and a2 2 b2

– n- (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 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 (8.6)

FIGURE 6 Hasse Diagrams of Four Posets. • 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

FIGURE 8 (8.6)

FIGURE 8 Hasse Diagrams of Three Posets. Topological Sorting

• A total ordering  is said to be compatible with the partial ordering R if a b whenever a R b. – Topological sorting: constructing a compatible total ordering from a partial ordering • 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 (8.6)

FIGURE 11 A Topological Sort of the Tasks.