Processing math: 100%
Close
Close Window

CSC303: Theory of Computation

Chapter 2 Mathematical Background

Show Source |    | About   «  1.4. Grammar Exercises   ::   Contents   ::   2.2. Relations  »

2.1. Set Notation

2.1.1. Introduction to Sets

The concept of a set in the mathematical sense is widely used 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 2.1.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 QP×QSet (Cartesian) Product: yields a set of ordered pairs

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). Both of these sets are finite in length. Other sets can be infinite, for example, the set of integers.

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 set product or Cartesian product of two sets Q×P is a set of ordered pairs. For our example sets, the set product would be

{(2,5), (2,10), (3,5), (3,10), (5,5), (5,10)}.

The powerset of a set S (denoted 2S) 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. 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.4. Grammar Exercises   ::   Contents   ::   2.2. Relations  »

nsf
Close Window