In fact, better than that, this guy is already sorted as well because I whittled that problem down to size 1.
事实上,更好的结果是这个杯子也是有序的了,因为我已将这个问题的规模削减到只有1个元素。
A log algorithm typically is one where you cut the size of the problem down by some multiplicative factor.
对数级复杂度的算法就是指,通过一系列常量级步数的操作,可以将问题的规模。
It implies that this algorithm is calling itself again and again, and again, and on each time the size of the problem I'm trying to sort is being divided by what?
这就说明此算法会一次又一次地调用自己,每次我要排序的问题规模大小,会除以多少呢?
I think that as organizations grow, a lot of the issues and structure that's put in place is put there because a comfort level breaks down and people communicating freely in a way that they can when they're friends.
随着企业规模的扩大,会产生许多问题,需要某种组织结构,因为那种缓和的关系被打破,人们可以自由交谈,就像好友一般。
Does it really matter to you whether your code is going to take 300 years or 900 years to run?
或者900年区别大么?,这个数字的规模才是问题关键所在?
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.
有问题么?,线性复杂度的算法,当进行了一个,常量级步数的操作的时候,将问题的规模缩小了一个。
And I'm going to show you an example in a 1 second, just to drive this home, but notice the characteristics. In the first two cases, the problem reduced by 1 at each step.
在前面两个例子里,每一部问题的规模缩小了,不管是迭代的还是递归的,这表明这个问题的复杂性可能是线性的。
But the problems can grow much faster than you can get a performance boost out of the computer.
对,电脑运行速度是很快,但是问题的规模增长的。
What we really want to worry about is, as the size of the problem gets larger, how does this thing grow? How does the cost go up?
随着问题规模的变大,解决问题花费的代价是怎么增长的,因此我们将会主要地讲讲?
If it's at that point, I'm done, if not, if it's greater than the value I'm looking for, I either take one half or the other.
那么我就取左边,否则的话就取右边,好,你们可以明白,我们一次就可以缩小问题规模的一半了吧。
We took the problem of size a thousand, we divided it in half.
当我们遇到一个规模为一千左右的问题时,会将其分为两部分。
Now. You might look at that and say, well that's just a lot like what we had over here Right? We had some additive constant plus a simpler version of the same problem reduced in size by 1.
现在你可能会看着这个说,这很像我们以前做过的,对不对?我们用一些附加的常量,加上问题的另外一个规模缩小了1的,简化版本来代替这个问题本身。
Because there, I'm done, if not, I'm either looking here or there.
我一直在把问题的规模变小,好,说过了以上。
The printout is simply telling me, what are the ranges of the search.
你可以看到这个方法每次都将,原问题的规模缩小了一半。
How does this thing grow as I make the problem size big?
也就是说当问题规模变大的时候,算法计算的时间会怎样增长?
Again, if you didn't hear it, the answer was it's log.
因为每次我可以把这个问题的规模,缩小一半,你答对了。
But in one step, I've reduced this problem in half.
我就将这个问题的规模减半了,我不仅仅是缩小了问题的规模。
I'm using exactly the same form to reduce this.
我用的同样的方法来减少问题的规模。
Because if b was odd, then b minus one is even which means on the next step, I can cut the problem in half again.
这意味着我在下一步里解决的问题,规模要小了一半,好,课堂材料的第三题。
In fact, it took the same number of steps as it did in the other case, because each time I'm cutting it down by a half.
因为每次我都把问题的规模,缩小一半,这很棒,好,接下来让我们这么做。
Wow. I think it took one more step.
我把问题的规模扩大了十倍。
That's a sign that it's probably linear.
我可以两步把问题的规模缩小一半。
Taking the problem, recognizing that you know what, 8 even though this is a pretty big problem size 8 in this case and last time it was size 8 or in the case of the papers in size of a thousand roughly with the phonebook, I assume these are in a perfectly straight line they won't quite fit.
以这个问题为例,你们要认识到,在这种情况下,这是个比较大的问题,其大小是,上次它的大小也是8,但在纸片那个问题中,电话簿的规模大概是上千的,现在假设这些,杯子完全在同一条直线上,虽然并不十分符合这个条件。
If I'm running at nanosecond speed, 1000 n, the size of the problem, whatever it is, is 1000, and I've got a log algorithm, it takes 10 nanoseconds to complete.
如果这个问题的规模,也就是n,是,如果这个问题是对数级的,这将会占据10纳秒的时间,你一眨眼的时间。
Where you go from problem of size n to a problem of size n minus 1.
或者缩减了2,这都一样的,也就是把问题的规模从n变成了n-1。
With this, if I can assume that accessing the i'th element of a list is constant, then you can't see that the rest of that analysis looks just like the log analysis I did before, and each step, no matter which branch I'm taking, I'm cutting the problem down in half.
读取数组中的第i个元素,是个常量时间的操作的话,我也就能像以前那样得到,这个算法是对数级复杂度的分析,并且每一步不管我选择哪个区间,我都可以把问题的规模缩小一半。
应用推荐