Sei sulla pagina 1di 4

Basic Operations and Sets

Sets
A set is a collection of member (or elements) each member of a set either is itself a set or
primitive element called an atom. All member of a set are different, which means no set can
contain two copies of the same elements.
When used as tool in algorithm and data structure design, atoms usually are integers,
characters or strings and all elements in any one set are usually of the same type. We shall
often assume that a relation, usually denoted and read less than or process, linearly orders
atoms. A linear order < on a set S satisfies two properties:
1. For any a and b in S, exactly one a< b, a=b or b< a is true.
2. For all a, b and c in S, if a<b and b<c then a<c (transitivity).

An ADT with union, intersection and difference
A set is an unordered collection of particular objects. These objects are referred to as
elements. An example is shown as:
A = {1, 2, 3, 4, 5, 9, 10}
Where. A is the set and the elements are identified within the braces. Generally a set is denoted
by a capital letter while lower case letters represents the elements. For a large series with a
pattern, the set could be designated as:

N = {1, 2, 3, 4, 5, . }

The use of the symbol e in set theory means that object is an element of a set. For example, a
e S means that a is an element within the set S. More than one element can be identified such
as a, b e S which indicates that both a and b are elements of the set S. Continuing in this vein,
e means that an element is not in a set. For example, a e S states that a is not an element
within the set S.

A subset is a set where every element belongs to another set. The symbols c and are used to
designate subsets, depending upon the syntax. If all of the elements of V are also elements of T
then V is a subset of T and this can be written as V c T , which can be interpreted as saying V
is contained in T, or T V, which can be used to imply that T contains V. For example,
T = {all letters in the English alphabet}
V = {all vowels}

then V c T

If there exists one element that exists in V that is not in T, then R is not a subset and
this is designated as V . T.

If two sets, S and T, contain exactly the same identical elements, then they are equal
and S = T. It is also true that S c T and T c S. If on the other hand, S c T and S = T then S is
called a proper subset of T. This means that there is at least one element of T, which is not an
element of S.

It is important to recognize the syntax utilized in set theory. For example, if the set S =
{a, b, c}, then a e S is the correct form that means a is an element of the set S. But, using {a} e
S is incorrect because the braces mean a set. S can consist of subsets that contain only one
element. For example, {a} can be used to designate a subset of S containing only a. Then, it is
proper to state that {a} c S which means that the set containing {a} is contained within S.

It is also possible to represent a set of elements in one set from another set, which has
certain properties. This is written as:

S = {x e T | x has the property p}

or, if the set T is clear to the user, this can be shortened to the form:

S = {x | x has the property p}

The following example shows the set S contains all of those elements from the set of natural
numbers N, where x + 2 = 7.

S = {x e N | x + 2 = 7}

Since S contains only one element, 5, this is called a unit set. Another example shows that the
definition of a particular set can be done in different fashions. In this first definition, the set E
will contain all even natural numbers:

E = {x e N | x is even}
hence,
E = {2, 4, 6, 8, . }

Another way of defining this set is as follows:

E = {2n | n e N }

By convention, uses of certain letters usually define the element of a set. For example,
the null set, C, is an empty set, which contains no elements. C is a subset of all sets. The
universal set, U, is the set consisting of all the elements that are of interest for a problem.
N is generally used for natural values (N = {1, 2, 3, 4, ...}, sometimes 0 is considered a
natural number), and Z is used for integers (Z = {..., -3, -2, -1, 0, 1, 2, 3, ...}), and R represents
all real numbers.

The union of sets defines another set, which consists of elements from two or more
sets. It can be shown mathematically as A B whose elements are {x | x e A or x e B}. This
operation is often called a Boolean OR operation since the element must be in either set A or
set B to be included in the newly formed set. For example, if

A = {0, 2, 3, 5, 7, 9, 11}
and
B = {1, 2, 4, 6, 7, 9, 11}
then
C = A B = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11}

A figure called a Venn diagram is often used to
depict the different relationships in set theory. If
the two sets have at least one common element
then they are called conjoint. If, on the other
hand, there are no common elements in the two
sets then they are said to be disjoint. For
example, E = {all male students at Ferris} and F =
{all female students at Ferris}, the sets are
disjoint because a student cannot be a member
of both groups. In the example above, the sets A
and B are conjoint since there is at least one
common element.

The intersection of two sets is denoted as C = A
B where the elements of this new set are
defined by {x | x e A and x e B}. This is
sometimes called a Boolean AND operation since
an element must be in both sets to be included in the new set. If the sets are disjoint then A
B = 0. In the example above, where:

A = {0, 2, 3, 5, 7, 8, 9, 11}
and
B = {1, 2, 4, 6, 7, 9, 11}
then
C = A B = {2, 7, 9, 11}

The complement of a set is defined by the
elements that are a part of the universal set
but not in the subset. If A is a subset then
the complement is shown as A
c
or comp (A).
As an example, if
U = {all male and female students at FSU}
then the subset
A = {all male students at FSU}
then
comp (A) = {all female students at FSU}

Another useful set of operations is A\B which
means A minus B. The new set will contain
all of those elements of A that are not in B or
{x | x e A and x e B}. Using the examples of A
and B from above,

C = A\B = {0, 3, 5, 8}

Sets also follow the distributive law. Thus,

A (B C) = (A B) (A C)
and
A (B C) = (A B) (A C)

While not a proof, this property is depicted in
using Venn diagrams.

Venn Diagram showing the union of two
sets.

Venn Diagram showing the intersection of
two sets.

Venn Diagram showing the A minus B set
operation.

3.3 A Bit Vector Implementation of Sets
The best implementation of a SET ADT depends on the operation to be performed and
on the size of the set. When all sets in our domain of discourse are subsets of a small
universal set whose elements are the integers 1,2,3.N for some fixed N, then we can
use a bit-vector (boolean array) implementation. A set is represented by a bit vector in which
the I
th
bit is true if I is an element of the set. The major advantage of this representation is that
MEMBER, INSERT and DELETE operation can be performed in constant time by directly
addressing the appropriate bit. UNION, INTERSECTION and DIFFERENCE can be performed in
time proportional to the size of the universal set.


Graphical "proof" of the distributive law.

Potrebbero piacerti anche