Partial Order Relations Lecture 50 Section 10 5

  • Slides: 57
Download presentation
Partial Order Relations Lecture 50 Section 10. 5 Wed, Apr 20, 2005

Partial Order Relations Lecture 50 Section 10. 5 Wed, Apr 20, 2005

Antisymmetry A relation R on a set A is antisymmetric if for all a,

Antisymmetry A relation R on a set A is antisymmetric if for all a, b A, (a, b) R and (b, a) R a = b. ¢ This is equivalent to (a, b) R and a b (b, a) R. ¢

Examples: Antisymmetry ¢ The following relations are antisymmetric. a b, on Z+. l A

Examples: Antisymmetry ¢ The following relations are antisymmetric. a b, on Z+. l A B, on (U). l x y, on R. l A B = A, on (U). l f(x)g(x) = f(x) on the set of all functions from R to R. l

Partial Order Relations ¢ A relation R on a set A is a partial

Partial Order Relations ¢ A relation R on a set A is a partial order relation if R is reflexive. l R is antisymmetric. l R is transitive. l ¢ We use as the generic symbol for a partial order relation.

Examples: Partial Order Relations ¢ The following relations are partial order relations. a b,

Examples: Partial Order Relations ¢ The following relations are partial order relations. a b, on Z+. l A B, on (U). l x y, on R. l ¢ Is the relation f(x)g(x) = f(x) on functions a partial order relation?

Lexicographic Order ¢ Given a finite set of symbols, let them be listed in

Lexicographic Order ¢ Given a finite set of symbols, let them be listed in a specific order. l For example, a < b < c. Let S be the set of all finite strings over the set of symbols. ¢ Then we may define the lexicographic order relation on S. ¢

Lexicographic Order Let s, t S and let s = a 1 a 2…am

Lexicographic Order Let s, t S and let s = a 1 a 2…am and t = b 1 b 2…bn. ¢ Then s t if ¢ s = , or l |s| |t| and ai = bi, for all 1 i m, or l There exists k 1 with k m and k n and ai = bi for all 1 i < k, but ak < bk. l

Lexicographic Order The first condition says that s for all strings s S. ¢

Lexicographic Order The first condition says that s for all strings s S. ¢ The secondition says that s is no longer than t and all of s matches the first part of t. ¢ The third condition says that s and t differ at some common position. ¢

Lexicographic Order Theorem: The lexicographic order relation is a partial order. ¢ Proof: ¢

Lexicographic Order Theorem: The lexicographic order relation is a partial order. ¢ Proof: ¢ Reflexive: Obvious (? ) l Antisymmetric: l • Suppose s t and t s for some s, t S. • There are potentially 9 combinations of reasons for this.

Lexicographic Order • Maybe both are true because of the first condition. Then s

Lexicographic Order • Maybe both are true because of the first condition. Then s = and t = , so s = t. • Maybe both are true because of the secondition. Then |s| |t| and |t| |s|, implying that s and t have the same length. But also s matches “the first part” of t and t matches “the first part” of s. Therefore, s = t. • The second and third conditions are incompatible. • Etc.

Lexicographic Order l Transitivity: • Suppose that s t and t u, for some

Lexicographic Order l Transitivity: • Suppose that s t and t u, for some s, t, u S. • There are potentially 27 combinations of reasons for this. (!!!) • Maybe s = and t = . Then s u. • Etc.

Hasse Diagrams A Hasse diagram is a drawing that represents a partial order relation.

Hasse Diagrams A Hasse diagram is a drawing that represents a partial order relation. ¢ Draw a diagram in which ¢ a b is represented by a b. l a is drawn below b. l If there exists c such that a c and c b, then we represent only a c and c b; a b is implied by transitivity. l

Example: Hasse Diagram ¢ Let the relation be on ({a, b, c}). {a ,

Example: Hasse Diagram ¢ Let the relation be on ({a, b, c}). {a , b , c} {a , b } {a , c} {b , c} {a } {b } {c} {}

Example: Hasse Diagram ¢ Let the relation be on {1, 2, 3, 4, 6,

Example: Hasse Diagram ¢ Let the relation be on {1, 2, 3, 4, 6, 12} 12 6 4 2 3 1

Example: Partial Order Relation Let F be the set of all functions f :

Example: Partial Order Relation Let F be the set of all functions f : R+ R+. ¢ Let E be the set of equivalence classes [f] of F, under the equivalence relation f ~ g if f(x) is (g(x)). ¢ Define on E by [f] [g] if f(x) is O(g(x)). ¢

[f] [g] is Well Defined First, we must show that is well defined on

[f] [g] is Well Defined First, we must show that is well defined on E. ¢ Let f 1, f 2 [f] and g 1, g 2 [g]. ¢ Then f 1~ f 2 and g 1 ~ g 2. ¢ To show that is well defined, we must show that if [f 1] [g 1], then [f 2] [g 2], meaning that it does not matter which function we select to represent the class. ¢

[f] [g] is Well Defined So suppose that [f 1] [g 1]. ¢ Then

[f] [g] is Well Defined So suppose that [f 1] [g 1]. ¢ Then ¢ l f 2(x) is O(f 1(x)), and l f 1(x) is O(g 1(x)) and l g 1(x) is O(g 2(x)). So, f 2(x) is O(g 2(x)). ¢ Therefore, [f 2] [g 2]. ¢

Example: Partial Order Relation Theorem: is a partial order relation on E. ¢ Proof:

Example: Partial Order Relation Theorem: is a partial order relation on E. ¢ Proof: ¢ Reflexivity ¢ l It is clear that [f]. (Use M = 1, x 0 = 0. )

Example: Partial Order Relation ¢ Antisymmetry Suppose that [f] [g] and [g] [f]. l

Example: Partial Order Relation ¢ Antisymmetry Suppose that [f] [g] and [g] [f]. l Then f(x) is O(g(x)) and g(x) is O(f(x)). l Then f(x) is (g(x)). l Therefore, f ~ g. l Therefore, [f] = [g]. l

Example: Partial Order Relation ¢ Transitivity Suppose that [f] [g] and [g] [h]. l

Example: Partial Order Relation ¢ Transitivity Suppose that [f] [g] and [g] [h]. l Then f(x) is O(g(x)) and g(x) is O(h(x)). l We have already shown that this implies that f(x) is O(h(x)). l Therefore, [f] [h]. l ¢ Thus, is a partial order relation on E.

Comparable Elements and Total Orders Given a partial order on a set A, two

Comparable Elements and Total Orders Given a partial order on a set A, two elements a, b A are comparable if a b or b a. ¢ A partial order relation is a total order relation if any two elements are comparable under that relation. ¢

Total Order Relations ¢ Which of the following partial orders are total orders? x

Total Order Relations ¢ Which of the following partial orders are total orders? x y, on R. l A B, on (U). l a b, on Z+. l

Total Order Relations Define [f] [g] to mean f(x) is O(g(x)). Is this a

Total Order Relations Define [f] [g] to mean f(x) is O(g(x)). Is this a total order relation on the set of equivalence classes of functions? ¢ Which are total orders on R R. ¢ (a, b) (c, d) if a c and b d. l (a, b) (c, d) if a c or b d. l (a, b) (c, d) if a + b c + d. l (a, b) (c, d) if a < c or (a = c and b d). l

Example: Total Ordering and Sorting ¢ In order to sort the list {(2, 3),

Example: Total Ordering and Sorting ¢ In order to sort the list {(2, 3), (3, 2), (2, 2)}. it is necessary that be a total ordering of the Point class. If is not a total order relation, then the results of any sorting algorithm are unpredictable. ¢ Why? ¢

Example: Total Ordering and Sorting ¢ Define a Point object to consist of two

Example: Total Ordering and Sorting ¢ Define a Point object to consist of two doubles. class Point { double x; double y; };

Example: Total Ordering and Sorting ¢ Define operator<() on the Point class as follows.

Example: Total Ordering and Sorting ¢ Define operator<() on the Point class as follows. bool operator<(const Point& p, const Point& q) { if (p. x != q. x) return p. x < q. x; else return p. y < q. y; } ¢ Then define operator<=() to mean that a < b or a == b.

C Library Functions There are two standard library functions, bsearch() and qsort(), that perform

C Library Functions There are two standard library functions, bsearch() and qsort(), that perform a binary search and a quicksort on an array, respectively. ¢ For each function, one parameter is a function compare(a, b) that returns ¢ < 0 if a < b l = 0 if a == b l > 0 if a > b l

C Library Functions Those three requirements are not sufficient to guarantee that operator<=() is

C Library Functions Those three requirements are not sufficient to guarantee that operator<=() is a total order relation. ¢ It is the programmer’s responsibility to be sure that it is. ¢ Otherwise, neither bsearch() nor qsort() is guaranteed to work properly. ¢

Chains of Elements Let a partial order be defined on a set A. ¢

Chains of Elements Let a partial order be defined on a set A. ¢ A subset B A is called a chain if any two elements of B are comparable. That is, is a total order on B (although not on A). ¢

Chains of Elements ¢ Find a chain of subsets in ({a, b, c}) under

Chains of Elements ¢ Find a chain of subsets in ({a, b, c}) under the subset relation. l ¢ What is the longest possible chain? Find a chain of integers in Z+ under the divides relation. l What is the longest possible chain?

Maximal and Greatest Elements Let A be a partially ordered set under . ¢

Maximal and Greatest Elements Let A be a partially ordered set under . ¢ An element a A is a maximal element if, for all b A, either b a or a and b are not comparable. ¢ An element a A is a greatest element if, for all b A, b a. ¢

Example Let A = {1, 2, 3, …, 20} and let the relation be

Example Let A = {1, 2, 3, …, 20} and let the relation be a b. ¢ Are there any maximal elements? ¢ l ¢ If so, what are they? Are there any greatest elements? l If so, what are they?

Example Let B = {1, 2, 3, 4, 5, 6, 10, 12, 15, 20,

Example Let B = {1, 2, 3, 4, 5, 6, 10, 12, 15, 20, 30, 60} and let the relation be a b. ¢ Are there any maximal elements? ¢ l ¢ If so, what are they? Are there any greatest elements? l If so, what are they?

Maximal and Greatest Elements Must maximal elements be exist? ¢ Must greatest elements be

Maximal and Greatest Elements Must maximal elements be exist? ¢ Must greatest elements be exist? ¢ If maximal elements exist, must they be unique? ¢ If greatest elements exist, must they be unique? ¢

Minimal and Least Elements Minimal and least elements are similar to maximal and greatest

Minimal and Least Elements Minimal and least elements are similar to maximal and greatest elements, respectively. ¢ An element a A is a minimal element if, for all b A, either a b or a and b are not comparable. ¢ An element a A is a least element if, for all b A, a b. ¢

Examples ¢ What are the minimal and least elements (if any) of the sets

Examples ¢ What are the minimal and least elements (if any) of the sets A = {1, 2, 3, …, 20} and B = {1, 2, 3, 4, 5, 6, 10, 12, 15, 20, 30, 60} under the relation a b?

Compatible Order Relations Let 1 and 2 be partial order relations defined on a

Compatible Order Relations Let 1 and 2 be partial order relations defined on a set A. ¢ We call 2 compatible with 1 if, whenever a 1 b, it is also the case that a 2 b. ¢ In other words, a, b A, a 1 b a 2 b. ¢

Topological Sorting Given a partial order relation 1 defined on a set A, a

Topological Sorting Given a partial order relation 1 defined on a set A, a topological sorting for 1 is a total order relation 2 that is compatible with 1. ¢ For example, the ordinary “less than or equal to” relation is a topological sorting for the “divides” relation because ¢ is a total order, and l If a b, then a b. l

Application: Computer Graphics In the “old days, ” a difficult problem in computer graphics

Application: Computer Graphics In the “old days, ” a difficult problem in computer graphics was to draw the objects of a scene in such a way that when two objects were on the same line of sight, the closer object obscured the farther object. ¢ One solution was the Painter’s Algorithm: sort the shapes from front to back, and then draw them from back to front. ¢

Application: Computer Graphics Define the relation a 1 b on the shapes to mean

Application: Computer Graphics Define the relation a 1 b on the shapes to mean that shape a hides part of shape b. ¢ Define the relation a 2 b on the shapes to mean that shape a is closer to the viewer than is shape b. ¢ Clearly, 2 is a topological sorting for 1. ¢

Application: Computer Graphics ¢ Therefore, the Painter’s Algorithm was to Determine which shapes hide

Application: Computer Graphics ¢ Therefore, the Painter’s Algorithm was to Determine which shapes hide which shapes (relation 1). l Find a topological sorting for 1 (relation 2). l Draw the shapes in reverse order according to the total ordering 2. l

Example ¢ Consider the following scene, with the viewpoint inside the house, looking out

Example ¢ Consider the following scene, with the viewpoint inside the house, looking out at the tree.

Example ¢ The scene might be rendered like this:

Example ¢ The scene might be rendered like this:

Topological Sorting Theorem: If A is a finite set with a partial order 1

Topological Sorting Theorem: If A is a finite set with a partial order 1 defined on it, then there exists a topological sorting for 1. ¢ The proof is the following algorithm. ¢ A partially ordered finite set must have a minimal element. l Let x 0 be a minimal element of A. l Let A 1 = A – {x 0}. l

Topological Sorting A 1 is again a partially ordered finite set, so it must

Topological Sorting A 1 is again a partially ordered finite set, so it must have a minimal element. l Let x 1 be a minimal element of A 1 and define A 2 = A 1 – {x 1}. l Continue in this manner, defining x 3, x 4, x 5, and so on, until no elements remain. l Then define 2 as follows: xi 2 xj if and only if i j. l

Example ¢ Let A = {1, 2, 3, …, 10} under the “divides” relation.

Example ¢ Let A = {1, 2, 3, …, 10} under the “divides” relation. 8 10 4 9 6 2 3 5 1 7

Example ¢ Let x 0 = 1 and remove 1 from the set. 8

Example ¢ Let x 0 = 1 and remove 1 from the set. 8 10 4 9 6 2 3 5 7

Example ¢ Let x 1 = 7 and remove 7 from the set. 8

Example ¢ Let x 1 = 7 and remove 7 from the set. 8 10 4 9 6 2 3 5

Example ¢ Let x 2 = 5 and remove 5 from the set. 8

Example ¢ Let x 2 = 5 and remove 5 from the set. 8 10 4 9 6 2 3

Example ¢ Let x 3 = 3 and remove 3 from the set. 8

Example ¢ Let x 3 = 3 and remove 3 from the set. 8 10 4 6 2 9

Example ¢ Let x 4 = 9 and remove 9 from the set. 8

Example ¢ Let x 4 = 9 and remove 9 from the set. 8 10 4 6 2

Example ¢ Let x 5 = 2 and remove 2 from the set. 8

Example ¢ Let x 5 = 2 and remove 2 from the set. 8 10 4 6

Example ¢ Let x 6 = 10 and remove 10 from the set. 8

Example ¢ Let x 6 = 10 and remove 10 from the set. 8 4 6

Example ¢ Let x 7 = 6 and remove 6 from the set. 8

Example ¢ Let x 7 = 6 and remove 6 from the set. 8 4

Example ¢ Let x 8 = 4 and remove 4 from the set. 8

Example ¢ Let x 8 = 4 and remove 4 from the set. 8

Example ¢ Let x 9 = 8 and remove 8 from the set.

Example ¢ Let x 9 = 8 and remove 8 from the set.

Example The total ordering is 1, 7, 5, 3, 9, 2, 10, 6, 4,

Example The total ordering is 1, 7, 5, 3, 9, 2, 10, 6, 4, 8. ¢ This ordering is compatible with the divide relation. ¢ A number of the choices were arbitrary, so there are many other topological sortings for the divide relation on this set. ¢