130 likes | 295 Views
Closure and Algorithms. Section 1.6 Mon, Sep 12, 2005. Transitive Closure. A relation R on a set A is transitively closed if the transitive property holds. ( a , b ) R and ( b , c ) R , then ( a , c ) R .
E N D
Closure and Algorithms Section 1.6 Mon, Sep 12, 2005
Transitive Closure • A relation R on a set A is transitively closed if the transitive property holds. • (a, b) R and (b, c) R, then (a, c) R. • Given a relation R on a set A, the transitive closure is the smallest set R* such that • RR*, • R* is transitively closed. • We may similarly define the reflexive closure and the symmetric closure of a set.
A Transitive Closure Algorithm • Given a finite set RAA, • Let R* = R. • For each (a, b) R* and each (b, c) R*, • If (a, c) R*, then add (a, c) to R*. • Repeat until there is no change in R*. • R* is the transitive closure of R. • If A is a finite set, then this algorithm must terminate.
Example • Let A be the set of all living people. • Let R be the “is a friend of” relation on A. • Let R* be the transitive closure of R. • What is R*? • What is the transitive closure of the “is the parent of” relation? • What is the symmetric closure of the “is the parent of” relation?
Operators vs. Relations • A binary operator from a set A to a set B is a function from AA to B. • For example, + is a binary operator from NN to N: + : (a, b) a + b • A binary operator is also a ternary relation: • (a, b, c) is in the relation if the operator maps (a, b) to c. • For example, under the + operator, (3, 5, 8) is in the relation and (3, 5, 9) is not in the relation.
Closed Operators • An operator on a set A is closed if it always produces a result that is back in the set A. • In this case, it is a ternary relation on A. • Or, if the operator is unary, then the relation is binary. • Addition is closed on the set N. • Division is not closed on the set N. • Squaring is closed on the set N. • Negation is not closed on the set N.
Closed Operators • Consider the collection A of sets {A1, A2, A3, …}, where An = {1, 2, 3, …, n}, for all n N. • The set A is closed under both and . • It is not closed under the set-difference operator. • Is it closed under symmetric difference?
Closed Relations • An n-ary relation R is closed if the (n – 1)-ary operator underlying it is closed. • For example, consider the ternary operator on NNN to N. * : (a, b, c) > gcd(gcd(a, b), c). • Is this closed on the set of even natural numbers?
The Closure of a Set under a Relation • Let R be a relation on a set A and let BA. • The closure of B under R is the smallest subset of A that contains B and that is closed under R. • Let A = N and let B = {6, 10, 15}. • What is the closure of B under the relation induced by the gcd function?
The Closure of a Set under a Relation • Let A be the set of real numbers and let B be the set of positive integers. • What is the closure of B under division? • Let A = 2N and let B the collection of all sets {n}, for all nN. • What is the closure of B under union?
A Closure Algorithm • Let R be an n-ary relation on a finite set A and let Bbe a subset ofA. • An algorithm to compute the closure of B: • Let B* = B. (This guarantees that B B*.) • Repeat the following steps until there is no change in B*. • For each b A – B*, (b is not yet in B*.) For every possible choice b1, …, bn – 1 B*, If (b1, …, bn – 1, b) R, Then add b to B*. (Now b is in B*.) • The set B* is the closure of B under R.
Example • Let A be the set of real numbers. • Let R be the ternary relation |a – b| = c on A. • What is the closure of the set{1/2, 1/3, 1/4}?
Algorithms • Two important properties of algorithms. • Every step is completely determined. • The process will terminate after a finite number of steps for all inputs. • Does the previous example have these properties?