200 likes | 352 Views
Advance Data Structure and Algorithm COSC600-101-FA14. Dr. Yanggon Kim Chapter 2 Algorithm Analysis. Algorithm Analysis. General, This Chapter learn for Running-time. How to estimate the time required for a program.
E N D
Advance Data Structure and AlgorithmCOSC600-101-FA14 Dr. Yanggon Kim Chapter 2 Algorithm Analysis
Algorithm Analysis • General, This Chapter learn for Running-time. • How to estimate the time required for a program. • How to reduce the running time of a program from day or years to fractions of a second. • The results of careless use of recursion. • Very efficient algorithms to raise a number to a power and to compute the greatest common divisor of two numbers.
Analysis of Algorithm -> Use running-time • Worst-case running-time • Average-case running-time (Expected)running –time Use T(n) More simplifying “abstract” T1(N) = 2 + 5N + 100 for algm1 T2(N) = 3+ 5N + 100 for algm2 “Higest Fact”
Asymptotic Notation Convenient for describing the worst-case running-time f(n), T(n) Function ① Big-Oh - O(N) ②Big-Omega - Ω(N) ③Big-Theta - ϴ(N) ④Little-Oh - o(N)
Function(Continued) ① Big-Oh - O(N) (Asymptotic Upper-bound) T(N) = O(f(N)) If these are positive constant C and s.t T(N) ≤ C∙f(N) when N≥ T(N) T T(N) N
Function(Continued) T(N) = 2 + 100 - 5N + 500 = O() f(n)= = O () = O () ex)T(N) = 2∙logN + 500,000 = O(logN) = O(N) = O()
Function(Continued) ② Big-Omega - Ω(N) (Asymptotic lower-bound) T(N) = Ω(g(N)) If these are positive constant C ≠ s.t T(N) ≥ C∙g(N) when N≥ T(N) T C∙g(N) N
Function(Continued) T(N) = 5∙+ 500 = O(1) = O() = O(log N) = O() = O(log100 N)
Function(Continued) ③ Big-Theta - ϴ(N) (Asymptotic tight-bound) T(N) = ϴ(h(N)) If T(N) = O(h(N)) ≠ T(N) = Ω(H(N)) Ex) T(N) = 3 ∙ + 1000N – 500 = O = () = O() ≠ () = Ω(N) =Ω(log N) =Ω() = ϴ()
Function(Continued) ④Little-Oh T(N) = o(P(N)) If T(N) = o(P(N)) and T(N) ≠ ϴ(P(N)) Rule1 If T1(N) = O(f(N)) ≠ T2(N) = O(g(N)) i) T1(N) + T2(N) = max(O(f(N)) ∙ O(g(N))) ii) T1(N) - T2(N) = O(f(N))∙ g(N)) iii) T1(N) – T2(N) ≠ min(o(f(N)) ∙ o(g(N))) iv) T1(N) / T2(N) ≠ O(f(N)/g(N))
Function(Continued) Rule2 If T(N) is a polynomial of degree K ∙f(n) T(N) = ϴ() ex) T(N) = 5 + 100 =ϴ() Rule3 = = O(N) • logarithm, grow very slowly • Ignore lowen-ove
Function(Continued) ex) T(N) = + 500 + ≠ O( = O() always = O() when a>1
Function(Continued) Hospitals Rules = O -> f(N) =O(g(N)) = C (constant) -> f(N) = O(g(N)) = ∞ -> g(N) =O(f(N)) =osicillate -> no relationship Ex) + O(n) = O() = = O(N) = Ω(log N) = Ω(log N) when k is a positive -100n = ϴ() n≥1
Function(Continued) Ex) stat O; T(1) for(i=0; i<n; i++){ stament1; stament2; T2(N) = 3n stament3; } T(n) = 2+3n+C for(j=0; j<n*n; j++){ = O() stament1; = ϴ() stament2; T3(N) =2 }
Function(Continued) Ex) for(i=0; i<n; i++){ for(j=0; j<i; j++){ stament1; stament2; T(N) = (1+2+3+ ∙∙∙∙∙ +n) ∙ 3 I = 3 ∙ stament10; = O() } = ϴ() }
Function(Continued) Ex) Binary Search let ,, ,∙∙∙∙∙∙, Be seted T(N) = T() + = T() + + = T() + + + = T(1) + ∙ ∙∙∙∙ ∙ + + + -> log n = C ∙ log n = ϴ(log n)
Function(Continued) Divide ≠ cones method General form of T(n) T(n) = a – T() + ϴ() Masten Theorem T(N) = O() if a > = O(∙ if a = = O() if a <
Function(Continued) Ex) Merge N ,∙∙∙∙∙∙, ϴ(N) ,,
Function(Continued) T(n) = 2∙T() + ϴ(n) = O(n ) = 2 ∙ 2∙T() + ϴ() + ϴ(n) = 2 ∙ 2 ∙ 2 ∙T() + () + ϴ() + ϴ(n) = 2∙∙∙∙∙2∙T(1) + = 2 ∙ ≈O(O(n )
Function(Continued) Typical f(n)’s growth rate C N N ∙ N ∙ = where A>1 Faster Faster