Linear algorithms tend to be things where, at one pass-through, you reduce the problem by a constant amount by one. If you reduce it by two, 1 it's going to be the same thing.
有问题么?,线性复杂度的算法,当进行了一个,常量级步数的操作的时候,将问题的规模缩小了一个。
OK. At this point, if we stop, you'll think all algorithms are linear. This is really boring.
可能我们就认为所有的解决这个问题的,算法都是线性增长的了,真很没意思,但是他们真不是对不对?
Obviously-- and that's a bad way of saying it, I said constant the previous time-- in the linear case, it's subtract by certain amount.
这么描述很不准确,我之前在,线性算法中也说了常数,它是每次减少固定的量。
I make the problem ten times bigger, it takes one more step to do it.
而在线性复杂度的算法里,我把规模扩大十倍。
Right? You can see that this ought to be linear, because what am I doing?
这个算法应该是线性复杂度的,因为这个算法是怎么执行的呢?
We've seen log, we've seen linear, we've seen quadratic, we've seen exponential.
我们看过了对数级的,线性的,二次平方的,指数级的算法。
Typical characterization, not all the time, but typical characterization, is an algorithm that reduces the size of a problem by one, or by some constant amount each time, is typically an example of a linear algorithm.
我们学习过了线性算法,它的典型特征,不是通用的,但是比较典型的特征是,它是逐一减小问题的大小的,或者说是每次减小常数的大小。
And we saw a couple of examples of linear algorithms.
这是线性算法的典型例子,我们在过去也看过了大量的线性算法的例子。
It is certainly possible, for example, that a quadratic algorithm could run faster than a linear algorithm. It depends on what the input is, it depends on, you know, what the particular cases are. So it is not the case that, on every input, a linear algorithm is always going to be better than a quadratic algorithm.
一个二次平方级复杂度的算法,当然也是可能跑的比线性复杂度算法快的,这取决于,你知道的,输入以及特定的案例,因此并不是对于每个输入,线性复杂度就一定会,比二次平方级复杂度的算法的表现要好,只是通常来说是这样的。
I've got to count my way down, which means that the access would be linear in the length of the list to find the i'th element of the list, and that's going to increase the complexity.
的位置并去访问,然后继续下去,也就意味着,找到数组中的第i个元素的方法,是关于数组的长度呈线性复杂度的,这回增加算法的复杂度。
It would be nice if it was less than linear, but linear is nice because then I'm going to get that n log in kind of behavior.
那么就是一个不错的算法,但是线性方案也是很好的,因为我需要做n次的log级的行为。
应用推荐