You are on page 1of 32

Theory of Computer Science Unit 1

Sikkim Manipal University Page No.: 1


Unit 1 Mathematical Fundamentals
for Computer Science
Structure
1.1 Introduction
Objectives
1.2 Sets and Properties
1.3 Functions and Relations
1.4 Equivalence Relations
1.5 Recursive Functions
1.6 Strings and Growth Functions
1.7 Summary
1.8 Terminal Questions
1.9 Answers

1.1 Introduction
The idea of set is fundamental in the study of mathematical structures. All
most all mathematical objects of can be defined in terms of sets and the
language of set theory is used in every mathematical subject. Also the
concept of relation and function arises when we consider a pair of objects
and compare each other. In this unit we study the different relations on a set
and the algebraic structures with single binary operation. In computer
programming, recursion plays an important role. It is an important facility in
many programming languages. We have discussed the concepts recursive
functions and growth functions which are useful in analysis of algorithms
and approximating the time complexity.
The content of this unit provides a mathematical tool for the later units.


Theory of Computer Science Unit 1
Sikkim Manipal University Page No.: 2
Objectives:
At the end of the unit you would be able to
- understand the fundamental idea of certain mathematical concepts.
- learn the various operations on sets.
- understand relations and types of relations
- know the recursive functions and growth functions.

1.2 Sets and Properties
1.2.1 Definition
A set is a collection of objects in which we can say whether a given object is
in the collection. Sets will be denoted by capital letters.
The fact that a is a member of a set A is denoted by a e A and we call it as
a belongs to A. The members of a set are called elements.
If x is not an element of A then we write x e A.
1.2.2 Note
There are five ways used to describe a set:
i) Describe a set by describing the properties of the members of the set.
ii) Describe a set by listing its elements.
iii) Describe a set A by its characteristic function, defined as

A
(x) = 1 if xe A
= 0 if xe A
for all x in U, where U is the universal set, some times called the
universe of discourse , or just universe.
iv) Describe a set by recursive formula. This is to give one or more
elements of the set and a rule by which the rest of the elements of the
set may be generated.
v) Describe a set by an operation (say union, intersection, complement
etc) on some other sets.
Theory of Computer Science Unit 1
Sikkim Manipal University Page No.: 3
1.2.3 Example
Describe the set containing all the non-negative integers less than or equal
to 4.
Let X denote the set. Then X can be described in the following ways:
i) X = {x / x is a non-negative integer less than or equal to 4}
and N = {x / x is a natural number} = {1, 2, 3, 4, } is an infinite set.
ii) X = {0, 1, 2, 3, 4}.
iii)
A
(x) = 1 for x = 0, 1, 2, 3, 4
= 0 if xe A.
iv) X = {x
i + 1
= x
i
+ 1, i = 0, 1, 2, 3 where x
0
= 0}.
1.2.4 Definition
Suppose A and B are two sets. Then we say that A is a subset of B (written
as A _ B) if every element of A is also an element of B. A set A is said to be
a proper subset of B if there exists an element of B which is not an element
of A. Then A is a proper subset of B if A c B and A = B.
1.2.5 Note
The containment of sets has the following properties: Let X, Y and Z be
sets.
i) X _ X.
ii) If X _ Y and Y _ Z, then X _ Z.
iii) If X c Y and Y c Z, then Xc Z.
1.2.6 Example
i) Let N, Z, Q, R denote the set of natural numbers; the set of integers;
the set of rational numbers; the set of real numbers respectively. Then
R Q Z N c c c .
ii) If A = {1, 3, 5}, B = {1, 3, 5, 7} then A is a proper subset of B.

Theory of Computer Science Unit 1
Sikkim Manipal University Page No.: 4
1.2.7 Definition
Two sets A and B are said to be equal (denoted by A = B) if A is a subset of
B, and B is a subset of A.
Observation: To show two sets A and B are equal, we must show that each
element of A is also an element of B, and conversely.
1.2.8 Definitions
i) The set that contains no members is called the empty set and it is
denoted by |.
ii) A set which contains a single element is called singleton set. X = {2} is
a singleton set.
iii) If A and B are two sets, then the set {x / x e A or x e B} is denoted by
A B and we call it as the union of A and B.
iv) The set {x / x e A and x e B} is denoted by A B and we call it as the
intersection of A and B.
1.2.9 Properties
S. No. Property Union Intersection
1 Idempotent A A = A A A = A
2 Commutative A B = B A A B = B A
3 Associative A(B C) = (A B) C A(BC) = (AB) C

1.2.10 Definition
Let X and Y be two sets. The symmetrical difference of X and Y is defined
as {x/ xe X, or xe Y, but not both}. It is denoted as X A Y. It is also called
Boolean sum of two sets.
1.2.11 Definition
If A and B are two sets, then the set {x e B / x e A} is denoted by B A (or
B \ A) and it is called as the complement A in B.

Theory of Computer Science Unit 1
Sikkim Manipal University Page No.: 5
1.2.12 Examples
Let A = {1, 2, 3, 4, 5}, B = {a, b, c, d}, C = {2, b, d}, D = {3, a, c} and E = {x /x
is an integer and 1 < x < 2}.
i) A B = {x / x e A or x e B } = {1, 2, 3, 4, 5, a, b, c, d }.
ii) A B = {x / xe A and xe B}
= the set of all elements that are both in A and B
= | (the empty set).
iii) A C = {x / x e A and x e C} = {2}.
iv) A D = {x / x e A and x e D}= {3}
v) B C = {x/ xe B or xe C} = {2, a, b, c, d}.
Here we may note that, in rooster form, there is no necessity of writing
the same element two times. So we avoid writing the same element
second time in rooster form.
vi) B C = {a, b, c, d} {2, b, d}= {b, d}.
vii) E = {x/ x is an integer and 1 < x < 2} = |. (Since there is no integer
strictly lying between 1 and 2)
viii) A | = {x / xe A or xe |} = A.
ix) A | = {x / xe A and xe |] = |.
1.2.13 Definitions
i) If S and T are two sets, then the set {(s, t) / s e S and t e T} is called
the Cartesian product of S and T (here (a, b) = (s, t) a = s and
b = t). The Cartesian product of S and T is denoted by S T. Thus
S T = {(s, t) / s e S and t e T}.
Note that if S and T are two sets, then S T and T S may not be
equal.
ii) If S
1
, S
2
, ..., S
n
are n sets, then the Cartesian product is defined as
S
1
S
2
S
n
= {(s
1
, s
2
, , s
n
) / s
i
e S
i
for 1 s i s n}.

Theory of Computer Science Unit 1
Sikkim Manipal University Page No.: 6
Here the elements of S
1
S
2
S
n
are called ordered n-tuples. For
any two n-tuples, we have (s
1
, s
2
, , s
n
)= (t
1
, t
2
, , t
n
) s
i
= t
i
1s i s n.
iii) Let A
i
be a collection of sets one for each element i e I, where I is
some set (I may be the set of all positive integers). We define

I i
i
A
e
= {a / a e A
i
for all i e I}, and

I i
i
A
e
= {a / a e A
i
for some i e I}.
A collection {A
i
}
ie I
of sets is said to be mutually disjoint if
A
i
A
j
= | for all i e I, j e I such that i = j.
1.2.14 Examples
i) If X = {a, b} and Y = {x, y}, then
X Y = {(a, x), (a, y), (b, x), (b, y)} and Y X = {(x, a) (x, b), (y, a),
(y, b)}.
Note that X Y = Y X.
ii) If A = {a, b}, B = {2}, C = {x}, then A B C = {(a, 2, x), (b, 2, x))}.
iii) Let T = {a, b, c, d} and S = {1, 2, 4}. Then the (S T) (T S) is an
empty set.
iv) Write A
i
= {i, i+1, i+2, } for each i e N, the set of natural numbers.
Then it is easy to observe that

N i
i
A
e
= N and

I i
i
A
e
= |.
v) If B
i
= {2i, 2i +1} for all i e N, then {B
i
}
ieN
is a collection of mutually
disjoint sets.
1.2.15 Definition
Let A be a set. The set P(A) = the set of all subsets of A, is called the power
set of A.
Result: If the set A has n elements, then the number of elements in P(A) is
2
n
.
Theory of Computer Science Unit 1
Sikkim Manipal University Page No.: 7
Proof: Suppose A has n elements. Let m be an integer such that 0 s m s n.
We can select m elements from the given set A in
n
C
m
ways. So A contains
n
C
m
distinct subsets containing m elements. Therefore,
the number of elements in P(A)
= number of subsets containing 0 number of elements
+ number of subsets containing only 1 element
+ + number of subsets containing n elements
=
n
C
0
+
n
C
1
+
n
C
2
+ +
n
C
n
= 2
n
.
Self Assessment Questions
1. Let A = {a, b} and B = {x, y, z}. Then find A B, B A.
2. Let S = {2, 5, 2 , 25, t,
2
5
} and T = {4, 25, 2 , 6,
2
3
}
i) Find S T, S T and T (S T)
ii) Find Z S, Z S, Z T and Z T.
3. Find A
c
(with respect to the universal set of real numbers) in the
following cases
i) A
1
= (1, ) (-, -2)
ii) A
2
= (-3, ) (-, 5).
4. Let x and y be real numbers with x < y. Find (x, y)
c
, [x, y)
c
, (x, )
c
, and
(-, y]
c
.
5. Let S = {x, y, z, {x, y}}. Find (i) S \ {x, y}; (ii) S \ |; (iii) ({x, y, z} {S})
\ S; and (iv) S \ {{x, y}}.
6. Find the power set of S = {(x, y), Z }.

1.3 Functions and Relations
Relation describes connections between different elements of the same set,
where as functions describe connections between two different sets.
Functions give a mathematical precise framework for the intuitive idea of
transformation.
Theory of Computer Science Unit 1
Sikkim Manipal University Page No.: 8
1.3.1 Definitions
Let S and T be sets. A function f from S to T is a subset f of S T such that
i) for s e S, there exists t e T with (s, t) e f;
ii) (s, u) e f and (s, t) e f t = u.
If (s, t) e f, then we write (s, f(s)) or f(s) = t.
Here t is called the image of s; and s is called the preimage of t.
The set S is called the domain of f and T is called the codomain.
The set {f(s) / s e S } is a subset of T and it is called the image of S under f
(or image of f). We denote the fact f is a function from S toT by f : S T.
f: S T is said to be
1.3.2 One-one function (or injective function)
f(s
1
) = f(s
2
) s
1
= s
2
.
onto function (or surjective function): t e T there exists an element
s e S such that f(s) = t.
1.3.3 Bijection
if it is both one-one and onto.
Let g: S T and f : T U. The composition of f and g is a function
fog: S U defined by (fog)(s) = f(g(s)) for all s in S.
1.3.4 Definitions
A function f : S T is said to have an inverse if there exists a function g
from T to S such that (gof)(s) = s for all s in S and (fog)(t) = t for all t
in T. We call the function g the inverse of f. A function f : S S is said
to be an identity function if f(s) = s for all s in S. The identity function on S is
denoted by either I or I
S
. Inverse of a function f, if it exists, is denoted by f
-1
.
Two functions f : A B and g : C D are said to be equal if A = C,
B = D and f(a) = g(a) for all elements a in A = C. If two functions f
and g are equal, then we write f = g. The identity function is one-one
and onto. A function g is inverse of f fog and gof are identity functions. A
function f has an inverse f is one-one and onto.
Theory of Computer Science Unit 1
Sikkim Manipal University Page No.: 9
1.3.5 Example
Let the functions f and g defined by f(x) = 2x and g(x) = x + 5 for all x in R
(the set of real numbers). Then (fog)(1) = f(g(1)) = f(1 + 5) = f(6) = 12 and
(gof)(1) = g(f(1)) = g(2) = 2 + 5 = 7. This shows that the two functions are
not equal at 1 and so fog = gof.
1.3.6 Definition
Let A be a subset of the Universal set U = {x
1
, x
2
, , x
n
}. The characteristic
function of A is defined as a function from U to {0, 1} by the following:
f
A
(x
i
) =
i
i
1 if x A
0 if x A
e

. For example, if A = {2, 3, 7} and U = {1, 2, , 10},


then f
A
(1) = 0, f
A
(2) = 1, f
A
(3) = 1, f
A
(7) = 1. and f
A
(11) is undefined. It can be
verified that f
A
is everywhere defined and onto, but not one one.
1.3.7 Definition
A relation R between the sets A
1
, A
2
, , A
n
is a subset of A
1
A
2

A
n
. This relation R is called an n-ary relation.
(twoary is called binary, three-ary is called ternary). In general, a relation
means binary relation on a set S (means a subset of S S). A relation R
on S is said to be
- transitive if (a, b) e R, (b, c) e R implies (a, c) e R;
- reflexive if (a, a) e R for all a e S;
- anti-symmetric if (a, b) e R and (b, a) e R a = b;
- symmetric if (a, b) e R implies (b, a) e R;
Self Assessment Questions
7. Determine whether or not each of the binary relations defined on the
given sets S
i
(i = 1, 2, 3) is reflexive, symmetric, anti symmetric or
transitive. If a relation has a certain property, prove this is so;
otherwise, provide a counter example to show that it does not.
i) S
1
= {1, 2, 3, 4}; R
1
= {(1, 1), (1, 2), (2, 1), (3, 4)}
Theory of Computer Science Unit 1
Sikkim Manipal University Page No.: 10
ii) S
2
= Z , (a, b) e R
2
if and only if ab > 0.
iii) S
3
= R R, R
3
= {((x, y), (u, v)) / x + y s u + v}

1.4 Equivalence Relations
1.4.1 Definition
A relation is said to be an equivalence relation if it is reflexive, symmetric
and transitive.
If (a, b) is an element of the equivalence relation, then we write a ~ b and
we say that a and b are equivalent.
Let R be an equivalence relation on S and a is an element of S. Then the
set [a] = {s e S / s ~ a} is called the equivalence class of a (or equivalence
class containing a).
1.4.2 Example
If A ={a, b, c} and R = {(a, a), (b, b), (c, c), (a, b), (b, a)}, then R is an
equivalence relation on A and [a] = {a, b}, [b] = {a, b}, and [c] = {c}.
1.4.3 Example
i) Let S be the set of all integers. Define for any a, b e S, a ~ b a - b
is an even number. Then relation ~ is an equivalence relation.
ii) Let R, the set of all real numbers, x ~ y x y is an integer. Then ~
is an equivalence relation. The set of all equivalence classes are given
by
{[x] / x e (0, 1]}.
1.4.4 Example
For (x
1
,y
1
) and (x
2
,y
2
) in R
2
(Euclidean Plane), define (x
1
,y
1
) ~ (x
2
,y
2
) if and
only if x
1
2
+ y
1
2
= x
2
2
+ y
2
2
. Then ~ is an equivalence relation on R
2
.
1.4.5 Definition
Let n > 0 be a fixed integer. We define a relation namely Congruence
Theory of Computer Science Unit 1
Sikkim Manipal University Page No.: 11
modulo n on Z, the set of integers as :
a b mod n n divides (a - b).
Some times we write a b as a ~ b. and we read as a ~ b mod n as a is
congruent to b modulo n.
1.4.6 Problem
The relation a b mod n defined above is an equivalence relation on Z.
Solution: Let a e Z.
Reflexive: Since n divides a - a = 0, we have a a mod n.
Symmetric: Let a b mod n.
n divides a - b
n divides - (a - b)
n divides b - a
b a mod n.
Transitivity: Let a, b, c eZ such that a b mod n, b c mod n.
n divides a - b, and n divides b - c
n divides ( a - b ) + ( b - c)
n divides a - c
a c mod n.
Hence the relation is an equivalence relation.
1.4.7 Example
Suppose n = 5. Then
[0] = {x / x 0 mod 5} = {x / 5 divides x - 0 = x} = {, -10, -5, 0, 5, 10, }
[1] = {x / x 1 mod 5} = {x / 5 divides x - 1} = {, -9, -4, 1, 6, }
[2] = { x / x 2 mod 5} = {x / 5 divides x -2} = {, -8, -3, 2, 7, 12, }
[3] = {x / x 3 mod 5} = { x / 5 divides x -3} = {, -7, -2, 3, 8, 13, }
[4] = { x / x 4 mod 5} = { x / 5 divides x - 4} = {, -6, -1, 4, 9, 14, }
Also it is clear that [0] = [5] = [10] =
Theory of Computer Science Unit 1
Sikkim Manipal University Page No.: 12
[1] = [6] = [11] =
[2] = [7] = [12] =
[3] = [8] = [13] =
[4] = [9] = [14] =
Therefore the set of equivalence classes is given by {[0], [1], [2], [3], [4]}.
1.4.8 Definition
A partition of a set S is a set of subsets {S
i
/ | = S
i
_ S and i e I where I is
some index set} satisfying

I i
i
S
e
= S and S
i
S
j
= | if i = j.
1.4.9 Example
i) Write A = {1, 2, 3, 4, 5, a, b, c}, S
1
= {1, 2}, S
2
= {3}, S
3
= {4, 5, a} and
S
4
= {b, c}. Then S
1
, S
2
, S
3
, S
4
form a partition for A.
ii) Consider R, the set of all real numbers. The collection
{(a, b) / a, b e Z and b = a + 1} of subsets of R, forms a partition for R.
1.4.10 Lemma
If R is an equivalence relation on a set S and a, b e S, then either
[a] = [b] or [a] [b] = |.
Proof: If [a] [b] = |, then it is clear.
Now suppose the intersection is non-empty.
Let x e [a] [b]
x e [a] and x e [b]
x ~ a and x ~ b
a ~ x and x ~ b (since ~ is symmetric)
a ~ b (since ~ is transitive).
Now we show that [a] = [b]. For this, let y e [a] y ~ a.
Since a ~ b, we get y ~ b (by transitive property) b ~ y y e [b].
Hence [a] _ [b]. Similarly, we get that [b] _ [a]. Therefore [a] = [b].

Theory of Computer Science Unit 1
Sikkim Manipal University Page No.: 13
From this lemma, we can conclude that any two equivalence classes are
either equal or disjoint.
1.4.11 Problem
Let A be a set and ~ an equivalence relation on A. Then the set of all
equivalence classes forms a partition for A.
Solution:
The collection of all equivalence classes is {[a] / a e A}.
Since each [a] _ A, we have that

A a
] a [
e
_ A.
Now let x e A. It is clear that x e [x] _

A a
] a [
e
.
Therefore we have that
A =

A a
] a [
e
.
By the lemma 1.4.11, we know that either [a] = [b] or [a] [b] = | for any
a, b e A.
Hence the set of all equivalence classes forms a partition.
Observation: Let A be a set and { A
i
/ i e I} be a collection of nonempty
subsets of A, which forms a partition for A. Then there exists an equivalence
relation ~ on A such that the equivalence classes are nothing but the sets of
the partition.
Self Assessment Questions
8. Whether R = {(1, 1), (1, 2), (3, 2), (3, 3), (2, 3), (2, 1)} is an equivalence
relation on S = {1, 2, 3}?
9. For x, y e R \{0}, define x ~ y
y
x
e Q. Whether or not, ~ is an
equivalence relation.

10. Let A = {x e Z
+
/ 1 s x s 10}. State whether or not each of the following
Theory of Computer Science Unit 1
Sikkim Manipal University Page No.: 14
families of sets is a partition of A.
i) {{1, 3, 5}, {4, 7, 9}, {2, 6, 10}}; (ii) {{1, 3, 5, 7}, {2, 4, 6}, {3, 8, 9,
10}};
ii) {{1, 2, 3}, {5, 8, 9}, {4, 6, 7, 10}}.
11. If |S| = n, then how many relations are there from S to S.
12. Give an example of a relation that is both symmetric and anti
symmetric.
13. Let S = Z \ {0} and define R on S by (a, b) R (c, d) ad = bc. Is R
an equivalence relation? If so find the equivalence class containing
(1, 2).

1.5 Recursive Functions
Recursion is the technique of defining a function, a set or an algorithm in
terms of itself. That is, the definition will be in terms of previous values.
1.5.1 Definition
A function f: N N, where N is the set of non-negative integers is defined
recursively if the value of f at 0 is given and for each positive integer n, the
value of f at n is defined in terms of the values of f at k, where 0 k < n.
Observation: f defined (above) may not be a function. Hence, when a
function is defined recursively it is necessary to verify that the function is
well defined.
1.5.2 Example
The sequence 1, 4, 16, 64, ... , can be defined explicitly by the formula
f(n) = 4
n
for all integers n > 0.
The same function can also be defined recursively as follows:
f(0) = 1, f(n + 1) = 4f(n), for n > 0
To prove that the function is well defined we have to prove existence and
uniqueness of such function. In this case, existence is clear as f(n) = 4
n
.
Theory of Computer Science Unit 1
Sikkim Manipal University Page No.: 15
1.5.3 Theorem: (Recursion Theorem):
Let F is a given function from a set S into S. Let s
0
be fixed element of S.
Then there exists a unique function f: N N where N is the set of non-
negative integers satisfying
i) f(0) = s
0

ii) f(n + 1) = F(f(n)) for all integers n e N.
(Here the condition (i) is called initial condition and (ii) is called the
recurrence relation).
1.5.4 Example
Define n! recursively and compute 5! recursively.
Solution: We have f: N N. Then
i) f(0) = 1
ii) f(n + 1) = (n + 1)f(n) for all n > 0.
Clearly f(n) = n!.
Now we compute 5! recursively as follows:
5! = 5. 4!
= 5. 4. 3!
= 5. 4. 3. 2!
= 5. 4. 3. 2. 1!
= 5. 4. 3. 2. 1. 0!
= 5. 4. 3. 2. 1. 1
= 120.
1.5.5 Note
Any sequence in arithmetic progression or geometric progression can be
defined recursively. Consider the sequence a, a + d, a + 2d, . Then
A(0) = a, A(n + 1) = A(n) + d.
Consider another sequence a, ar, ar
2
, . Then
G(0) = a, G(n +1) = r G(n).
Theory of Computer Science Unit 1
Sikkim Manipal University Page No.: 16
1.5.6 Definition
The Fibonacci sequence can be defined recursively as
i) F
0
= 1 = F
1

ii) F
n+1
= F
n
+ F
n-1
for n > 1.
Then
F
2
= F
1
+ F
0
= 2
F
3
= F
2
+ F
1
= 3
F
4
= F
3
+ F
2
= 5
..
Here, there are two initial conditions.
1.5.7 Example:
Define
f(x) =
when x is even
2
1
when x is odd
2
x
x


Solution: Define f: N N such that f(0) = 0 and f(x + 1) = x f(x).
Then f(6) = 5 f(5) = 5 [4 f(4)]
= 5 4 + [3 (3)]
= 5 4 + 3 2 + [1 f(1)]
= 5 4 + 3 2 +1 [0 f(0)]
= 3.
and f(5) = 4 f(4)
= 4 [3 - f(3)]
= 4 3 + 2 - [1-f(1)]
= f 3 + 2 -1 + [0 f(0)]
= 2.

Theory of Computer Science Unit 1
Sikkim Manipal University Page No.: 17
1.5.8 Example
Using recursion theorem, verify that the object defined by the recursive
definition is a function. That is.
i) g(0) = 1
ii) g(n + 1) = 3[g(n)]
2
+ 7 for all n > 0
Solution: We obtain
i) s
0
= 1
ii) f(k) = 3k
2
+ 7, where f: N N
Then g(0) = s
0
. And g(n +1) f(g(n)). Thus g is a well-defined function.
The following is an example of a recursive function that does not define a
function.
1.5.9 Example
Consider a recursion function g: Z
+
(the set of positive integers) Z (the set
of integers), for all integers n > 1.
Solution: Suppose g is a function. Then by definition of g,
g(1) = 1
g(2) = 1 + g(1) = 1 + 1 = 2.
g(3) = g(8) = 1 + g(4) = 1 + (1 + g(2)) = 1 + (1 + 2) = 4.
g(4) = 1 + g(2) = 1 + 2 = 3.
Now, g(5) = g(14) = 1 = g(7) = 1 + g(20)
= 1 + (1 + g(10))
= 1 + 1(1 + (1 + g(5)))
= 3 + g(5).
Subtracting g(5) we get 0 = 3. Therefore g is not well defined.
1.5.10 Definition
If m and n are two non-negative integers then the (greatest common divisor)
g.c.d. (m, n) is defined as the largest positive integer d such that d divides
Theory of Computer Science Unit 1
Sikkim Manipal University Page No.: 18
both m and n. Euclidean algorithm computes the greatest common divisor
(g.c.d.) of two non-negative integers.
We can find g.c.d. (m, n) recursively as follows:
g.c.d. (n, m) if n > m
. . . (m, n) = m if n = 0
g.c.d. (n, mod (m, n)) Otherwise
g c d


where mod (m, n) is the remainder obtained when m is divided by n.
Observations:
- The first part interchanges the order of m and n if n > m.
- Second part is the initial condition.
- Third part is the recursive part mod (m, n) will become 0 in a finite
number of steps.
1.5.11 The recursive functions of more than one variable
i) Define f(x, y) = x + y recursively.
Here, we keep x fixed and use recursion on y. We define
i) f(x, 0) = x
ii) f(x, y + 1) = f(x, y) + 1.
Take x = 2, y = 3. Now f(2, 3) = f(2, 2) + 1
= f(2, 1) + 1 + 1
= f(2, 0) + 1 + 1 +1
= 2 + 1 + 1 +1
= 5.
ii) Define g(x, 0) = 0, g(x, y + 1) = g(x, y) + x. Take x = 3, y = 4. Then
g(3, 4) = g(3, 3) + 3
= g(3, 2) + 3 + 3
= g(3, 1) + 3 + 3 + 3
= g(3, 0) + 3 + 3 + 3 + 3 = 12 (since g(3, 0) = 0).

Theory of Computer Science Unit 1
Sikkim Manipal University Page No.: 19
Self Assessment Questions
14. The g.c.d. (20, 6) of _______
15. The g.c.d. (81, 36) of ________
16. The g.c.d. (22, 8) of _______

1.6 Strings and Growth Functions
Let us see the simple example, to understand this.
Bhanu is running a successful business and is planning a short vacation trip.
She is planning to take a cell phone with her so that in the case of an
emergency, the manager at work can reach her. To budget her calls, we
looks at various plans and chooses the pan that charges US $ 1.00 for the
connection charge and US $ 10 for each minute. For example, the charges
for a one minute call are US $ 1.10, the charges for a two minute call are US
$ 1.20 and so on. So Bhanu makes the following table for the first ten
minutes of telephone charges.
Min 1 2 3 4 5 6 7 8 9 10
Charges 1.10 1.20 1.30 1.40 1.50 1.60 1.70 1.80 1.90 2.00
From the table we see that for a 30 min call, the charges are 1.00 + 30(0.10)
= 4.00.
In general, for an n-minute call, the charges are
1.00 + n(0.10) = 1.00 + 0.10 n.
Let us list the telephone charges as follows.
1.10, 1.20, 1.30, , (1.00 + 0.1 n),
This is an ordered list of real numbers in which the first element is 1.10, the
second element is 1.20, and so on. Such an ordered list of elements is
called a sequence. If the sequence stops after n elements for some positive
integer n, then it is called finite otherwise it is called infinite sequence.

Theory of Computer Science Unit 1
Sikkim Manipal University Page No.: 20
Define a function f: N (natural numbers) R (real numbers) as f(n) = 1.00 +
(0.1)n.
Then f(1) = 1.00 + (0.1)1 = 1.10 = c
1

f(2) = 1.00 + (0.1)2 = 1.20 = c
2


f(n) = 1.00 + (0.1)n = c
n
.
1.6.1 Definition
An infinite sequence or a sequence, on a non empty set X is a function from
the set of positive integers N to X. A sequence whose terms are integers is
called an integer sequence.
1.6.2 Example
Let f: N Z be a function defined by f(n) = n
2
. Then f(1) = 1, f(2) = 2
2
= 4,
and so we get a sequence 1, 4, 9, , n
2
, is a sequence on A. Let a
n

denote the n
th
term of this sequence. Then a
1
= 1, a
2
= 4, , and so on. We
denote this sequence by

=1
2
} {
n
n or simply by {n
2
}.
1.6.3 Definition
Let

=1 n n
} a { be a sequence. Consider the following terms of this sequence:
a
m
, a
m+1
, , a
n
.
Some of the common things we do with these terms are adding them and
multiplying them. Let us first consider the addition.
The sum of the terms a
m
, a
m+1
, , a
n
is written as

=
n
m i
i
a . There is nothing about the choice of the variable i. We could choose
j or k as the index of the summation and write as the sum as

=
n
m j
j
a
or

=
n
m k
k
a .
Theory of Computer Science Unit 1
Sikkim Manipal University Page No.: 21
1.6.4 Example
i)

=
4
1 i
i = 1 + 2 + 3 + 4 = 10.
ii)

=
+
3
1 i
1 i
i
= + 2/3 + = 23/12.
1.6.5 Example
Consider the sums

=
+
3
1
) 1 (
i
i and

=
4
2 i
j

=
+
3
1 i
) 1 i ( = (1+1) + (2 + 1) + (3 +1) = 9.

=
4
2 i
j = 2 + 3 + 4 = 9.
Therefore

=
+
3
1 i
) 1 i ( =

=
4
2 i
j
1.6.6 Note
To change the index variable in a sum we do the following.
1. Calculate the lower limit of the new index variable.
2. Calculate the upper limit of the new index variable.
3. Find the general term of the summation in terms of the new index
variable.
1.6.7 Example
Consider the sum

=
+
3
1 i
) 1 i ( and change the index variable to j = i + 1.

Theory of Computer Science Unit 1
Sikkim Manipal University Page No.: 22
Solution: Step (i): Lower limit for j: The lower limit for i is 1, so the lower
limit for j is j = i + 1 = 1 + 1 = 2.
Step (ii): Upper limit for j: The upper limit for i is 3, so the upper limit for j is j
= i + 1 = 3 + 1 = 4.
Step (iii): The general term is i + 1 = j.
Hence, the equivalent sum is

=
4
2 j
j .
1.6.8 Example
Consider the sum

=
+ +
1 n
0 i
2
) i 1 n ( , change the index variable to j = i + 1.
Solution:
Step (i): Lower limit for j = i + 1 = 0 + 1 = 1.
Step (ii): Upper limit for j = i + 1 = n 1 + 1 = n.
Step (iii): The general term for the new summation is given by
n
2
+ 1 + i = n
2
+ j.
Hence, the new sum is

=
+
n
1 j
2
) j n ( .
1.6.9 Properties of Summation
Let

=1 n n
} a { and

=1 n n
} b { be sequences of real numbers and let c be a real
number. Suppose m and n are integers such that 1 m n. Then
(i)

=
n
m i
i
a +

=
n
m i
i
b = ) b a (
n
m i
i i
=
+ ,
(ii) c.

=
n
m i
i
a =

=
n
m i
i
ca .
Theory of Computer Science Unit 1
Sikkim Manipal University Page No.: 23
1.6.10 Definition
Let A be a nonempty finite set. A string or word, over A is a finite sequence
of elements from A. The set A is called an alphabet.
A string with no element in it is called the empty string or empty word.
If s
1
and s
2
are two strings over a set A, then the concatenation of s
1
and s
2

is the string s
1
s
2
. That is, to obtain the concatenation of s
1
and s
2
we list the
elements of s
1
followed by the elements of s
2
.
1.6.11 Example
Suppose s
1
= abbabcdb and s
2
= caabcdbbd are two strings over the set
A = {a, b, c, d}. Then the concatenation of s
1
and s
2
is s
1
s
2

= abbabcdbcaabcdbbd.
It follows that if s
1
and s
2
are strings over a set A, then s
1
s
2
= s
1
+ s
2
.
1.6.12 Example
Let A = {0, 1}.
i) Let s = 01101010. Then s is a string over A and s = 8.
ii) 00, 01, 10, 11 are only strings of length 2 over A.
iii) If s
1
= 1001010 and s
2
= 00111 then s
1
s
2
= 100101000111. Also s
1
=
7, s
2
= 5, and s
1
s
2
= 12 = s
1
+ s
2
.
1.6.13 Growth Functions
The growth of a function is often described using a special notation,
O-notation (read as big-oh notation). It provides a special way to compare
relative sizes of functions that is very useful in the analysis of computer
algorithms. It often happens that the time or memory space requirements
for the algorithms available to do a certain job differ from each other on such
a grand scale that differences of just a constant factor are completely
overshadowed. The O-notation makes use of approximations that highlight
these large-scale differences while ignoring differences of a constant factor
and differences that only occur for small sets of input data.
Theory of Computer Science Unit 1
Sikkim Manipal University Page No.: 24
1.6.14 Definition
Let f and g be functions from the set of integers or the set of real numbers to
the set of real numbers. Then f of order g written as f(x) is O(g(x)), if there
are constants C and k such that f(x) C g(x) whenever x > k (this is read
as f(x) is big-oh of g(x)).
1.6.15 Remark
To show f(x) is O(g(x)), we need only find one pair of constants C and k
such that f(x) < C(g(x)) if x > k. However, a pair C, k that satisfies the
definition is not unique. Moreover, if one such pair exists, there are infinitely
many such pairs. A simple way to see this is to note that if C, k is one such
pair, any pair C
1
, k
1
with C < C
1
and k < k
1
also satisfies the definition, since
f (x) < C
1
g(x) whenever x > k
1
> k.
1.6.16 Example
Use O-notation to express 3x
3
+ 2x + 7 12 x
3
, for all real numbers
x > 1.
Solution: Take C = 12 and k = 1, the given statement translates to
2x
3
+ 2x + 7 is O(x
3
).
1.6.17 Note: Order of Polynomial functions
i) If 1 < x then x < x
2
and so x
2
< x
3
. Thus, if 1 < x, then 1 < x < x
2
< x
3
.
ii) For any rational numbers r and s, if x > 1 and r < s, then x
r
< x
s
.
Therefore x
s
is O(x
s
).
1.6.18 Example
Show that for any real number x > 1, 2x
4
+ 4x
3
+ 5 11x
4
.
Solution: Since x is a real number and x > 1, we have
x
3
< x
4
and 1 < x
4
. So
4x
3
< 4x
4
and 5 < 5x
4
.
Adding we obtain, 2x
4
+ 4x
3
+ 5 2x
4
+ 4x
4
+ 5x
4
= 11x
4
.
Theory of Computer Science Unit 1
Sikkim Manipal University Page No.: 25
1.6.19 Example
Use the definition of order to show that 5x
3
3x + 4 is O(x
3
).
Solution
The functions f and g referred to in the definition of O-notation are defined
as follows.
For all real numbers x, f(x) = 5x
3
3x + 4 and g(x) = x
3
.
For all real numbers x > 1,
5x
3
3x + 4 5x
3
+ 3x + 4 (by the triangle inequality)
5x
3
+ 3x + 4
5x
3
+ 3x
3
+ 4x
3

12x
3
12 x
3
.
Therefore, f(x) 12 g(x) for all x > 1
Or f(x) C g(x) for all x > k where C = 12 and k = 1.
Hence, 5x
3
3x + 4 is O(x
3
).
1.6.20 Example
Show that 9x
2
is O(x
3
). Is it true that x
3
is O(9x
2
)?
Solution: We note that 9x
2
< x
3
is true whenever x > 9 (by dividing both
sides by x
2
). Hence, 9x
2
is O(x
3
), taking C = 1 and k = 9 in the definition of
big-oh notation.
To determine whether x
3
is O(9x
2
) or not , it is necessary to determine
whether there are constants C and k such that x
3
C (9x
2
) whenever x > k.
This is equivalent to the inequality x < 9C (we get this dividing both sides by x
2
).
No such x can exist since x can be marked arbitrarily large. Hence, x
3
is not
O(9x
2
).
Now we generalize above example, to show that any polynomial function is
big oh of the power function of its highest order term or of any larger power
function.
Theory of Computer Science Unit 1
Sikkim Manipal University Page No.: 26
1.6.21 Theorem
Let f(x) = a
n
x
n
+ a
n-1
x
n-1
+ + a
1
x + a
0
where a
0
, a
1
, , a
n-1
, a
n
are real
numbers then f(x) is O(x
n
).
Proof: Using the triangle inequality, if x > 1, we have that
f(x) = a
n
x
n
+ a
n-1
x
n-1
+ + a
1
x + a
0

a
n
x
n
+ a
n-1
x
n-1
+ + a
1


x + a
0

x
n
(

a
n
+ a
n-1
/ x + + a
1
/ x
n-1
+ a
0
/x
n
)
x
n
(

a
n
+ a
n-1
+ + a
1
+ a
0
) (since x > 1).
This shows that
f(x) C x
n
where
C =

a
n
+ a
n-1
+ + a
1
+ a
0
, whenever x > 1.
Hence, f(x) is O(x
n
).
1.6.22 Example
Use big-oh notation to estimate the sum of the first n positive integers?
Solution: Each positive integer n is greater than every positive integer that
precedes it. Therefore, for each positive integer n,
1 + 2 + 3 + + n

times n
n n n

+ + + ... = n n = n
2
.
Therefore, 1 + 2 + 3 + + n is O(n
2
).
Observation: big O-estimates will be developed for the factorial function
and its logarithm. These estimates will be important in the analysis of the
number of steps used in sorting procedures.
1.6.23 Example
Give big-O estimates for the factorial function and the logarithm of the
factorial function, where the factorial function f(n) = n ! = 1 2 3 n
where n is a positive integer, and 0 ! = 1.
For example, 1! = 1, 2! = 2, 3! = 6, 4! = 24.
Theory of Computer Science Unit 1
Sikkim Manipal University Page No.: 27
Note that the function n! grows rapidly.
20 ! = 2, 432, 902, 008, 176, 640, 000.
Solution: A big-O estimate for n ! can be obtained by noting that each term
in the product does not exceed n. Hence,
n ! = 1 2 n n n n = n
n
.
This inequality shows that n ! is O(n
n
), taking C = 1 and k = 1.
Taking logarithm both sides, we get
log n! log n
n
= n log n.
This shows that log n! is O(n log n), again taking C = 1 and k =1.
1.6.24 Theorem
- Suppose that f
1
(x) is O(g
1
(x)) and f
2
(x) is O(g
2
(x)). Then (f
1
+ f
2
) (x) is
O(max (g
1
(x), g
2
(x))).
- Suppose that f
1
(x) and f
2
(x) are both O(g(x)). Then (f
1
+ f
2
)(x) is O(g(x)).
- Suppose that f
1
(x) is O(g
1
(x)) and f
2
(x) is O(g
2
(x)). Then (f
1
f
2
)(x) is
O(max (g
1
(x)g
2
(x)).
1.6.25 Example
Give a big O-estimate for f(n) = 3n log(n!) + (n
2
+ 3) log n, where n is a
positive integer.
Solution: First we estimate the product 3n log (n!). From the example, we
log n! is O(n log n). Also 3n is O(n).
Using these two estimates, and the theorem, we can estimate that 3n log (n!) is
O(n
2
log n).
Next the product (n
2
+ 3) log n will be estimated.
(n
2
+ 3) 2n
2
when n > 2, it follows that n
2
+ 3 is O(n
2
).
Therefore (n
2
+3)log n is O(n
2
log n). Using theorem, to combine the two
big O-estimates for the products shows that
f(n) = 3nlog (n!) + (n
2
+ 3)log n is O(n
2
log n).
Theory of Computer Science Unit 1
Sikkim Manipal University Page No.: 28
1.6.26 Example
Give a big O estimate for f(x) = (x + 1)log(x
2
+ 1) + 3x
2
.
Solution: A big-O estimate for (x + 1) is O(x).
When x > 1, x
2
+ 1 2x
2
. Therefore,
log (x
2
+ 1)
log(2x
2
)
= log 2 + log x
2
= log 2 + 2 log x
3 log x, if x > 2.
Therefore
log(x
2
+ 1) is O(log x).
By theorem, it follows that (x + 1)log(x
2
+ 1) is O(x logx).
Further, 3x
2
is O(x
2
), by theorem, f(x) is O(max (x logx, x
2
)).
Since x log x x
2
, for x > 1, it follows that f(x) is O(x
2
).
1.6.27 Big-Omega and Big-Theta Notations
If f(x) is O(g(x)), all that one can conclude that except for constants and a
finite number of exceptions, f is bounded above by g, so g grows at least as
fast as f. For example, if f(x) = x and g(x) = 2x, then f(x) is O(g(x)), but g
grows considerable faster than f. The statement f(x) is O g(x) says nothing
about lower bound for f. For this, we use big-Omega notation. When we
want to give both upper and a lower bound on the size of a function f(x)
relative to a reference function g(x), we use big-Theta notation.
1.6.28 Definition
Let f and g be functions from the set of integers or the set of real numbers to
the set of real numbers. We say that f(x) is O(g(x)), if there are positive
constants C and k such that f(x) > C g(x) whenever x > k which is read
as f(x) is big-Omega g(x).

Theory of Computer Science Unit 1
Sikkim Manipal University Page No.: 29
Let f and g be functions from the set of integers or the set of real numbers to
the set of real numbers. We say that f(x) is u g(x) if f(x) is O(g(x)) and f(x) is
Og(x). When f(x) is u g(x), we say that f is big-Theta of g(x) and we say
f(x) is of order g(x).
Therefore, f(x) is O(g(x)), then f(x) is an upper bound for f(x) and whenever
f(x) is g(x), g(x) is a lower bound for f(x). The big-O notation compares the
rate of growth of functions rather than their values, so when f(x) is u g(x), f(x)
and g(x) have the same rates of growth, but can be very different in their
values.
1.6.29 Example
Let f(x) = x and g(x) = 1, 000, 000x, then f(x) C g(x) for C = 1 and k = 1, so
that f(x) is O(g(x)). Also Cf(x) > g(x) for C = 1, 000, 000 and k = 1, so f(x) is
O(g(x)). Therefore f(x) is u g(x).

Self Assessment Questions
17. Use the definition of order to show that x
2
+ 2x + 1 is O(x
2
).

1.7 Summary
In this unit we introduced the basic concept sets and the different properties
of sets. Some properties common to operations on sets, cartesian product
of sets were studied as relations between two sets. We also discussed the
equivalence relations with a few illustrations. The reader can easily apply
the mathematical concepts introduced, in various situations. In the last
section we studied the strings and growth functions which are very useful in
time complexity of algorithms.



Theory of Computer Science Unit 1
Sikkim Manipal University Page No.: 30
1.8 Terminal Questions
1. Explain Equivalence relation and give examples.
2. Explain growth functions and give examples.
3. Define recursive function and give examples.
4. Explain Big Omega and Big theta functions.

1.9 Answers
Self Assessment Questions
1. A B = {(a, x), (a, y), (a, z), (b, x), (b, y), (b, z)}, and
B A = {(x, a), (x, b), (y, a), (y, b), (z, a), (z, b)}. This problem illustrates
that, in general, the sets A B and B A are different.
2. i) S T = { 2 , 25}, S T = {2, 5, 2 , 25, t,
2
5
, 4, 6,
2
3
},
T (S T) = {(4, 2 ), (4, 25), (25, 2 ), (25, 25), ( 2 , 2 ), ( 2 ,
25), (6, 2 ), (6, 25), (
2
3
, 2 ), (
2
3
, 25)}.
ii) Z S = { 2 , t,
2
5
, 0, 1, -1, 2, -2, . }, Z S = {2, 5, 25}
Z T = { 2 ,
2
3
, 0, 1, -1, 2, -2, .}, Z T = {4, 25, 6}.
3. i)
c
1
A = [-2, 1]; (ii).
c
2
A = (- , 3] [5, ).
4. (x, y)
c
= (-, x] [y, ); [x, y)
c
= (-, a) [y, ); (x, )
c
= (-, x]; and (-,
y]
c
= (y, )
5. (i) {z, {x, y}}, (ii). S (iii). {x, y, z}, and (iv).{x, y, z}.
6. P (S) = the power set of S = {|, S, {(a, b)}, {c}}.
7. i) Not reflexive as (2, 2) e R
1
.
Not symmetric as (3, 4) e R
1
but (4, 3) e R
1

Not anti symmetric as (1, 2), (2,1) e R
1
, but 1 = 2
Not transitive as (2, 1), (1, 2) e R
1
but (2, 2) e R
1
.

Theory of Computer Science Unit 1
Sikkim Manipal University Page No.: 31
ii) Reflexive: For any a e S
2
, a
2
> 0 and so (a, a) e R
2

Symmetric: If (a, b) e R
2
, then ab > 0, so ba > 0 and hence (b, a)e R
2
.
Not Anti symmetric: (5, 2) e R
2
, since 5(2) = 10 > 0 and similarly
(2, 5) e R
2
, but 5 = 2.
Not transitive: (5, 0) e R
2
, (0, -6) e R
2
but (5, -6) e R
2
, since
5(-6) />0.
iii) Reflexive:
Not symmetric: ((1, 2), (3, 4)) e R
3
, but ((3, 4), (1, 2)) e R, since
3 + 4 / s 1 + 2.
Not anti symmetric: ((1, 2), (0, 3)) e R
3
, ((0, 3), (1, 2)) e R
3
but
(1, 2) = (0, 3).
Transitive:
8. No: Since R is not reflexive as (2, 2) e R.
9. Yes
10. (i) No; (ii) No; (iii)Yes.
11. 2
n
.
12. The relation R defined by xRy x = y. That is., the identity relation,
is both symmetric as well as anti symmetric.
13. Yes. [(1, 2)] = {(1, 2), (-1, -2), (2, 4), (-2, -4), }.
14. g.c.d. (20, 6) = g.c.d. (6, mod (20, 6)) (since 20 = 6 3 + 2)
= g.c.d. (6, 2)
= (2, mod (6, 2))
= g.c.d. (2, 0)
= 2.
15. g.c.d. (81, 36) = g.c.d. (36, 9)
= g.c.d. (9, 0)
= 9.
Theory of Computer Science Unit 1
Sikkim Manipal University Page No.: 32
16. g.c.d. (22, 8) = g.c.d. (8, mod (22, 8))
= g.c.d. (8, 6)
= g.c.d. (6, mod (8, 6))
= g.c.d. (6, 2)
= g.c.d. (2, 0)
= 2.
17 The functions f and g referred to in the definition of O-notation are
defined as follows. For all real numbers x, f(x) = x
2
+ 2x

+ 1 and
g(x) = x
2
.
For all real numbers x > 1, x
2
+ 2x + 1 = x
2
+ 2x + 1
x
2
+ 2x
2
+ x
2

4x
2

4 x
2
.
Therefore,
f(x) 4 g(x) for all x > 1.
Or f(x) C g(x) for all x > k where C = 4 and k = 1.
Hence, x
2
+ 2x + 1 is O(x
2
).

You might also like