1 / 23

Relations on a Set

Relations on a Set. Lecture 46 Section 10.1, 10.2, 10.5 Mon, Apr 30, 2007. Relations on a Set. A relation from a set A to a set B is a subset of A  B . A relation on a set A is a relation from A to A , i.e., a subset of A  A. Examples: Relations on a Set.

dorisdavis
Download Presentation

Relations on a Set

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Relations on a Set Lecture 46 Section 10.1, 10.2, 10.5 Mon, Apr 30, 2007

  2. Relations on a Set • A relation from a set A to a set B is a subset of AB. • A relation on a set A is a relation from A to A, i.e., a subset of AA.

  3. Examples: Relations on a Set • Define the relation < on the real numbers as x < y if x is less than y. • Define the relation  on the integers as ab if a divides b. • Define the relation  on Z as m  n if m – n is even. • Define the relation  on the set of all statements as p  q if p  q  p.

  4. Inverse Relations • Let R be a relation from A to B. • The inverse relation, denoted R–1, is defined by (a, b) R–1 if and only if (b, a) R.

  5. Examples: Inverse Relations • What is the inverse of the relation < on the real numbers? • What is the inverse of the relation  on the integers? • What is the inverse of the relation  on Z? What is the inverse of the relation  on statements, defined by p  q  p?

  6. Inverse of p q  p • Theorem: If p q  p, then p  q  q. • Proof: • Suppose that p q  p. • Then • (p  q)  p  p or p. • (p  p)  (q  p)  p  p. • T  (q  p)  T. • q  p  T.

  7. Inverse of p q  p • (q p)  q T  q. • (q q)  (p q) q. • F  (p q) q. • p qq. • p qq.

  8. Reflexivity, Symmetry, and Transitivity • Let R be a relation on a set A. • R is reflexive if xA,(x, x) R. • R is symmetric if x, yA, (x, y) R (y, x) R. • R is transitive if x, y, zA, (x, y) R and (y, z) R (x, z) R.

  9. Examples • Which of the following relations are reflexive? symmetric? transitive? • ab, on Z. • A B, on (U). • pq, on a set of statements. • a b (mod 10), on Z. • gcd(a, b) > 1, on Z. • pq = p, on a set of statements.

  10. Examples • Which of the following relations are reflexive? symmetric? transitive? • RR, on R. • , on R.

  11. 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 If a b, then (a, b) R (b, a)  R.

  12. Examples: Antisymmetry • The following relations are antisymmetric. • a b, on Z+. • A  B, on (U). • x  y, on R. • A  B = A, on (U). • f(x)g(x) = f(x) on the set of all functions from R to R.

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

  14. Examples: Partial Order Relations • The following relations are partial order relations. • a b, on Z+. • A  B, on (U). • x  y, on R. • Are the following relations partial order relations? • A  B = A, on (U) • f(x)g(x) = f(x) on functions

  15. 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.

  16. Total Order Relations • Which of the following partial orders are total orders? • x y, on R. • A  B, on (U). • a  b, on Z+.

  17. Total Order Relations • Which are total orders on R  R? • (a, b)  (c, d) if a  c and b  d. • (a, b)  (c, d) if a  c or b  d. • (a, b)  (c, d) if a + b  c + d. • (a, b)  (c, d) if a < c or (a = c and b  d).

  18. Example: Total Ordering and Sorting • In order to sort the list {(2, 3), (3, 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?

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

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

  21. 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 • = 0 if a == b • > 0 if a > b

  22. 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.

  23. C Library Functions • SortDemo.cpp

More Related