Unit 10 - Mathematical Functions and Notations
Unit 10 - Mathematical Functions and Notations
10.1 Introduction
You know that number of mathematical and statistical tools, techniques and
notations form an essential part in the concept of analysis of algorithms. In
this unit, we will study a number of well known approximation functions.
These functions will calculate approximate values of quantities, and these
quantities are useful in many situations and among these some of the
quantities are calculated just for comparison with each other.
Objectives:
After studying this unit, you should be able to:
use various Mathematical Notations like , , , , mod, log, e etc.
apply concepts of Mathematical Expectation in Algorithms
use of principle of Mathematical Induction in establishing truth of
infinitely many Statements
analyze the efficiency of an Algorithm
is denoted as i
a
The expression a1 a2 …. x ai ….. an
i 1
Function
For two given sets A and B (which need not be different , i.e., A may be the
same as B) a rule f which associates with each element of A, a unique
element of B, is called a function from A to B. If f is a function from a set A to
a set B, then we denote it by f: A B. Also, for x A, f(x) is called image of
x in B. Then, A is called the domain of f and B is called the co domain of f.
Example:
Let f: I I be defined such that f(x) = x2 for all x I then
f maps 4 to 16
f maps 0 to 0
f maps 5 to 25
Remark
We may note the following:
i) If f: x y is a function, then there may be more than one element, say
x1 and x2 such that f(x1) = f(x2)
In the above example
f(2) = f(–2) = 4
By putting restriction that f(x) f(y) if x y, we get special functions,
called 1 – 1 or injective functions.
ii) Though for each element x X, there must be at least one element
y Y, such that f(x) = y. However it is not necessary that for each
element y Y there must be at least one element x X, such that
f(x) = y, For example, for y = – 3 Y there is no x X such that
f(x) = x2 = –3. By putting the restriction on the function f, such that for
each y Y, there must be at least one element x of X such that f(x) = y,
we get special functions called onto or surjective functions.
f(x) f(y)
In other words, as x increases, value of its image decreases.
Further, f is said to be strictly monotonically decreasing, if x < y then
f(x) > f(y).
Example:
Let f: R R be defined as
f(x) = – x + 3
If x1 x2 then –x1 –x2 implying – x1 + 3 –x2 + 3 which further implies
that f(x1) f(x2) hence, f is monotonically decreasing.
b
b n
b(mod n) = n
given by n = n. n – 1 = n factorial (n – 1)
Exponentiation Function (Exp): is a function of two variables x and n
where x is any non – negative real number and n is an integer (though n can
be taken as non integer also, but we restrict to integers only)
Exp (x n) denoted by xn, is defined recursively as follows:
For n = 0
Exp (x, 0) = x0 = 1
For n > 0
Exp (x, n) = x. Exp (x, n – 1)
i.e.,
xn = x . xn–1
For n < 0, let n = –m where m > 0
1
x n x m
xm
1 1
Exp (1.5, – 3) = (1.5) = 1.5
–3 3 3.375
Further, the following rules apply to exponential function.
b b
m n mn
b b
m n n m
b m .b n b m n
Each of ai n i is called a term.
Generally, the suffix k in Pk (n) is dropped and instead of Pk(n) we write P(n)
only.
The result, in non – mathematical terms, states that for any given constants
b and c, but with
1c 2 c 3 c kc
, , ,....., ,........
b > 1, the terms in sequence b1 b 2 b 3 bk
gradually decrease and approaches zero. Which further means that for
constants b and c, and integer variable n, the exponential term bn, for b > 1,
increases at a much faster rate than the polynomial term nc.
Exponential Function: The letter e is used to denote the quantity
1 1 1
1 ......
1! 2 ! 3 !
and is taken as the base of natural logarithm function, then for all real
numbers x, we define the exponential function
x2 x3 xi
ex 1 x
2! 3!
......... i!
i 0
For all real numbers, we have
Further, if | x | 1 then 1 x e 1 x x
x 2
ii)
loga b n n loga b
1
iii) log a b log a b
1
iv) log a b log a
b
v) a log b c c log b a
Example: Suppose, the students of MCA, who completed all the courses in
the year 2005, had the following distribution of marks:
Percentage of students who
Range of marks
scored in the range
0% to 20% 08
20% to 40% 20
40% to 60% 57
60% to 80% 09
80% to 100% 06
Percentage of students
% marks
scoring the marks
10* 08
30 20
50 57
70 09
90 06
8
Thus, we assign weight 100 to the score 10% ( 8, out of 100 students
20
score on the average 10% marks); 100 to the score 30% and so on.
Thus,
Expected % of marks
8 20 57 9 6
10 30 50 70 90 47
100 100 100 100 100
The final calculation of expected marks of 47 is roughly equal to our intuition
of the expected marks, according to our intuition, to be around 50.
We generalize and formalize these ideas in the form of the following
definition.
Mathematical Expectation
For a given set S of items, let to each item, one of the n values, say
v1, v2 ….., vn, be associated. Let the probability of occurrence of an item with
value vi be pi. If an item is picked up at random, then its expected value E(v)
is given by
n
E( v ) pi v i p1v1 p2 v 2 ..... pn v n
i 1
the same algorithm for multiplying, say, two 100 x 100 matrices. This
explains intuitively the notion of the size and instances of a problem and
also the role of size in determining the (time) complexity of algorithm. If the
size of general instance is n then time complexity of the algorithm solving
the problem under consideration is some function of n.
However, for all types of problems, this does not serve properly the purpose
for which the notion of size is taken into consideration. Hence, different
measures of size of an instance of a problem are used for different types of
problem. For example,
i) In sorting and searching problems, the number of elements, which are to
be sorted or are considered for searching, is taken as the size of the
instance of the problem of sorting/ searching.
ii) In the case of solving polynomial equations i.e., dealing with the algebra
of polynomials, the degrees of polynomial instances, may be taken as
the sizes of the corresponding instances.
There are two approaches for determining complexity (or time required) for
executing an algorithm, viz.,
i) empirical (or a posterior)
ii) theoretical (or priori)
In the empirical approach (the programmed) algorithm is actually executed
on various instances of the problem and the size (s) and time (t) of
execution for each instance is noted. And then by some numerical or other
technique, t is determined as a function of s. This function then, is taken as
complexity of the algorithm under consideration.
In the theoretical approach, we mathematically determine the time needed
by the algorithm, for a general instance of size, say, n of the problem under
consideration. In this approach, generally, each of the basic instructions like
assignment, read and write and each of the basic operation like ‘+’,
comparison of pair of integers etc. is assumed to take one or more, but
some constant number of, (basic) units of time for execution. Time for
execution for each structuring rule is assumed to be some function of the
time required for constituent of the structure.
Thus starting from the basic instructions and operations and using
structuring rules, we can calculate the time complexity of a problem or an
algorithm.
The theoretical approach has a number of advantages over the empirical
approach as listed below:
i) The approach does not depend on the programming language in which
the algorithm is coded and on how it is coded in the language.
ii) The approach does not depend on the computer system used for
executing (a programmed version of) the algorithm.
iii) In case of a comparatively inefficient algorithm, which ultimately is to be
rejected, the computer resources and programming efforts which
otherwise would have been required and wasted, will be saved.
iv) Instead of applying the algorithm to many different – sized instances, the
approach can be applied for a general size, say, n of an arbitrary
instance of the problem under consideration. In the case of theoretical
approach, the size n may be arbitrary large. However, in empirical
approach, because of practical considerations, only the instances of
moderate sizes may be considered.
Self Assessment Question
6. Starting from the basic instructions and operations and using structuring
rules, we can calculate the ––––––––– of a problem.
Solution:
i) Consider
f(x) = 2x2 + 3x2 + 1
2x3 + 3x3 + 1x3 = 6x3 for all x 1
(by replacing each term xi by the highest degree term x3)
there exist C = 6 and k = 1 such that
f(x) C, x3 for all x k
Thus we have found the required constants C and k. Hence f(x) is O(x3)
ii) As, above, we can show that
f(x) 6x4 for all x 1
However, we may also, by computing some value of f(x) and x4, find
C and k as follows
f(1) = 2 + 3 + 1 = 6 ; (1)4 = 1
f(2) = 2.23 + 3.22 + 1 = 29 ; (2)4 = 16
f(3) = 2.33 + 3.32 + 1 = 82 ; (3)4 = 81
for C = 2 and k = 3 we have
f(x) 2. x4 for all x k
Hence f(x) is O(x4)
iii) for C = 1 and k = 1 we get
x3 C (2x3 + 3x2 + 1) for all x k
iv) We prove the result by contradiction. Let there exist positive constants C
and k such that
x4 C (2x3 + 3x2 + 1) for all x k
x4 C (2x3 +3x3 + x3) = 6 Cx3 for x k
x4 6 Cx3 for all x k
Implying x 6C for all x k
But for x = max {6C + 1, k}, the previous statement is not true.
Hence the proof.
v) Again we establish the result by contradiction.
Let O(2x3 + 3x2 + 1) = x2
Then for some positive numbers C and k
2x3 + 3x2 + 1 Cx2 for all x k,
Implying
x3 C x2 for all x k ( x3 2x3 + 3x2 + 1 for all x 1)
implying
x C for x k
Again for x = max {C + 1, k}
The last inequality does not hold. Hence the result.
2) The Notation
*
The function f(n)= (g(n)) (read as “f of n is omega of g of n”) if there exist
positive constants c and no such that f(n) =c g(n) for all n, n no.
Eg: The function 3n+2= (n) as 3n+2 3n for n 1
The function 3n+3= (n) as 3n+3 3n for n 1
The function 10n2+4n+2= (n2) as 10n2+4n+2 n2 for n 1
The statement f(n)= (g(n)) states that g(n) is only a lower bound on f(n).
3) The Notation
This notation provides simultaneously both asymptotic lower bound and
asymptotic upper bound for a given function.
Let f(x) and g(x) be two functions, each from the set of natural numbers or
positive real numbers to positive real numbers. Then, f(x) is said to be
(g(x)) (pronounced as big-theta of g of x) if, there exists positive constants
C1, C2 and k such that C2 g(x) f(x) C1g(x) for all x k.
(Note the last inequalities represent two conditions to be satisfied
simultaneously viz.,
C2 g(x) f(x) and f(x) C1g(x))
Now we state the following theorem without proof which relates the three
functions O
Theorem: For any two functions f(x) and g(x), f(x) = (g(x)) if and only if
f (x) = 0 (g(x)) and f(x) = (g(x)) where f(x) and g(x) are non-negative.
Solution: First, we find an upper bound for the sum. For n 1, consider
1 + 2 + …… + n n + n + ….. + n = n. n = n2
This implies that f(n) = O(n2). Next, we obtain a lower bound for the sum.
We have
n
1 2 ... n 1 2 ... ..... n
2
n
..... n
2
n n n
..
2 2 2
n n
.
2 2
n2
.
4
This proves that f(n) = (n2). Thus by the above. Theorem f(n) = (n2).
4) The Notation
The asymptotic upper bound provided by big-oh notation may or may not be
tight in the sense that if f(x) = 2x3 + 3x2 + 1. Then for f(x) = O(x3), though
there exist C and k such that f(x) C(x3) for all x k yet there may also be
some values for which the following equality also holds
f(x) = C(x3) for x k However, if we consider f(x) = O(x4) then there can not
exist positive integer C such that f(x) = Cx4 for all x k.
The case of f(x) = O(x4) provides an example for the notation of small-oh
i.e., notation o
Let f(x) and g(x) be two functions, each from the set of natural numbers or
positive real numbers to positive real numbers.
Further, let C > 0 be any number, then f(x) = o (g(x)) (pronounced as little oh
of g of x) if there exists natural number k satisfying
f(x) < Cg (x) for all x k 1 ………..(B)
Here we get the following points
i) In the case of little-oh the constant C does not depend on the two
functions f(x) and g(x). instead, we can arbitrarily choose C > 0
ii) The inequality (B) is strict whereas the inequality (A) of big — oh is not
necessarily strict.
Examples:
For f(x) = 2x3 + 3x2 + 1, we have
i) f(x) = o(xn) for any n 4
ii) f(x) o(xn) for any n 3
Solutions:
i) Let C > 0 be given and to find out k satisfying the requirement of little-
oh.
Consider
3 1 n 3
2x3 + 3x2 + 1 < C xn 2 x 3 Cx
x
When n = 4
Then, above inequality becomes
3 1
2 3 Cx
x x
7
If we take k max C , 1
Then,
2x3 + 3x2 + 1 < C x4 for n k. In general, as xn > x4 for n 4, therefore,
7
2x3 + 3x2 + 1 < C xn for n 4.For all x k with k max C , 1
ii) We prove the result by contradiction Let, if possible, f(x) = 0 (x) for n 3.
Then there exist positive constants C and k such that 2x3 + 3x2 + I < C xn
for all x k.
Dividing by x3 throughout, we get
3 1
2 2 C x n 3
x x
3 1
2 2 1
x x for n 3
However, the last inequality is not true. Therefore, the proof by
contradiction. Generalizing the above example, we get the results
f(x) is a polynomial of degree m and g(x) is a polynomial of degree n. Then
f(x) = o(g(x)) if and only if n > m
We state below the two results which can be useful in finding small-oh upper
bound for a given function (without proof).
More generally, we have
Theorem: Let f(x) and g (x) be functions in definition of small — oh notation.
Then f(x) = o(g (x)) if and only if
f x
Lim 0
x g x
Example:
Lf f(x) = 2x3 + 3x2 + 1 then f(x) = and also f(x) = (x2)
Solution:
Let C be any positive constant
Consider 2x3 + 3x2 + 1 > Cx
To find out k 1 satisfying the Conditions of the bound .
1
2x2 3x C (dividing through out by x)
x
Let k be integer with k C + 1 then for all x k
2x2 3x
1
x
2 x 2 3 x 2 k 2 3K 2C 2 3C C k C 1
1
f(x) = (x)
Again, consider for any C > 0, 2x3 + 3x2 + I > C > x2 then
1
2x 3 C
x2 Let k be integer with k C + 1
1
Then, for x k we have 2 x 3 2 x 3 2 k 3 2C 3 C
x2
Hence
f(x) = (x2)
In general, we have the following two theorems
g x
lim 0
x f x
Analysis of First-Averages
The different steps involved in the analysis of first averages is discussed
below
Step 1: Initialization step for setting up of the array A [1. .n] takes constant
time, say, C1, in view of the fact that for the purpose, only address of A (or of
Manipal University Jaipur B1640 Page No. 193
Data Structures and Algorithm Unit 10
A[1] is to be passed. Also after all the values of B [1...n] are computed, then
returning the array B [1…n] also takes constant time say C2, again for the
same reason.
Step 2: The body of the algorithm has two nested for-loops, the outer one,
called the first for loop is controlled by i and is executed n times. Hence, the
second for-loop along with its body, which form a part of the first for-loop, is
executed n times. Further, each construct within second for-loop controlled
by j, is executed i times just because of the iteration of the second for-loop.
However, the second for-loop itself is being executed n times because of the
first for-loop. Hence, each instruction within the second for-loop is executed
(n, i) times for each values of
i = 1, 2, . . .,n.
The second for-loop makes, for each value of i = 1, 2,……n, one addition
and one comparison. Thus, total number of each of additions and
comparisons done just for controlling variable j
nn 1
1 2 ...... n
2
10.8 Summary
We Studied the different types of functions and Notations with well
illustrated example.
The concept of Modular arithmetic/ Mod function is well defined with
simple examples.
The concept of Mathematical Expectation and its use in average case
analysis of algorithms is well illustrated.
In this unit, we discussed that if a problem is algorithmically solvable
then it may have more than one algorithmic solutions. In order to choose
the best out of the available solutions, there are criteria for making such
a choice. The complexity/efficiency measures or criteria are based on
requirement of computer resources by each of the available solutions.
In this unit, we also studied the different types of Asymptotic functions
and their Notations.
10.10 Answers
Self Assessment Questions
1. f(x) f(y)
2. Ceiling function
3. Exponentiation function
4. ex
5. Mathematical Expectation
6. time complexity
7. Notation O
f ( x)
8. Lim 0
x g( x )
n(n 1)
9.
2
Terminal Questions
1. Refer Section 10.2
2. Refer Section 10.2
3. Refer Section 10.3
4. Refer Section 10.6
5. i) for C1 =3, C2 = 1 and k = 4 i.e. 1. C2 x3 f(x) C1 x3 for all x k
ii) We can show by contradiction that no C1 exists. Let, if possible for
some positive integers k and C1, we have 2x3 + 3x2 + 1 C1. x2 for
all x k hence x3 C1 x2 for all x k
i.e.,x C1 for all x k
But for x = max {C1 + 1, k}
The last inequality is not true.
Therefore, x = max {C1 + 1, k}
iii) f(x) (x4)
we can show by contradiction that there does not exist C2
such that
C2 x4 (2x3 + 3x2 + 1)
If such a C2 exists for some k then C2 x4 2x3 + 3x2 + 1 6x3 for all
x 1, k 1, implying C2 x 6 for all x k
6
But for x 1
C2
The above inequality is false. Hence, proof by contradiction.