zoukankan      html  css  js  c++  java
  • 基础复习-算法设计基础 | 复杂度计算

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

     

    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

     

     

     

     

     

  • 相关阅读:
    在iview admin中封装axios请求
    git使用
    css选择器
    vue打包空白及字体路径错误问题
    axios 等待同步请求用法及多请求并发
    在Vuex更新,组件内的视图更新问题
    vue中用ajax上传文件
    在vue中使用lang="scss"出现报错解决思路
    HBuilder打包vue项目app后空白,并请求不到数据
    接口里返回的数据不全问题
  • 原文地址:https://www.cnblogs.com/qinziang/p/9241521.html
Copyright © 2011-2022 走看看