DR. Gatot F. Hertono, MSc. Design and Analysis of ALGORITHM (Session 2)
Algorithm design and analysis process Source: Introduction to the Design and Analysis of Algorithms, Anany Levitin
Asymptotic Notation: Order of Growth Suppose, in worst case, a problem can be solved by using two different algorithms, with time complexity: Algorithm A:Algorithm B: Which one is better? we use Asymptotic Notation ( , dan O) Background
Upper and Lower Bounds
, and O notations What does it mean?
Names of Bounding Functions f(n) =O(g(n)) means C x g(n) is an upper bound on f(n). f(n) =Ω(g(n)) means C x g(n) is a lower bound on f(n). f(n) =(g(n)) means C 1 x g(n) is an upper bound on f(n) and C 2 x g(n) is a lower bound on f(n).
O (big Oh) Notation i.e. f does not grow faster than g. Example: f(n) = n n n, then f(n) = O(n 3 ). Proof: n 0, n n n n n n 3 = 121.n 3. Choose c = 121 and n 0 = 0, then it completes the definition. Formal definition:
(big Omega) Notation c 2.g(n) f(n)f(n) n0n0 Formal definition:
(Big Theta) Notation c 1.g(n) c 2.g(n) f(n)f(n) n0n0 Formal definition:
More on Big-Theta f(n) is sandwiched between c 1 g(n) and c 2 g(n) f(n) = (g(n)) For some definition of “sufficiently large” For some sufficiently small c1 (= ) For some sufficiently large c2 (= 1000) For all sufficiently large n Constants c1 and c2 must be positive!
Examples of 3n 2 + 7n + 8 = (n 2 ) ? 3·n 2 3n 2 + 7n + 8 4·n n 8 n 2 = (n 3 ) ? 0 0 · n 3 n 2 c 2 · n 3 True False, since C1,C2 must be >0
Properties Assignment 2a: Based on the definition of , and O, prove that
Notes Assignment 2b:
Examples
What does asymptotic property imply for an algorithm? How is the overall efficiency of this algorithm?
Other Notations Thetaf(n) = θ(g(n))f(n) ≈ c g(n) BigOhf(n) = O(g(n))f(n) ≤ c g(n) Omegaf(n) = Ω(g(n))f(n) ≥ c g(n) Little Ohf(n) = o(g(n))f(n) << c g(n) Little Omegaf(n) = ω(g(n))f(n) >> c g(n)
Order Hierarchy O(1) O(log n) O( n) O(n) O(n log n) O(n 2 ) O(n 3 ) O(2 n ) O(n2 n ) O(n!) Note : not all order are comparable Two functions, f(n) and g(n), are not comparable if: Example: f(n) = n 3 and g(n) = n 4.(n mod 2) + n 2 ))(()(and ))(()(nfOngngOnf
Lesson Learn