Function and algorithm
Function and algorithm
f:N→N,f(x)=x^2
is injective.
f:R→R,f(x)=x^2
is not injective as (−x)^2=x^2
A function f:A→B is surjective (onto) if the
image of f equals its range. Equivalently, for
every b∈B, there exists some a∈A such that
f(a)=b. This means that for any y in B, there
exists some x in A such that y=f(x).
Example:
f:N→N,f(x)=x+2is surjective.
f:R→R,f(x)=x^2
is not surjective since we cannot find a real
number whose square is negative.
A function f : A → B is said to be one-to-one if
different elements in the domain A have distinct
images. Another way of saying the same thing is that
f is one-to-one if f (a) = f (a′) implies a = a′.
A function f : A → B is said to be an onto function if
each element of B is the image of some element of A.
In other words, f : A → B is onto if the image of f is
the entire codomain, i.e., if f (A) = B. In such a case
we say that f is a function from A onto B or that f
maps A onto B.
A function f : A → B is invertible if its inverse relation
f −1 is a function from B to A. In general, the inverse
Theorem 3.1: A function f : A → B is invertible if and
only if f is both one-to-one and onto.
• f1 is one-to-one since no element of B is the image of more
than one element of A.
•Similarly, f2 is one-to-one. However, neither f3 nor f4 is one-to-
one since f3(r) = f3(u) and f4(v) = f4(w)
•As far as being onto is concerned, f2 and f3 are both onto
functions since every element of C is the image under f2 of some
element of B and every element of D is the image under f3 of
some element of C, f2(B) = C and f3(C) = D.
On the other hand, f1 is not onto since 3 ∈ B is
not the image under any element of A. and f4 is
not onto since x ∈ E is not the image under f4 of
any element of D.
Thus f1 is one-to-one but not onto, f3 is onto
but not one-to-one and f4 is neither one-to-one
nor onto.
However, f2 is both one-to-one and onto, i.e., is
a one-to-one correspondence between A and B.
Hence f2 is
invertible and f −1
2 is a function from C to B.
⌊x⌋, called the floor of x, denotes the
greatest integer that does not exceed x.
⌈x⌉, called the ceiling of x, denotes the least
integer that is not less than x.
If x is itself an integer, then ⌊x⌋ = ⌈x⌉;
otherwise ⌊x⌋ + 1 = ⌈x⌉. For example,
⌊3.14⌋ = 3, ⌊√5⌋= 2, ⌊−8.5⌋ = −9, ⌊7⌋ = 7,
⌊−4⌋ = −4, ⌈3.14⌉ = 4,⌈√5⌉= 3, ⌈−8.5⌉ =
−8, ⌈7⌉ = 7, ⌈−4⌉ = −4
Let k be any integer and let M be a positive integer.
Then k (mod M) (read: k modulo M) will denote the
integer remainder when k is divided by M. More
exactly, k (mod M) is the unique integer r such that k
= Mq + r where 0 ≤ r < M
When k is positive, simply divide k by M to obtain the
remainder r. Thus 25 (mod 7) = 4, 25 (mod 5) = 0,
35 (mod 11) = 2, 3 (mod 8) = 3
If k is negative, divide |k| by M to obtain a remainder
r′; then k (mod M) = M − r′ when r′ = 0. Thus −26
(mod 7) = 7 − 5 = 2, −371 (mod 8) = 8 − 3 = 5, −39
(mod 3) = 0
The term “mod” is also used for the mathematical
congruence relation, which is denoted and defined as
follows: a ≡ b (mod M) if any only if M divides b − a.
Logarithms are related to exponents as
follows. Let b be a positive number. The
logarithm of any positive number x to be the
base b, written logb x represents the
exponent to which b must be raised to obtain
x. That is, y = logb x and by = x are
equivalent statements. Accordingly,
log2 8 = 3 since 23 = 8; log10 100 = 2 since
102 = 100
log2 64 = 6 since 26 = 64; log10 0.001 = −3
since 10−3 = 0.001
Suppose M is an algorithm, and suppose n is the size
of the input data. Clearly the complexity f (n) of M
increases as n increases. It is usually the rate of
increase of f (n) that we want to examine. This is
usually done by comparing f (n) with some standard
function, such as log n, n, n log n, n2, n3, 2n
The rates of growth for these standard functions are
indicated in Fig. 3-7, which gives their approximate
values for certain values of n. Observe that the
functions are listed in the order of their rates of
growth: the logarithmic function log2 n grows most
slowly, the exponential function 2^n grows most
rapidly, and the polynomial functions n^c grow
according to the exponent c.