Lecture02 Analysis
Lecture02 Analysis
Analysis of Algorithms
T. M. Murali
Polynomial time
I Brute force algorithm: Check every possible solution.
Polynomial time
I Brute force algorithm: Check every possible solution.
I What is a brute force algorithm for sorting: given n numbers,
permute them so that they appear in increasing order?
Polynomial time
I Brute force algorithm: Check every possible solution.
I What is a brute force algorithm for sorting: given n numbers,
permute them so that they appear in increasing order?
I Try all possible n! permutations of the numbers.
I For each permutation, check if it is sorted.
Polynomial time
I Brute force algorithm: Check every possible solution.
I What is a brute force algorithm for sorting: given n numbers,
permute them so that they appear in increasing order?
I Try all possible n! permutations of the numbers.
I For each permutation, check if it is sorted.
Polynomial time
I Brute force algorithm: Check every possible solution.
I What is a brute force algorithm for sorting: given n numbers,
permute them so that they appear in increasing order?
I Try all possible n! permutations of the numbers.
I For each permutation, check if it is sorted.
Polynomial time
I Brute force algorithm: Check every possible solution.
I What is a brute force algorithm for sorting: given n numbers,
permute them so that they appear in increasing order?
I Try all possible n! permutations of the numbers.
I For each permutation, check if it is sorted.
Polynomial time
I Brute force algorithm: Check every possible solution.
I What is a brute force algorithm for sorting: given n numbers,
permute them so that they appear in increasing order?
I Try all possible n! permutations of the numbers.
I For each permutation, check if it is sorted.
Denition
An algorithm is ecient if it has a polynomial running time.
T. M. Murali January 16, 2008 Analysis of Algorithms
Computational Tractability Asymptotic Order of Growth Common Running Times
Transitivity
I If f = O (g ) and g = O (h), then f = O (h).
I If f = Ω(g ) and g = Ω(h), then f = Ω(h).
I If f = Θ(g ) and g = Θ(h), then f = Θ(h).
Transitivity
I If f = O (g ) and g = O (h), then f = O (h).
I If f = Ω(g ) and g = Ω(h), then f = Ω(h).
I If f = Θ(g ) and g = Θ(h), then f = Θ(h).
Additivity
I If f = O (h) and g = O (h), then f + g = O (h).
I Similar statements hold for lower and tight bounds.
Transitivity
I If f = O (g ) and g = O (h), then f = O (h).
I If f = Ω(g ) and g = Ω(h), then f = Ω(h).
I If f = Θ(g ) and g = Θ(h), then f = Θ(h).
Additivity
I If f = O (h) and g = O (h), then f + g = O (h).
I Similar statements hold for lower and tight bounds.
I If k is a constant and there are k functions
fi = O (h), 1 ≤ i ≤ k ,
Transitivity
I If f = O (g ) and g = O (h), then f = O (h).
I If f = Ω(g ) and g = Ω(h), then f = Ω(h).
I If f = Θ(g ) and g = Θ(h), then f = Θ(h).
Additivity
I If f = O (h) and g = O (h), then f + g = O (h).
I Similar statements hold for lower and tight bounds.
I If k is a constant and there are k functions
fi = O (h), 1 ≤ i ≤ k , then f1 + f2 + . . . + fk = O (h).
Transitivity
I If f = O (g ) and g = O (h), then f = O (h).
I If f = Ω(g ) and g = Ω(h), then f = Ω(h).
I If f = Θ(g ) and g = Θ(h), then f = Θ(h).
Additivity
I If f = O (h) and g = O (h), then f + g = O (h).
I Similar statements hold for lower and tight bounds.
I If k is a constant and there are k functions
fi = O (h), 1 ≤ i ≤ k , then f1 + f2 + . . . + fk = O (h).
I If f = O (g ), then f + g =
Transitivity
I If f = O (g ) and g = O (h), then f = O (h).
I If f = Ω(g ) and g = Ω(h), then f = Ω(h).
I If f = Θ(g ) and g = Θ(h), then f = Θ(h).
Additivity
I If f = O (h) and g = O (h), then f + g = O (h).
I Similar statements hold for lower and tight bounds.
I If k is a constant and there are k functions
fi = O (h), 1 ≤ i ≤ k , then f1 + f2 + . . . + fk = O (h).
I If f = O (g ), then f + g = Θ(g ).
Examples
I f (n) = pn2 + qn + r is
Examples
Examples
Examples
Examples
Examples
Examples
Examples
Linear time
Linear time
Linear time
Linear time
O (n log n) time
Quadratic time
Quadratic time
Quadratic time
O (nk ) time
O (nk ) time
O (nk ) time
O (nk ) time