Академический Документы
Профессиональный Документы
Культура Документы
15/11/2016
Recap
Asymptotic analysis
f(n)
Calculating c and g
Calculating c and g
g(n) vs c
N is always a
point where the
functions cg(n)
and f intersect
each other
function g is plotted with different coefficients c
M. Shahzad: Data Structures & Algorithms
Best g(n)
The inherent imprecision of the big-O notation goes even
further, because there can be infinitely many functions g for
a given function f
E.g., f (n) = 2n2 + 3n + 1 is big-O not only of n2, but also of
n3, n4, . . . , nk, . . . for any k 2
To avoid this, the smallest function g is chosen, i.e., n2 in
this case
Also, the approximation of f can go further
I.e., f (n) = 2n2 + 3n + 1 can be approximated as f(n) =
2n2 + O(n)
Or the function n2 + 100n + log10n + 1,000 can be
approximated as n2 + 100n + O(log10n)
M. Shahzad: Data Structures & Algorithms
Big-O Examples
Big-O Examples
Big-O Examples
T(n) examples
3n + 4
4n2 + 17n + 5344
6n3+ 3n2 + 5n + 57
15log2(n) + 37
15 x 2n + 4n57 +16
37
O(n)
O(n2)
O(n3)
O(log(n)) Logarithmic
O(2n)
Exponential
O(1)
Constant time
Linear
Quadratic
Cubic
10
11