Lecture-15_student
Lecture-15_student
Algorithms
x y( x y )
x( | x )
1 Chapter 3
x 1
x
?
x 1
x ?
RIZOAN TOUFIQ
ASSISTANT PROFESSOR
DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING
RAJSHAHI UNIVERSITY OF ENGINEERING & TECHNOLOGY
The Growth of Functions
Section 3.2
Section Summary
Big-O Notation
Big-O Estimates for Important Functions
Big-Omega and Big-Theta Notation
Donald E. Knuth
(Born 1938)
f(x) is O(g(x)
Some Important Points about
Big-O Notation
If one pair of witnesses is found, then there are infinitely
many pairs. We can always make the k or the C larger and
still maintain the inequality .
– Any pair C ̍ and k̍ where C < C̍ and k < k ̍ is also a pair of witnesses
since whenever x > k̍ > k.
You may see “ f(x) = O(g(x))” instead of “ f(x) is O(g(x)).”
– But this is an abuse of the equals sign since the meaning is that
there is an inequality relating the values of f and g, for sufficiently
large values of x.
– It is ok to write f(x) ∊ O(g(x)), because O(g(x)) represents the set of
functions that are O(g(x)).
Usually, we will drop the absolute value sign since we will
always deal with functions that take on positive values.
Using the Definition of Big-O
Notation
Example: Show that is .
Solution: Since when x > 1, x < x2 and 1 < x2
is
Big-O Notation
Both and
are such that and .
We say that the two functions are of the same order. (More on this
later)
Continued →
Big-O Estimates for some
Important Functions
Example: Use big-O notation to estimate log n!
Solution: Given that (previous slide)
then .
Hence, log(n!) is O(n∙log(n)) taking C = 1 and k = 1.
Display of Growth of Functions
– By the definition of big-O notation, there are constants C1,C2 ,k1,k2 such that
| f1 (x) ≤ C1|g1(x) | when x > k1 and f2 (x) ≤ C2|g2(x) | when x > k2 .
– |( f1 + f2 )(x)| = |f1(x) + f2(x)|
≤ |f1 (x)| + |f2 (x)| by the triangle inequality |a + b| ≤ |a| + |b|
– |f1 (x)| + |f2 (x)| ≤ C1|g1(x) | + C2|g2(x) |
≤ C1|g(x) | + C2|g(x) | where g(x) = max(|g1(x)|,|g2(x)|)
= (C1 + C2) |g(x)|
= C|g(x)| where C = C1 + C2
– Therefore |( f1 + f2 )(x)| ≤ C|g(x)| whenever x > k, where k = max(k1,k2).
Ordering Functions by Order
of Growth
Put the functions below in order so that each function is big-
O of the next function on the list.
f1(n) = (1.5)n
f2(n) = 8n3+17n2 +111
f3(n) = (log n )2 We solve this exercise by successively finding the function that grows
slowest among all those left on the list.
f4 (n ) = 2n
• f (n) = 10000 (constant, does not increase with n)
f5(n) = log (log n) 9
f6(n) = n2 (log n)3 •f (n) = log (log n) (grows slowest of all the others)
5
f8(n) = n3+ n(log n)2 •f (n) = n (log n) (next largest, (log n) factor smaller than any power of n)
6
2 3 3
f9(n) = 10000 •f (n) = 8n +17n +111 (tied with the one below)
3 2
2
•f7(n) = 2n (n2 +1) (grows faster than above because of the n2 +1 factor)
x 1 x ? 1
x 1
x
?
1
1 2 3 4.... ?
1 1 1 1 1......... ?
x 1
x
?