问题1:关于 算法复杂度

KhanAcademy

衡量算法复杂度,一般是指算法花费的时间长短,这取决于input的size和随着input size增长而算法时间增长的速度:

1) The size of its input;

2) The rate of growth: how fast a function grows with the input size.

 

1. 算法复杂度的标记:

$\Theta: $ an asympototic tight bound.类似于上确界的定义

$O:$ an asympototic upper bound.类似于上界的定义

$\Omega:$ an asympototic lower bound.类似于下界的定义

If f(n) is O(g(n)) this means that f(n) grows asymptotically no faster than g(n)

If f(n) is Θ(g(n)) this means that f(n) grows asymptotically at the same rate as g(n)

$\Theta(g(n))$表示当n足够大时,算法在最坏的情况下,存在某常数$k_1,k_2$,使得执行时间会在$k_1\cdot g(n)$和$k_2\cdot g(n)$之间。

 

2. 算法复杂度的大小比较:

constant < logarithmic < linear < polynomial < exponential < factorial

代入具体的数字,有

$\Theta(1) < \Theta(\lg n) < \Theta(n\lg n) < \Theta(n^2) < \Theta(2^n) < \Theta(n!)$

并且$\Theta(n^b) < \Theta(a^n), \forall a > 1, b \geq 1$,$\Theta(n!) > \Theta(a^n), \forall a>1$

posted on 2017-11-19 16:08  RRRRecord  阅读(216)  评论(0编辑  收藏  举报