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

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

 
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

 

 

 

 

 

 

转载于:https://www.cnblogs.com/qinziang/p/9241521.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值