1-2 Growth of Functions

Southgiri·2025년 8월 4일

SNUON Algorithm

목록 보기
2/7

Standard methods for simplifying the asymptotic analysis of algorithms

Algorithm Analysis

  • The running time TT is a function of the amount of input nn, T(n)=f(n)T(n)=f(n)

Θ-notation

  • Θ(g(n))={f(n):0c1g(n)f(n)c2g(n) for all nn0}\Theta(g(n))=\{ f(n): 0 \leq c_1g(n) \leq f(n) \leq c_2g(n) \text{ for all }n \geq n_0 \}
  • f(n)=Θ(g(n))f(n)=\Theta(g(n)) if there is positive constants c1,c2c_1, c_2
  • g(n)g(n) is an asymptotically tight bound for f(n)f(n)
  • f(n)f(n) is nonnegative whenever nn is sufficiently large
  • g(n)g(n) must be asymptotically nonnegative

Example : f(n)=12n23n=Θ(n2)=g(n)f(n)={{1}\over{2}}n^2-3n=\Theta(n^2)=g(n)

  • c1n212n23nc2n2c_1n^2 \leq {{1}\over{2}}n^2-3n \leq c_2n^2 for all nn0n \geq n_0
  • Dividing by n2n^2
    • c1123nc2c_1 \leq {{1}\over{2}}-{{3}\over{n}} \leq c_2
  • Right hand inequality
    • Hold for any value of n1n\geq 1 by choosing any constant c212c_2 \geq {{1}\over{2}}
  • Left hand inequality
    • Hold for any value of n7n \geq 7 by choosing any constant c1114c_1 \leq {{1}\over{14}}
  • Thus, by choosing c1=114,c212,n07c_1={{1}\over{14}}, c_2 \geq {{1}\over{2}}, n_0 \geq 7,
    we can verify that 12n23n=Θ(n2){{1}\over{2}}n^2-3n=\Theta(n^2)

O-notation

  • Given an upper bound on a function
  • O(g(n))={f(n):0f(n)cg(n) for all nn0}O(g(n))=\{f(n): 0 \leq f(n) \leq cg(n) \text{ for all }n \geq n_0\}
    • There exist positive constants cc and n0n_0

Ω-notation

  • Lower bound on a function
  • Ω(g(n))={f(n):0cg(n)f(n) for all nn0}\Omega(g(n)) = \{f(n): 0 \leq cg(n) \leq f(n) \text{ for all } n \geq n_0\}
    • Positive constants cc and n0n_0

Asymptotic Notation

  • We have f(n)=Θ(g(n))f(n)=\Theta(g(n))
    if and only if f(n)=O(g(n))f(n)=O(g(n)) and f(n)=Ω(g(n))f(n)=\Omega(g(n))

Properties of Big-O

  • If T1(n)=O(f(n))T_1(n)=O(f(n)) and T2(n)=O(g(n))T_2(n)=O(g(n)),
    • T1(n)+T2(n)=max(O(f(n)),O(g(n)))T_1(n)+T_2(n) = max(O(f(n)), O(g(n)))
    • Lower order terms are ignored
  • O(cf(n))=O(f(n))O(c*f(n))=O(f(n))
    • Constants are ignored
  • Constants and lower order terms may matter especially when the input size is small
  • For large nn, dominant term is usually indicative of algorithm's behavior
  • For small nn, typically programs on small inputs run so fast we don't care anyway

0개의 댓글