Order of Growth
Order of Growth
• The order of growth ignores the constant factor needed for fixed
operations and focuses instead on the operations that increase
proportional to input size.
Orders of growth
Order Big-Theta Example
first_post = posts[0]
Orders of growth (Logarithmic)
List size Steps
• When analgorithm has a logarithmic order of 1 1
growth, it increases proportionally to the 10 4
logarithm of the input size. 100 7
1000 10
• The binary search algorithm is an example of
an algorithm that runs in logarithmic time.
Orders of growth (Linear time)
List size Steps
• When an algorithm has a linear order of growth, its
1 1
number of steps increases in direct proportion to the
input size. 10 10
•
To compare two algorithms with running times f(n) and g(n), we need a rough measure that
characterizes how fast each function grows.
•
Hint: use rate of growth
•
Compare functions in the limit, that is, asymptotically!
(i.e., for large values of n)
Engineered for
Tomorrow
ASYMPTOTIC NOTATION
•
O notation: asymptotic “less than”:
f(n)=O(g(n)) implies: f(n) “≤” g(n)
•
Ω notation: asymptotic “greater than”:
f(n)= Ω (g(n)) implies: f(n) “≥” g(n)
•
θ notation: asymptotic “equality”:
f(n)= θ (g(n)) implies: f(n) “=” g(n)
19
Engineered for
Tomorrow
ASYMPTOTIC NOTATIONS
O-notation
12/8/13
Engineered for
Tomorrow
Examples
f(n)=3n2+n
= 3n2+n2 n2 ≤ cn2 ; c ≥ 1 ; c = 1 and n0= 1
=4n2
f(n)<=c*g(n)
3n2+n<=4n2=o(n2)
12/8/13
Engineered for
Tomorrow
Examples
f(n)=3n2+n
= 3n2+n
=3n2
f(n)>=c*g(n)
3n2+n>=3n2= Ω(n2)
Examples
C2g(n)<=f(n)<=c1g(n) for all n>=n0
3n2+n<=f(n)<=3n2+n2
3n2<=f(n)<=4n2
Where c2=3, c1=4 and n=1
Therefore, 3n2+n ∈ θ(n2)
Establishing order of growth using limits
0 order of growth of T(n) < order of growth of g(n)
Examples:
• 10n vs. n2
• n(n+1)/2 vs. n2
L-Hopital’s rule and Stirling’s formula
L’Hôpital’s rule: If limn f(n) = limn g(n) = and
the derivatives f´, g´ exist, then
Example: 2n vs. n!
Orders of growth of some important functions
• All logarithmic functions loga n belong to the same class
(log n) no matter what the logarithm’s base a > 1 is
• All polynomials of the same degree k belong to the same class: aknk + ak-1nk-1 + … +
a0 (nk)
• Exponential functions an have different orders of growth for different a’s
• order log n < order n (>0) < order an < order n! < order nn
Basic asymptotic efficiency classes
1 constant
log n logarithmic
n linear
n log n n-log-n
n2 quadratic
n3 cubic
2n exponential
n! factorial