OK. What would you guess the order of growth here is? Yeah. Why? Good. Exactly. Right?
如果没听到答案的同学,答案是对数级的?
Cut the problem in half. Cut the problem in half again. And that's a typical characterization of a log algorithm.
是每次除以特定的量,将问题减一半,再减一半,如此,这就是对数算法的典型特性。
You might remember vaguely logarithms from high school math and such but what this suggests for us , the computer scientists, is that this is certainly a smarter, a faster algorithm.
你可能还会依稀记得,高中数学里的对数,这就给了我们这些计算机科学家们,一些启示,即,这种算法更智能,更迅速。
And if you look at this series, the series log of one, what is the series expansion?
如果你们看这个式子,它的对数分之一,它的指数是多少?
The integral of one over a quantity is the natural log.
这种形式的积分结果,是自然对数。
For example, this is x=t, x=t^, you're going to have x=sin t and cos t and log t.
例如,这是x=t,x=t^,你还会遇到正弦,余弦,对数函数
So, this is several months and this logarithmic scale on the Y-axis represents antibody concentration.
这是在几个月内,这里使用的是对数刻度,Y轴代表的是抗体的浓度
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.
不仅仅是做搜索,还可以解决一整类问题,本质上,这个模板就描述了,对数形的算法,我们一会再回来。
So in fact, what does that suggest about the order of growth here? What is the complexity of this? Yeah. Logarithmic. Why?
复杂度是多少?,对的,对数级的么?,为什么呢?,学生:对数级的?
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.
为什么对数级复杂度是个好事情,让我们再来看一个算法,噢,抱歉是让我们再来看两个算法。
Wrev So minus w reversible, 1 p2 is less than p1, so p2 over p1 is less than one, log of something less than 1 is negative times negative.
那么,而p2小于p1,p2/p1小于,取对数后是负数,负负得正。
N 6 Sixteen, so that's 16 times log base 2 of 16 and though I'm writing small here, log base 2 of 16, 16 this gives me 4 'cause 2 to the 4 equals 16.
是多少呢?,Well,,N,is,what?,16,那就是16乘以以2为底16的对数6,在这儿我将2写小一些,以2为底16的对数是4,因为2^4等于。
It's nR log of p2 over p1 for the process where there's a pressure change.
结果是dS等于nR乘以p2除以p1的对数,这是对压强变化的结果。
Thank you. I mean, I know I sort of said it to you, but you're right. It's logarithmic, right?
但你们是正确的,是对数级的,它有这样的效率是因为他每次能把问题减半?
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.
并且我们也很喜欢对数算法,因为它很快,对数算法的典型特性是高速,哦,抱歉,是他能以常数因子的速度,降低问题的大小,很明显。
Let's suppose n is 1000, and we're running at nanosecond speed.
假入我们一秒钟运算十亿次,我们已经看过了对数级,线性增长的。
OK. There's some constants in there, but this is order log b.
对数级的,这太重要了,接下来我要给你们看个例子。
This case, I reduced the size of the problem in half.
这很好的表明了这是,对数级复杂度的问题,我马上就要解释。
It's got that property of, it cuts things in half.
换个角度来思考下为什么是对数级的。
Log? Linear? Exponential? Quadratic?
对数?线性?指数?平方?
We've seen log, we've seen linear, we've seen quadratic, we've seen exponential.
我们看过了对数级的,线性的,二次平方的,指数级的算法。
What does a logarithmic running time look like?
这个对数函数是怎样的?
In the log case, it's divide by an amount.
而在对数算法中。
But mathematically, we've mentioned this before, log N or really to be precise, log base 2 of N, is the way you express this mathematically.
但从数学上说,之前我们已经提到过了,准确地说是log,N,以2为底N的对数,这就是它在数学上的表示。
And as a consequence, it is log.
因此这是对数级复杂度的算法。
We also saw a logarithmic algorithm.
我们也看过对数算法。
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个元素,是个常量时间的操作的话,我也就能像以前那样得到,这个算法是对数级复杂度的分析,并且每一步不管我选择哪个区间,我都可以把问题的规模缩小一半。
So it's nR log V2 over V1.
结果是nR乘以V2除以V1的对数。
应用推荐