A log algorithm typically is one where you cut the size of the problem down by some multiplicative factor.
对数级复杂度的算法就是指,通过一系列常量级步数的操作,可以将问题的规模。
So in fact, what does that suggest about the order of growth here? What is the complexity of this? Yeah. Logarithmic. Why?
复杂度是多少?,对的,对数级的么?,为什么呢?,学生:对数级的?
All right? It's now something that I can search in constant time. And that's what's going to allow me to keep this thing as being log.
在固定的时间内搜索,这样就可以让时间复杂度保持在对数级,好的,考虑过了这些。
It's a good sign that this is logarithmic, and I'm going to come back in a second to why logs are a great thing.
为什么对数级复杂度是个好事情,让我们再来看一个算法,噢,抱歉是让我们再来看两个算法。
Right? If that was the case in that code, then my complexity is no longer log, because I need linear access for each time I've got to go to the list, and it's going to Lisp be much worse than that.
这里的复杂度不再是对数的了,因为每次在列表中,查找需要线性访问,可能还要糟糕,其实,有些编程语言,如。
This case, I reduced the size of the problem in half.
这很好的表明了这是,对数级复杂度的问题,我马上就要解释。
Yeah. Is the last one there?
对数级复杂度的算法的优势对不对?
And as a consequence, it is log.
因此这是对数级复杂度的算法。
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个元素,是个常量时间的操作的话,我也就能像以前那样得到,这个算法是对数级复杂度的分析,并且每一步不管我选择哪个区间,我都可以把问题的规模缩小一半。
应用推荐