180 likes | 463 Views
Transitive Closure. Theorem 1. Let R be a relation on a set A. Then R is the transitive closure of R.
E N D
Transitive Closure Theorem 1. Let R be a relation on a set A. Then Ris the transitive closure of R. • the reachability relation R* of a relation R on a set A is defined as xR*y, which means that x=y or xRy, i.e. y is reachable from x if either y is x or there is some path from x to y • R*=R • M =M (M )(M )… Theorem 2. Let A be a set with |A|=n, and let R be a relation on A. Then R=RR2…Rn. In other words, powers of R greater than n are not needed to computer R.
Warshall’s Algorithm • Let R be a relation on a set A={a1,…,an}. For 1≤k≤n, define a Boolean matrix Wk as follows: Wk has a 1 in position i, j if and only if there is a path from ai to aj in R whose interior vertices, if any, come from the set {a1,…,ak}. • Since any vertex must come from the set {a1,…,an}, it follows that the matrix Wn has a 1 in position i, j if and only if some path in R connects ai with aj, i.e. Wn=M • Define W0 to be MR, then the sequence W0, W1 …, Wn has the first term as MR and last term as M • Suppose Wk =[tij] and Wk-1 =[sij], then tij =1 if and only if either (1) sij =1 or (2) sik =1 and skj =1
Warshall’s Algorithm To compute Wk from Wk-1 Step1: First transfer to Wk all 1’s in Wk-1 Step2: List the locations p1,p2 …, in column k of Wk-1, where the entry is 1, and the locations q1,q2 …, in row k of Wk-1, where the entry is 1 Step3: Put 1’s in all the positions pi,pj of Wk (if they are not already there) • Compared with the formula (1) M =M (M )…(M ), which requires about n4 steps without the final joins, while the Warshall’s algorithm requires n3 steps in all • Thus Warshall’s algorithm is a significant improvement over direct computation M of using the formula (1)
Transitive Closure • if R and S are equivalence relations on a set A, then the relation RS is the largest equivalence relation contained in both R and S Theorem 3. If R and S are equivalence relations on a set A, then the smallest equivalence relation containing both R and S is (RS).
5. Functions Functions in Computer Science Growth of Functions
Functions Function, a special type of relation • let A and B be nonempty sets, a function f from A to B, denoted as f: AB, is a relation from A to B such that for all aDom(f), f(a), the f-relative set of a, contains only one element of B, i.e. f(a)={b}, or f(a)=b • the relation f can be described as the set of pairs {(a, f(a)) | aDom(f)} • functions are also called mappings or transformations; the element a is called an argument of the function f, and f(a) is called the value of the function for the argument a, and is also referred to as the image of a under f
Functions • let A be an arbitrary nonempty set, the identityfunction on A, denoted by 1A, is defined by 1A(a)=a, if A1A, then 1A(A1)= A1 • 1A is the relation • suppose that f: AB and g: BC are functions, then the composition of f and g, gf is a relation; let aDom(gf), then (gf)(a)=g(f(a)) • if f and g are functions specified by giving formulas, then gf is also a function, and the formula for gf is produced by substituting the formula for f into the formula for g
Special Types of Functions • let f be a function from A to B, then f is everywhere defined if Dom(f)=A; f is onto if Ran(f)=B; f is one to one if there is no f(a)=f(a') for two distinct elements a and a' of A • one to one: if f(a)=f(a'), then a=a' • if f is one to one and onto, it’s also called a bijection between Dom(f) and Ran(f) • f is called a one-to-one correspondence between A and B if f is everywhere defined, onto and one to one • a function f: AB is said to be invertible if its inverse relation f-1 is also a function
Invertible Functions Theorem1. Let f: AB be a function. (a) then f-1 is a function from B to A if and only if f is one to one if f-1 is a function, then (b) the function f-1 is also one to one (c) f-1 is everywhere defined if and only if f is onto (d) f-1 is onto if and only if f is everywhere defined • if f is a one-to-one correspondence between A and B, then f-1 is a one-to-one correspondence between B and A; for all a in A and b in B, f(f-1(b))=b and f-1(f(a))=a • if f: AB is a one-to-one function, then the equation b=f(a) is equivalent to a= f-1(b)
Composition of Functions Theorem2. Let f: AB be any function. Then (a) 1Bf=f (b) f1A=f if f is a one-to-one correspondence between A and B, then (c) f-1f = 1A (d) ff-1=1B Theorem3. (a) Let f: AB and g: BA be functions such that gf= 1A and fg= 1B.Then f is a one-to-one correspondence between A and B, g is a one-to-one correspondence between B and A, and each is the inverse of the other (b) Let f: AB and g: BC be invertible. Then gf is invertible, and (gf)-1=f-1 g-1
Functions • It’s often easier to show that a function is one to one and onto by constructing an inverse instead of proceeding directly Theorem4. Let A and B be two finite sets with the same number of elements, and let f: AB be an everywhere defined function. • if f is one to one, then f is onto • if f is onto, then f is one to one