算法复杂度总结

算法复杂度主要包括时间复杂度和空间复杂度,由于现在内存比较大,空间复杂度考虑的已经不多。

 

复杂度主要是n的函数,(n是输入数据的大小)

 

时间复杂度是由基本的操作cop和这个操作的运行次数C(n)(这个基本的操作是程序中耗时最多的基本操作)

 

例如运行时间: T(n) 约等于 copC(n).

 

我们主要关注时间的增长; 对数函数logan的增长最慢; 指数函数2n和阶乘n!的增长太快,这种函数只有在输入数据n很小的时候才有实用价值。

 

复杂度包括:最坏,最好,平均三种。

 

最坏时间复杂度指明的算法的运行上限,最好时间复杂度并不像最坏算法时间复杂度那么重要,但并不是没有用,像排序算法中对一个已经排好序的数组时行排序是最好的情况,一个好的最好时间复杂度的算法可以用来对大部分排好序的数组时行排序。

平均复杂度时行计算不是太容易,可通过概率计算。

 

amortized efficency: 不是运行一遍算法,而是对同一数据结构运行多次,在某些情况下一次运行可能会耗用很多时间,运行多次它们的平均时间会比一次运行的情况要好。

 

O(g(n)) is the set of all funcitons with a smaller or same order of growth as g(n), like  n属于O(n^2) and 2n^2属于O(n^2). Ω(g(n)) stands for the set of all functions with a larger or same order of growth as g(n). Θ(g(n)) is the set of all functions that have the same order of growth as g(n).

 

对非递归算法分析时间复杂度的步骤:

1. Decide on a parameter indication an input's size.

2. Identify the algorithm's basic operation.

3. Check whether the number of times the basic operation is executed depend only o the size of an input. If it also depends on some additional property, the worst-case, average-case, and, if necessary, best-case efficiencies have to be inverstigated separately.

4. Set up a sum expressing the number of times the algorithm's basic operation is exectued.

5. Using standard formulas and rules of sum manipulation, either find a closed-form formula for the cout or, at the very least, establish its order of growth.

 

对递归算法分析时间复杂度的步骤:

1. Decide on a parameter indicating an input's size.

2. Identify the algorithm's basic operation.

3. Check whether the number of times the basic operation is executed can vary on different inputs of the same size; if it can, the worst-case, average-case, and, best-case efficiencies must be inverstigated separately.

4. Set sup arecurrence relation, with an appropriate initial condition, for the number of times the basic operation is executed.

5. Solve the recurrence or at least ascertain the order of growth of its solutions.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值