Although we run it on a laptop so that we can monitor its operation, the algorithm itself doesn't require a lot of computer power and could easily be run from a chip that has the capabilities of one that's already in insulin pumps or in cell phones."
VOA: standard.2010.04.15
So I'm going to solve this by enumerate and check, which is an example of what's called a brute-force algorithm.
你懂的,所以我得靠列举和检验来解决这个问题,这就是我们说的穷举算法。
Cut the problem in half. Cut the problem in half again. And that's a typical characterization of a log algorithm.
是每次除以特定的量,将问题减一半,再减一半,如此,这就是对数算法的典型特性。
Now, as obvious a statement as that is in this algorithm, it turns out that is the key to this whole problem being solved correctly without my algorithm looping infinitely.
这是此算法中很明显的一句话,也是正确解决,整个问题的关键,否则此算法就会陷入死循环。
It couldn't have been a very complicated algorithm because it basically paired people up randomly on the campus.
这个算法不是很复杂,基本上是给校园里的人随机配对。
A log algorithm typically is one where you cut the size of the problem down by some multiplicative factor.
对数级复杂度的算法就是指,通过一系列常量级步数的操作,可以将问题的规模。
We started off talking about binary search, and I suggested that this was a log algorithm which it is, which is really kind of nice.
我告诉了你们这是一个对,数级的算法,这是很棒的,我们来一起看看这个算法到底做了什么。
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.
你可能还会依稀记得,高中数学里的对数,这就给了我们这些计算机科学家们,一些启示,即,这种算法更智能,更迅速。
Obviously the algorithm is likely to depend on the size of the input, so this is not a great idea.
很明显这个算法是与我的,输入的大小相关的,因此这不是个好方法。
And that's because that is a version of a divide and conquer algorithm.
这个想法非常重要,因为这就是分而治之算法的一个版本。
Where those pieces, I would do the same thing with, I would divide them up into smaller chunks, and sort those. Is that going to give me a more efficient algorithm?
合并起来,而那些小列表,我又会把他们拆成更小的列表,再排序,这会给我,一个更高效的算法么?
So this is a nice little search-- sorry, a nice little sort algorithm . And in fact, it's relying on something that we're going to come back to, called the loop invariant.
恩,这是一个很棒的小搜索,抱歉,和很棒的小排序算法,事实上,它依赖于一些我们要回顾的东西,被称作循环不变量。
All right? Because if I don't do any swaps on a pass through the algorithm, then it says everything's in the right order.
好么?因为如果我,这一遍没有做任何交换,那么就意味着已经排好序了。
If I'm running a quadratic algorithm, it'll take one millisecond to complete.
算法会在1毫秒内完成,如果问题的复。
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.
并且我们也很喜欢对数算法,因为它很快,对数算法的典型特性是高速,哦,抱歉,是他能以常数因子的速度,降低问题的大小,很明显。
And so ease of implementation is actually a very compelling -- metric against which to measure-- -- do you mind toning my voice down a bit-- is a very reasonable measure against which to measure the quality of an algorithm, right.
如此简单的实现实际上是一个很牵强的,度量,与之相对的衡量是-,如果你们不介意,我降低点音量-,是一种用来度量算法质量的,合理的方法。
They are computationally challenged, meaning, at the time they were invented, they were perfectly good sorting algorithms, there are better ones, we're going to see a much better one next time around, but this is a good way to just start thinking about how to do the algorithm, or how to do the sort.
他们是相当棒的排序算法,是有更好的算法,我们下一次,就会看一个更好的,但是开始想想,如何完成算法,或者说是如何排序,是一个好的学习方法,恩,再试试吧,如何来排序呢?
Well, we saw the teaser in terms of that animation that suggests this merge sort algorithm when implemented by a computer is absolutely faster.
我们从前面的动画中可以看到,这个归并排序算法在计算机上实现之后,绝对比其他算法更快。
And probably the obvious thing you'll think about is, we'll come up with a clever algorithm. And I want to disabuse you of that notion.
可能你想到的最有效的方法,就是设计一个,聪明点的算法了,这正是我想你们注意到的。
A really nice algorithm. As I said, an example of divide and conquer.
真的很好的一个算法,就如我说的。
PROFESSOR: Great question. So the question is, how do you choose an algorithm, why would I choose to use a pseudo-polynomial algorithm when I don't know how big the solution is likely to be, I think that's one way to think about it.
教授:问得好,所以问题是,你怎样选择算法,为什么当我,不知道解决方案会有多大的时候,我要选伪多项式算法呢,我想这是一种思考问题的方式。
We saw this with the sock algorithm a moment ago.
我们前面看到了袜子算法。
Because the algorithm I proposed is going to leverage this idea of recursion which recall was just a piece of jargon we tossed out at the last-- at the end of last week's lecture, last time's lecture recursion really in this context refers to the act of a function calling it's self.
因为我提出的这种算法使用了,递归的思想,这是上周课程的最后,所提出的一个术语,上次的课程中,递归是指,函数的自我调用。
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.
不仅仅是做搜索,还可以解决一整类问题,本质上,这个模板就描述了,对数形的算法,我们一会再回来。
Where have we implemented a greedy algorithm, or have been asked to do a greedy algorithm? Well, there are not that many things you guys have been working on this semester.
现在你已经实施了一个贪婪算法,我们在哪里实施了贪婪算法,或者我们那里被要求实施贪婪算法呢?,们这学期不需要用什么功对吧?
If I'm running a linear algorithm, it'll take one microsecond to complete.
算法会在1微秒内完成,如果是一个平方级的方法。
And we can just extrapolate in a straight line We before saw some examples where I had an algorithm to generate points, and we fit a curve to it, used the curve to predict future points and discovered it was nowhere close.
我们可以干脆用一条直线来描述它,我们之前看到在一些例子中,我用一个算法去生成一些点,然后用一条曲线对它进行拟合,然后用这条曲线来预测未来的点,最后却发现结果完全不对。
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.
我们学习过了线性算法,它的典型特征,不是通用的,但是比较典型的特征是,它是逐一减小问题的大小的,或者说是每次减小常数的大小。
At the University of Minnesota, a computer algorithm paired people up.
在密尼苏达州立大学,通过计算机算法将同学分组。
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.
一个二次平方级复杂度的算法,当然也是可能跑的比线性复杂度算法快的,这取决于,你知道的,输入以及特定的案例,因此并不是对于每个输入,线性复杂度就一定会,比二次平方级复杂度的算法的表现要好,只是通常来说是这样的。
应用推荐