• 基础复习-算法设计基础 | 复杂度计算


    一. 算法时间复杂度比较符号

     

    Definition of Asymptotic Signature

      一般讨论的 “计算算法的(时间)复杂度” 是人们为了衡量算法性能创造的一种评估方法,我们引入O,Ω,Θ符号来表示算法的复杂度比较关系,在实际分析中我们默认:f,g are monotonic functions and maps from positive to positive.

     

    "O" signature:

      • We say f(n) = O(g(n)) if g(n) eventually domains f(n).

      Or:

      • If there exists a constant c such thta for all sufficient large n: f(n) ≤ c*g(n). 

    "Ω" signature:

      • We say f(n) = Ω(g(n)) if f(n) eventually domains g(n).

      Or:

      • If there exists a constant c such that for all sufficient large n: f(n) ≥ c*g(n).

    "Θ" signature:

      -We say f(n) = Θ(g(n)) if f(n) = O(g(n))   and f(n) = Ω(g(n))

    Note here in the definition of big o and big sigma, the constant c locate at the same position at the formular, but we can understand it like this:

    • f(n) ≥ c*g(n)
    • 1/c*f(n) ≥ g(n)
    • a*f(n) ≥ g(n)

    so we can think we are searching for a big constant c(a) to magnitude the domianing function in both asymptotic relation.

     

    Approach of Sorting Functions in Asymptotic Order

    Basically we can classify functions into three types: logarithmic, polinomial, exponencial function.

    This is because functions belong to these three types are strictly in ascending asymptotic order:

    证明对数函数增长慢于多项式函数:

      • 令f(n) = n, 则 f(n) = O(P(n))
      • 现证log(n) = O(f(n)):

    令Φ(n) = c*f(n) - log(n)

    令Φ'(n) = c - 1/n = 0, 得c = 1/n

    故Φ(n)在 n = 1/c处取最小值为Φ(1/c) = 1 + log(c)

    得到:当1 + log(c)>0 时,c*f(n) > log(n) 恒成立

    证明指数函数增长快于多项式函数:

    The properties of logarithic function:

      1. 和差
      2. 换底
      3. 指系
      4. 还原
      5. 互换
      6. 倒数
      7. 链式

    Practice:

    sorting functions below in ascending asymptotic order:

    1. log(nn), n2, nlog(n), nlog(log(n)), 2log(n), log2(n), n2^1/2
    2. n2.5, (2n)1/2, n+10, 10n, 100n, n2logn
    3. 2(logn)1/2, 2n, n4/3, nlogn, 22^n, 2n^2

     

     

     

     

     

  • 相关阅读:
    SVN迁移到GIT
    Android之高效率截图
    Android TV 开发(5)
    Android 标题栏(2)
    Android 标题栏(1)
    C# 之抽象类和抽象方法
    浏览器渲染原理及流程
    C#中的DateTime
    由于 Web 服务器上的“ISAPI 和 CGI 限制”列表设置,无法提供您请求的页面。
    配置错误:不能在此路径中使用此配置节。如果在父级别上锁定了该节,便会出现这种情况。锁定是默认设置的
  • 原文地址:https://www.cnblogs.com/qinziang/p/9241521.html
Copyright © 2020-2023  润新知