Download presentation
Presentation is loading. Please wait.
Published byGary Banks Modified over 8 years ago
1
DR. Gatot F. Hertono, MSc. Design and Analysis of ALGORITHM (Session 2)
2
Algorithm design and analysis process Source: Introduction to the Design and Analysis of Algorithms, Anany Levitin
3
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
4
Upper and Lower Bounds
5
, and O notations What does it mean?
6
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).
7
O (big Oh) Notation i.e. f does not grow faster than g. Example: f(n) = n 3 + 20 n 2 + 100.n, then f(n) = O(n 3 ). Proof: n 0, n 3 + 20 n 2 + 100.n n 3 + 20 n 3 + 100.n 3 = 121.n 3. Choose c = 121 and n 0 = 0, then it completes the definition. Formal definition:
8
(big Omega) Notation c 2.g(n) f(n)f(n) n0n0 Formal definition:
9
(Big Theta) Notation c 1.g(n) c 2.g(n) f(n)f(n) n0n0 Formal definition:
10
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 (= 0.0001) For some sufficiently large c2 (= 1000) For all sufficiently large n Constants c1 and c2 must be positive!
11
Examples of 3n 2 + 7n + 8 = (n 2 ) ? 3·n 2 3n 2 + 7n + 8 4·n 2 348 n 8 n 2 = (n 3 ) ? 0 0 · n 3 n 2 c 2 · n 3 True False, since C1,C2 must be >0
12
Properties Assignment 2a: Based on the definition of , and O, prove that
13
Notes Assignment 2b:
14
Examples
15
What does asymptotic property imply for an algorithm? How is the overall efficiency of this algorithm?
16
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)
17
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
18
Lesson Learn
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.