The idea behind all these algorithms is that what's ultimately important is how many comparisons you ultimately need to make.
这些算法的思想是,你最终需要做多少次的比较,这才是真正重要的。
So in fact, over the next thirty or forty minutes we're going to show you a set of examples of sort of canonical algorithms, and the different classes of complexity.
在接下来的三四十分钟里面,我们将要讲一系列的,权威算法,以及不同种类的复杂度问题。
And the reason for the scale is -- that as we saw last week the idea of these algorithms-- I broke the scale already.
之所以要用到它,是因为上周我们讨论的这些算法思想-,我把天平弄坏了。
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.
有问题么?,线性复杂度的算法,当进行了一个,常量级步数的操作的时候,将问题的规模缩小了一个。
One of the things we want to help you do is identify the different classes of algorithms, what their costs are, and how you can map problems into the most efficient class to do the computation.
我们想要教会你们的事情之一就是,学会辨别不同种类的算法,它们的代价是怎么样的,以及怎么样把问题映射到,最有效的算法种类中去做计算。
OK. Binary search is perhaps the simplest of the divide and conquer algorithms, and what does that mean? It says, in order to solve a problem, cut it down to a smaller problem and try and solve that one.
好了,二分搜索也许是,最简单的分治算法,这意味着什么?,也就是说,为了解决一个问题,把它切割成小的问题,然后再来一个个解决。
And then we're going to turn to the question of efficiency. How do we measure efficiency of algorithms? Which is going to be a really important thing that we want to deal with, and we'll start it today, it's undoubtedly going to take us a couple more lectures to finish it off.
然后我们会回头继续讨论效率问题,我们如何计算算法的效率?,我们处理这些问题的时候,最重要的事情是什么?,我们今天要去讨论这个问题,毫无疑问我们要用,挺多节课来学习这个。
Alright, so we can implement any number of algorithms using this thing because the basic mechanism I have here is a comparator.
好了,利用它我们可以实现,很多种算法,因为在此我用到的基本原理是一个比较器。
I want you to recognize classes of algorithms and match what you see in the performance of the algorithm to the complexity of that algorithm. All right?
让我再试一次这么说,我期望大家能通过,算法的复杂度,来看到算法的性能?
What have we done over the last three or four lectures? We've started introducing you to classes of algorithms. Things that I'd like you to be able to see are how to do some simple complexity analysis.
我们在过去三节或四节课中讲了什么?,我开始向你们,介绍算法的类型,我想你们知道的是,如何做一些简单的复杂度分析。
And we haven't seen all of these sorts, but it's actually quite neat to recognize how different the underlying work is of each of these algorithms.
我们还没有探讨所有的排序算法,但应该很容易区分,每一种算法其内在的,不同之处。
What you're much better at doing is saying how do I take the problem I've got and map it into a class of algorithms about which I know and use the efficiencies of those to try and figure out how to make it work.
当你碰到问题的时候,更好的方法是把遇到的问题映射,到已经设计好的算法中去,并用这些算法来提高效率,来保证问题得到解决。
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.
他们是相当棒的排序算法,是有更好的算法,我们下一次,就会看一个更好的,但是开始想想,如何完成算法,或者说是如何排序,是一个好的学习方法,恩,再试试吧,如何来排序呢?
One of the things you should begin to do, is to recognize what identifies those classes of algorithms, so you can map your problems into those ranges.
你们现在开始要做的事情之一,就是要学会辨别这些算法,这样你就能为你的问题,选择对应种类的算法了。
But I want you to take away from this how we reason about the complexity of these algorithms. And I'll remind you, we said we're going to mostly talk about time.
但是我想你们理解我们,是怎么推出这些问题的复杂度的,提醒大家,我说过了我们主要讨论时间问题。
Selection sort too really reduces to a total number of comparisons because I'm again comparing the current smallest to the next thing I see, the next thing, so really a lot of these sorting algorithms boil down to comparisons and the numbers that you actually have to make.
选择排序也可归纳为总数的比较,因为要将当前最小者与下一个进行比较,接着再下一个,可见,很多排序算法都可归结为比较,以及需要比较的次数。
OK. Today, for the rest of the lecture, we're going to take a break from the topic of algorithms, and computation, and things of the sort. And do something pretty pragmatic.
好,今天剩下的时间里,我们不再讲算法,计算和排序这些话题了,我们会做一些非常实用的事,我们主要的讲讲测试。
And part of it is we want you to learn how to have a catalog, if you like, of different classes of algorithms, so that when you get a problem, you try and map it into an appropriate class, and use the leverage, if you like, of that class of algorithms.
另外我希望你们能学会,如何制作一个关于,算法不同课程的目录,这样当你碰到问题的时候,你可以去找到合适的课程,然后在那门课程中,寻找解决方法。
And if you ask the TAs in recitation tomorrow, they'll tell you that you see a lot of n log n algorithms in computer science.
如果你明天在复习课上问助教的话,他们会告诉你在计算机科学中,存在着非常多的n,log,n规模的算法。
Let me show you one more class, though about-- sorry, let me show you two more classes of algorithms. Let's look at the next one g- and there's a bug in your handout, it should be g of n and m, I apologize for that, I changed it partway through and didn't catch it.
请大家看,额,在你们的课堂材料中有个错误,应该是g,很抱歉-,我改了一部分这个错误但是没看到这里的,好,这儿的增长率,有人想猜猜么?
应用推荐