Cut the problem in half. Cut the problem in half again. And that's a typical characterization of a log algorithm.
是每次除以特定的量,将问题减一半,再减一半,如此,这就是对数算法的典型特性。
A log algorithm typically is one where you cut the size of the problem down by some multiplicative factor.
对数级复杂度的算法就是指,通过一系列常量级步数的操作,可以将问题的规模。
It's an example of a very common tool that's going to be really useful to us, not just for doing search, but for doing a whole range of problems. That is, in essence, the template the describes a log style algorithm.
不仅仅是做搜索,还可以解决一整类问题,本质上,这个模板就描述了,对数形的算法,我们一会再回来。
and we like log algorithms, because they're really fast. A typical characteristic of a log algorithm is a pro-- or sorry, an algorithm where it reduces the size of the problem by a constant factor.
并且我们也很喜欢对数算法,因为它很快,对数算法的典型特性是高速,哦,抱歉,是他能以常数因子的速度,降低问题的大小,很明显。
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.
为什么对数级复杂度是个好事情,让我们再来看一个算法,噢,抱歉是让我们再来看两个算法。
We've seen log, we've seen linear, we've seen quadratic, we've seen exponential.
我们看过了对数级的,线性的,二次平方的,指数级的算法。
In the log case, it's divide by an amount.
而在对数算法中。
Yeah. Is the last one there?
对数级复杂度的算法的优势对不对?
We also saw a logarithmic algorithm.
我们也看过对数算法。
And as a consequence, it is log.
因此这是对数级复杂度的算法。
Yeah. Log. It's a good think, but why do you think it's log? Ah-ha. It's not a bad instinct, the length is getting shorter each time, but what's one of the characteristics of a log algorithm? It drops in half each time.
对了,对数,这是个好想法,但是你们为什么认为是对数呢?,啊哈,这样的本能不错,每次长度都会缩小些,但是对数算法的特性是什么。
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个元素,是个常量时间的操作的话,我也就能像以前那样得到,这个算法是对数级复杂度的分析,并且每一步不管我选择哪个区间,我都可以把问题的规模缩小一半。
Perhaps more importantly, how to recognize a kind of algorithm based on its properties and know what class it belongs to. This is a hint. If you like, leaning towards the next quiz, that you oughta be able to say that looks like a logarithmic algorithm because it's got a particular property. That looks like an n log n algorithm because it has a particular property.
也许更重要的是,如何根据一个算法的特点将其辨别出来,并且知道它属于哪一类算法,这是一个提示,就对于接下来的测验来说,如果你喜欢你可以说它看起来像一个对数算法,因为它有一个特定的性质,那个看起来像一个n,log,n的算法,因为它有一个特定的性质。
应用推荐