Professional Documents
Culture Documents
1
Analysis of Algorithms
• Issues:
Correctness
Time Efficiency
Space Efficiency
Optimality
• Approaches:
Theoretical Analysis
Empirical Analysis
Analysis of Algorithms - Issues
• Issues:
Correctness – Does it work as advertised?
Time Efficiency – Are time requirements minimized?
Space Efficiency – Are space requirements minimized?
Optimality – Do we have the best balance between minimizing time and
space?
• Theoretical
Theoretical Analysis Of Time Efficiency
Asymptotic Notations
c2 ⋅ g
f
c1 ⋅ g
n0
The O-Notation
c⋅g
n0
The Ω-Notation
f
c⋅g
n0
The o-Notation
c2 ⋅ g
c1 ⋅ g
f
n1 n2 n3
The ω-Notation
c2 ⋅ g
c1 ⋅ g
n1 n2 n3
Comparison of Functions
• Monotonicity
A function f(n) is monotonically increasing if m n
implies f(m) f(n) .
A function f(n) is monotonically decreasing if m n
implies f(m) f(n) .
A function f(n) is strictly increasing
if m < n implies f(m) < f(n) .
A function f(n) is strictly decreasing
if m < n implies f(m) > f(n) .
Standard Notation and
Common Functions
• Exponentials
For all n and a1, the function an is the exponential function
with base a and is monotonically increasing.
• Logarithms ai
Textbook adopts the following convention
lg n = log2n (binary logarithm),
ln n = logen (natural logarithm),
lgk n = (lg n)k (exponentiation),
lg lg n = lg(lg n) (composition),
lg n + k = (lg n)+k (precedence of lg).
• Consider this peace of code for calculating the factorial of a number:
function factorial(n):
fact = 1
for i in range(0 to n-1)
fact = fact * i
return fact
Now if you sum up all the primitive operations' cost you get
C = c1 + n*c2 + 2*c3*n + c4
= (c1+c4) + n*(c2+c3)
= C1+n*C2
C = θ(n)