0% found this document useful (0 votes)
54 views12 pages

CSC 204 SS5

Sets are collections of distinct objects called elements that can be grouped together. There are three main ways to specify a set: listing all its members, stating a property its elements share, or defining recursive rules to generate members. Operations on sets include union, intersection, and difference. The union of sets A and B contains elements that are in A, B, or both. The intersection of A and B contains only elements that are common to both sets.

Uploaded by

Chuks Valentine
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views12 pages

CSC 204 SS5

Sets are collections of distinct objects called elements that can be grouped together. There are three main ways to specify a set: listing all its members, stating a property its elements share, or defining recursive rules to generate members. Operations on sets include union, intersection, and difference. The union of sets A and B contains elements that are in A, B, or both. The intersection of A and B contains only elements that are common to both sets.

Uploaded by

Chuks Valentine
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

CSC 204: Fundamentals of Data Structures

Study Session 5: Set Structure

Introduction
Sets are usually used to group objects together. Often, the objects in a set have similar properties.
For instance, all the students who are currently enrolled in this course makeup a set. The language
of set is a means to study such collections in an organized fashion.

In this study session, you will also be provided with the definition of a set, as well as the operations
that can be performed on sets. You will also get to know about set notations and cardinality of sets.

Learning Outcomes for Study Session 5


After studying this session, you should be able to:
5.1 Define set structure.
5.2 Define equality of sets, empty sets, and some other set terms.
5.3 Identify set notation and specify set correctly.
5.4 Explain the basic set operations
5.5 Evaluate cardinality of set.

Page 1 of 12
CSC 204: Fundamentals of Data Structures

5.1 Definition of Set


A set is any collection of definite, distinguishable objects, and these objects are called the elements
of the set. It is a computer implementation of the mathematical concept of a finite set. Unlike most
other collection types, rather than retrieving a specific element from a set, one typically tests a
value for membership in a set. If we have a set, we say that some objects belong (or do not belong)
to this set, are (or are not) in the set. Therefore, we also say that sets consist of their elements.

For example, the number of students in this classroom is a set. Similarly, the English alphabets may
be viewed as the set of letters of the English language.Also, the set of natural numbers is a set, and
so on. So, sets can consist of elements of various natures, such as, people, physical objects,
numbers, signs, other sets, and so on.

Note: We will use the word object or entity in a very broad way to include all these different kinds
of things. So, in general, a set is an ABSTRACT object; its members do not have to be physically
collected together for them to constitute a set.

Pilot Question 5.1


Define a set.

5.2 Definition of Set Terminologies


Now, there are certain general terms you will be coming across in sets and you must familiarize
yourself with them. These are enumerated below.

5.2.1 Equal sets


Two sets A and B are said to be equal to each other, if A and B have the same elements. It is
defined as; A ═ B. For example, if A ═ {3,4,6,8} and B ═ {3,4,6,8}, then A ═ B

5.2.2 Subset
A is a subset of B, if every element of A is also an element of B. That is, A is included in B or B
includes A or B is a superset of A. This is defined symbolically as, A Ϲ B or B Ͻ A. For example, if
A ═ {a, b, c, e, h} and B ═ {a ,b, c, d, e, f g, h, i},therefore A is a subset of B.

5.2.3 Proper Subset


A is said to be a proper subset of B if A is included in B, but A is not equal to B, but there exists at
least one element b Ϲ B such that b ₡ A. It is usually defined symbolically as A Ϲ B strictly, if A Ϲ
B and A≠ B.

Page 2 of 12
CSC 204: Fundamentals of Data Structures

5.2.4 The empty set


The set which has no element is called the empty set and is denoted by Ø.

That is Ø = {x ϵ A: x ₡ A}, where A is any set.

5.2.5 Power set of a set


Let X be any set. The set of all subsets of X is called the power set of X and is denoted by

P (X).We can define power set therefore as P( X ) = {A : A Ϲ X}

It is now worthy of note that, if A and B can be any sets, then the following propositions can be
proved easily:

(1) A = B if and only if A Ϲ B and B Ϲ A,

(2) A Ϲ A and Ø Ϲ A,

(3) A ϵ P(A) and Ø ₡ P(A),

(4) P( Ø) = { Ø }. Note that P (Ø) is not empty but has exactly one element, i.e. Ø.

Pilot Question 5.2


What is an empty set and how is it denoted?

5.3 Set Notation


Sets are usually denoted by capital letters (A, B, C,…). The elements of the set are usually denoted
by small letters (a, b, c, …).

1. If X is a set and x is an element of X, we write x ϵ X. Which reads as x belongs to X


2. If X is a set and y is not an element of X, we write y ₡ X . Which reads as y does not
belong to X
3. When we give a set, we generally use braces, e.g.:
(i) S ═ { a, b, c, …} where the elements are listed between braces, the three dots imply
that the law of formation of other elements is known,
(ii) S ═ {x ϵ X : p( x ) is true } where ‘x’ stands for a generic element of the set S and p
is a property defined on the set X .
You have to know very importantly that, if we want to emphasize that the elements of the set are
also sets, we denote the set by script capital letter, such as:

(i) A ═ {A, B, C, …} where A, B, C, … are sets.

(ii) A ═ {Aα : α ϵΓ} where Γ is the so called indexing set and Aα 's are sets.

Page 3 of 12
CSC 204: Fundamentals of Data Structures

The following are examples of sets:

a. N ═ {0, 1, 2, 3, …}, that is, the set of all natural numbers,


N+═ {n ϵ N : n > 0}

b. Z ═ {0, -1, +1, -2, +2, …}, that is, the set of all integers,
c. Q ═ { p/q : p ϵ Z : q ϵ N+ }, that is, the set of all rational numbers,
Q+═ {r ϵ Q : r > 0},

d. R ═ the set of all real numbers,


R+ ═ {x ϵ R: x > 0},

e. C ═ the set of all complex numbers.


5.3.1 Specification of Sets
There are three main ways to specify a set:
i. By listing all its members (list notation);
ii. By stating a property of its elements (predicate notation);
iii. By defining a set of rules which generates (defines) its members (recursive rules).

5.3.2 List Notation.


This first way is suitable only for finite sets. In this case, we list names of elements of a set,
separate them by commas and enclose them in braces. For examples: {1, 12, 45}, {George
Washington, Bill Clinton}, {a, b, d, m}.
The “Three-dot abbreviation” like in, {1,2, ..., 100 }, shows that, the set elements continues in that
order and ends at 100. In the case of, {1, 2, 3, 4,…}, this is not a real list notation, it is not a finite
list, but it is a common practice as long as the continuation is clear. Note that we do not care about
the order of elements of the list, and elements can be listed several times. For instance, {1, 12, 45},
{12, 1, 45,1} and {45,12, 45,1} are different representations of the same set.

5.3.3 Predicate Notation.


In this case, for example, {x | x is a natural number and x < 8} Reads as, “the set of all x such that x
is a natural number and is less than 8” So the second part of this notation is a property the members
of the set share which is a condition or a predicate which holds for members of this set.
Other examples include:

a. { x | x is a letter of Russian alphabet}


b. {y | y is a student of UMass and y is older than 25}

Page 4 of 12
CSC 204: Fundamentals of Data Structures

Generally, predicate notation takes the form:

{ x | P(x)}, where P is some predicate (condition, property).

The language to describe these predicates is not usually fixed in a strict way. But it is known that
unrestricted language can result in paradoxes. Example: { x | x∉ x}. The moral: not everything that
looks on the surface like a predicate can actually be considered to be a good defining condition for
a set.

5.3.4 Recursive Rules.


For example, the set E of even numbers greater than 3, can be written as:

a) 4∈E
b) if x ∈ E, then x + 2 ∈ E
c) Nothing else belongs to E.
The first rule is the basis of recursion, the second one generates new elements from the elements
defined before and the third rule restricts the defined set to the elements generated by rules a and b.
(The third rule should always be there. Sometimes in practice it is left implicit. It is best when you
are a beginner to make it explicit.

Pilot Question 5.3


i. How is a set and its elements denoted?
ii. Enumerate the 3 ways of specifying sets.

5.4 Operations between Sets


Several operations can be defined on sets. This is what you will be learning now. Let A and B be
arbitrary sets.

5.4.1 The union of Sets


The union of sets A and B, written as A ∪ B, is the set whose elements are just the elements of

A or B or both. In the predicate notation the definition is A ∪ B =def { x| x ∈ A or x ∈ B}

The examples are as follows:

Let K = {a, b}, L = {c, d} and M = {b, d}, then

a) K ∪ L = {a, b, c, d}
b) K ∪ M = {a, b, d}

Page 5 of 12
CSC 204: Fundamentals of Data Structures

c) L ∪ M = {b, c ,d}
d) (K ∪ L) ∪ M = K ∪ (L ∪ M) = {a, b, c, d}
e) K ∪ K = K ═ {a, b}
f) K ∪∅ = ∅∪ K = K = {a, b}.

5.4.2 The Intersection of Sets


The intersection of A and B, denoted by A ∩ B, is the set whose elements are just the elements of
both A and B. In other words, they are elements in common. In the predicate notation the definition
is A ∩ B =def { x | x ∈ A and x ∈ B}

The following examples, give better understanding on intersection of sets.

Using the elements for K, L, and M in the immediate examples above,

i. K∩L = ∅
ii. K∩M = {b}
iii. L∩M = {d}
iv. (K ∩ L) ∩ M = K ∩ (L ∩ M) = ∅
v. K ∩ K = K ═ {a, b }
vi. K∩∅=∅∩K=∅

5.4.3 Difference and Complement of Sets


It is also called relative complement, that is, the complement of B relative to A. The predicate
notation defines this operation as follows:

A – B =def { x| x ∈ A and x ∉ B}

Using the previous examples, of elements of K, L, and M:

1. K – L = {a,b}
2. K – M = {a}
3. L – M = {c}
4. K – K = ∅
5. K – ∅ = K ═ {a, b}
6. ∅ – K = ∅.

Page 6 of 12
CSC 204: Fundamentals of Data Structures

A – B is also called the relative complement of B relative to A. This operation is to be


distinguished from the complement of a set A, usually written asA', which is the set consisting of
everything not in A. In predicate notation A' =def { x | x ∉ A}

It is natural to ask, where do these objects come from which do not belong to A? In this case, it is
presupposed that there exists a universe of discourse and all other sets are subsets of this set. The
universe of discourse is conventionally denoted by the symbol U.

Then you have

A' =def U – A

5.4.4 Set-Theoretic equalities


There are a number of general laws about sets which follow from the definitions of set-theoretic
operations, subsets, and so on. A useful selection of these is shown below. They are grouped under
their traditional names. These equations below hold for any sets X, Y, Z:

1. Idempotent Laws

(a) X ∪ X = X (b) X ∩ X = X

2. Commutative Laws

(a) X ∪ Y = Y ∪ X

(b) X ∩ Y = Y ∩ X

3. Associative Laws

(a) (X ∪ Y) ∪ Z = X ∪ (Y ∪ Z)

(b) (X ∩ Y) ∩Z = X ∩ (Y ∩ Z)

4. Distributive Laws

(a) X ∪ (Y ∩ Z) = (X ∪ Y) ∩ (X ∪ Z)

(b) X ∩ (Y ∪ Z) = (X ∩ Y) ∪ (X ∩ Z)

5. Identity Laws

(a) X ∪∅ = X (c) X ∩ ∅ = ∅

(b) X ∪ U = U (d) X ∩ U = X

6. Complement Laws

Page 7 of 12
CSC 204: Fundamentals of Data Structures

(a) X ∪ X' = U (c) X ∩ X' = ∅

(b) (X')' = X (d) X – Y = X ∩ Y'

7. DeMorgan’s Laws

(a) (X ∪ Y)' = X' ∩ Y' (b) (X ∩ Y)' = X'∪ Y'

8. Consistency Principle

(a) X ⊆ Y if and only if X ∪ Y = Y

(b) X ⊆ Y if and only if X ∩ Y = X

Pilot Question 5.4


i. State Idempotent laws as discussed in this Study Session
ii. State commutative laws as discussed in this Study Session
iii. Mention any two operations that can be carried out on sets as discussed in this Study
Session.
iv. If set A = {1, 3, 8} and B = {7, 8, 10} find A ∩ B

5.5 Cardinality of Sets


The following explanation defines cardinality of sets:

Let X and Y be any sets.

Firstly, you say that X and Y have the same cardinality and write | X | = |Y | or say that X and Y are
equivalent sets and write X ˜ Y if there exists a bijective function f : X → Y .

Secondly, you say that the cardinality of X is not greater than the cardinality of Y (or the cardinality
of Y is not less than the cardinality of X) and write | X | ≤ |Y | if there exists an injective function

F: X →Y .

Thirdly, you say that the cardinality of X is less than the cardinality of Y (or the cardinality of Y is
greater than the cardinality of X) and write | X | < | Y | if | X |≤| Y | and | X | ≠ | Y |.

Pilot Question 5.5


i. What is cardinality of a set?

Page 8 of 12
CSC 204: Fundamentals of Data Structures

Summary of Study Session 5


In this Study Session 5, you have learnt that:

1. A set is any collection of definite, distinguishable objects, and these objects are
called the elements of the set. It is a computer implementation of the mathematical
concept of a finite set.
2. Sets are usually denoted by capital letters (A, B, C, …). And the elements of the set
are usually denoted by small letters (a, b, c, …).
3. The union of sets A and B, written as A ∪ B, is the set whose elements are just the
elements of A or B or of both.
4. The intersection of A and B, written usually as A ∩ B, is the set whose elements are
just the elements of both A and B.
5. Two sets A and B are said to be equal to each other, if A and B have the same
elements.
6. We say that A is a subset of B, if every element of A is also an element of B.
7. Another binary operation on arbitrary sets is the difference, that is, “A minus B”,
usually written A – B, which reads as, ‘subtracts’ from A all elements which are in B.
8. Cardinality of a set is the number of elements contained in the set.

Page 9 of 12
CSC 204: Fundamentals of Data Structures

Pilot Answers
Pilot Answer 5.1
A set is a collection of definite distinguishable objects, and these objects are called the elements of
the set.

Pilot Answer 5.2


An empty set is a set which has no element. It is denoted by Ø

Pilot Answer 5.3


i. A set is usually denoted by capital letters while its elements are denoted by small letters.
ii. The 3 ways of specifying sets are:

a) List notation
b) Predicate notation
c) Recursive rules
Pilot Answer 5.4
i. Idempotent laws states that: (i)X∪X=X (ii)X∩X=X
ii. Commutative laws states that: (i)X∪Y=Y∪X (ii)X∩Y=Y∩X
iii. Operations on set includes:

(i) Union of set


(ii) Intersection of set
(iii) Difference of set
(iv)Compliment of sets
iv A ∩ B = 8 because element 8 can be found in both sets A and B

Pilot Answer 5.5


Cardinality of a set is the number of elements contained in the set

Page 10 of 12
CSC 204: Fundamentals of Data Structures

Glossary of Terms
Set:A set is any collection of definite, distinguishable objects, and these objects are called the
elements of the set.
Empty set: The set which has no element is called the empty set and is denoted by Ø.

That is Ø = {x ϵ A: x ₡ A}, where A is any set.

Union of sets: The union of sets A and B, written as A ∪ B, is the set whose elements are just the
elements of A or B or both.

Intersection: The intersection of A and B,denoted as A ∩ B is the set whose elements are just the
elements of both A and B. In other words, they are elements in common.

Cardinality of set: Cardinality of a set is the number of elements contained in the set

Page 11 of 12
CSC 204: Fundamentals of Data Structures

Self-Assessment Questions (SAQs) for Study Session 5


Now that you have completed this study session, you can assess how well you have achieved its
Learning Outcomes by answering the following questions.

i. Define a set?
ii. What is an empty set and how is it denoted?
iii. Mention the 3 ways of specifying sets.
iv. Mention any two operations that can be carried out on sets as discussed in this Study
Session.
v. What is cardinality of a set?

Page 12 of 12

You might also like