Processing math: 100%
Close
Close Window

Chapter 6 Mathematical Background

Show Source |    | About   «  6.1. Chapter Introduction   ::   Contents   ::   6.3. Miscellaneous Notation  »

6.2. Sets and Relations

6.2.1. Set Notation

The concept of a set in the mathematical sense has wide application in computer science. The notations and techniques of set theory are commonly used when describing and implementing algorithms because the abstractions associated with sets often help to clarify and simplify algorithm design.

A set is a collection of distinguishable members or elements. The members are typically drawn from some larger population known as the base type. Each member of a set is either a primitive element of the base type or is a set itself. There is no concept of duplication in a set. Each value from the base type is either in the set or not in the set. For example, a set named P might consist of the three integers 7, 11, and 42. In this case, P's members are 7, 11, and 42, and the base type is integer.

The following table shows the symbols commonly used to express sets and their relationships.

Table 6.2.1

{1,4}A set composed of the members 1 and 4{x|x is a positive integer}A set definition using a set formerExample: the set of all positive integersxPx is a member of set PxPx is not a member of set PThe null or empty set|P|Cardinality: size of set Por number of members for set PPQ,QPSet P is included in set Q,set P is a subset of set Q,set Q is a superset of set PPQSet Union: all elements appearing in P OR QPQSet Intersection: all elements appearing in P AND QPQSet difference: all elements of set P NOT in set Q

Here are some examples of this notation in use. First define two sets, P and Q.

P={2,3,5},Q={5,10}.

|P|=3 (because P has three members) and |Q|=2 (because Q has two members). The union of P and Q, written PQ, is the set of elements in either P or Q, which is {2, 3, 5, 10}. The intersection of P and Q, written PQ, is the set of elements that appear in both P and Q, which is {5}. The set difference of P and Q, written PQ, is the set of elements that occur in P but not in Q, which is {2, 3}. Note that PQ=QP and that PQ=QP, but in general PQQP. In this example, QP={10}. Finally, the set {5, 3, 2} is indistinguishable from set P, because sets have no concept of order. Likewise, set {2, 3, 2, 5} is also indistinguishable from P, because sets have no concept of duplicate elements.

The powerset of a set S is the set of all possible subsets for S. Consider the set S={a,b,c}. The powerset of S is

{, {a}, {b}, {c}, {a,b}, {a,c}, {b,c}, {a,b,c}}.

A collection of elements with no order (like a set), but with duplicate-valued elements is called a bag [1]. To distinguish bags from sets, we will use square brackets [] around a bag's elements. For example, bag [3, 4, 5, 4] is distinct from bag [3, 4, 5], while set {3, 4, 5, 4} is indistinguishable from set {3, 4, 5}. However, bag [3, 4, 5, 4] is indistinguishable from bag [3, 4, 4, 5].

A sequence is a collection of elements with an order, and which may contain duplicate-valued elements. A sequence is also sometimes called a tuple or a vector. In a sequence, there is a 0th element, a 1st element, 2nd element, and so on. We will use angle brackets to enclose the elements of a sequence. For example, 3,4,5,4 is a sequence. Note that sequence 3,5,4,4 is distinct from sequence 3,4,5,4, and both are distinct from sequence 3,4,5.

[1]The object referred to here as a bag is sometimes called a multilist. But, the term multilist also refers to a list that may contain sublists.

6.2.2. Relations

A relation R over set S is a set of ordered pairs from S. As an example of a relation, if S is {a,b,c}, then

{a,c,b,c,c,b}

is a relation, and

{a,a,a,c,b,b,b,c,c,c}

is a different relation. If tuple x,y is in relation R, we may use the infix notation xRy. We often use relations such as the less than operator (<) on the natural numbers, which includes ordered pairs such as 1,3 and 2,23, but not 3,2 or 2,2. Rather than writing the relationship in terms of ordered pairs, we typically use an infix notation for such relations, writing 1<3.

Define the properties of relations as follows, with R a binary relation over set S.

  • R is reflexive if aRa for all aS.
  • R is irreflexive if aRa is not true for all aS.
  • R is symmetric if whenever aRb, then bRa, for all a,bS.
  • R is antisymmetric if whenever aRb and bRa, then a=b, for all a,bS.
  • R is transitive if whenever aRb and bRc, then aRc, for all a,b,cS.

As examples, for the natural numbers, < is irreflexive (because :math`aRa` is never true), antisymmetric (because there is no case where aRb and bRa), and transitive. Relation is reflexive, antisymmetric, and transitive. Relation = is reflexive, symmetric (and antisymmetric!), and transitive. For people, the relation "is a sibling of" is symmetric and transitive. If we define a person to be a sibling of himself, then it is reflexive; if we define a person not to be a sibling of himself, then it is not reflexive.

6.2.3. Equivalence Relations

R is an equivalence relation on set S if it is reflexive, symmetric, and transitive. An equivalence relation can be used to partition a set into equivalence classes. If two elements a and b are equivalent to each other, we write ab. A partition of a set S is a collection of subsets that are disjoint from each other and whose union is S. An equivalence relation on set S partitions the set into disjoint subsets whose elements are equivalent. The UNION/FIND algorithm efficiently maintains equivalence classes on a set. One application for such disjoint sets computing a minimal cost spanning tree.

Example 6.2.1

For the integers, = is an equivalence relation that partitions each element into a distinct subset. In other words, for any integer a, three things are true.

  1. a=a,
  2. if a=b then b=a, and
  3. if a=b and b=c, then a=c.

Of course, for distinct integers a, b, and c there are never cases where a=b, b=a, or b=c. So the requirements for symmetry and transitivity are never violated, and therefore the relation is symmetric and transitive.

Example 6.2.2

If we clarify the definition of sibling to mean that a person is a sibling of him- or herself, then the sibling relation is an equivalence relation that partitions the set of people.

Example 6.2.3

We can use the modulus function to define an equivalence relation. For the set of integers, use the modulus function to define a binary relation such that two numbers x and y are in the relation if and only if xmodm=ymodm. Thus, for m=4, 1,5 is in the relation because 1mod4=5mod4. We see that modulus used in this way defines an equivalence relation on the integers, and this relation can be used to partition the integers into m equivalence classes. This relation is an equivalence relation because

  1. xmodm=xmodm for all x;
  2. if xmodm=ymodm, then ymodm=xmodm; and
  3. if xmodm=ymodm and ymodm=zmodm, then xmodm=zmodm.

6.2.4. Partial Orders

A binary relation is called a partial order if it is antisymmetric and transitive. If the relation is reflexive, it is called a non-strict partial order. If the relation is irreflexive, it is called a strict partial order. The set on which the partial order is defined is called a partially ordered set or a poset. Elements x and y of a set are comparable under a given relation R if either xRy or yRx. If every pair of distinct elements in a partial order are comparable, then the order is called a total order or linear order.

Example 6.2.4

For the integers, relations < and define partial orders. Operation < is a total order because, for every pair of integers x and y such that xy, either x<y or y<x. Likewise, is a total order because, for every pair of integers x and y such that xy, either xy or yx.

Example 6.2.5

For the powerset of the integers, the subset operator defines a partial order (because it is antisymmetric and transitive). For example, {1,2}{1,2,3}. However, sets {1, 2} and {1, 3} are not comparable by the subset operator, because neither is a subset of the other. Therefore, the subset operator does not define a total order on the powerset of the integers.

   «  6.1. Chapter Introduction   ::   Contents   ::   6.3. Miscellaneous Notation  »

nsf
Close Window