• You'll also notice that this thing goes through the entire list, even if the list is sorted before it gets partway through.

    你也能注意到,它始终会遍历列表,甚至列表排序之前,就是有序的也是这样。

    麻省理工公开课 - 计算机科学及编程导论课程节选

  • I haven't said how I'm going to get those sorted lists, but imagine I had two sorted lists like that.

    我还没有说明我怎么才能得到已排序列表,但是想像一下我现在已经有,两个已排序好序的列表了。

    麻省理工公开课 - 计算机科学及编程导论课程节选

  • So the first one here is something called insertion sort which amounts to going through the list, taking the first thing that you see and inserting that element into its correct place, - then moving on to the next one, dealing with what element-- whatever element you're given and putting it in its right place.

    首先是插入排序,在此算法中,需要遍历整个列表,将你遇到的第一个元素放在其正确的位置,然后移动到下一个元素,继续处理-,不管是什么元素,都将其插入到合适的位置。

    哈佛公开课 - 计算机科学课程节选

  • If it was an unordered list, we were basically stuck with linear search. Got to walk through the whole list to see if the thing is there.

    如果是一个未排序列表,基本上我们就只能使用线性搜索了,通过遍历整个列表来查看。

    麻省理工公开课 - 计算机科学及编程导论课程节选

  • 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?

    合并起来,而那些小列表,我又会把他们拆成更小的列表,再排序,这会给我,一个更高效的算法么?

    麻省理工公开课 - 计算机科学及编程导论课程节选

  • Merge sort takes this idea of divide and conquer, and it does the following: it says let's divide the list in half.

    归并排序以如下的步骤使用了分治思想:,把列表分成两半:,下面就是分治。

    麻省理工公开课 - 计算机科学及编程导论课程节选

  • OK, what I would like you to see is I've been printing out, as I went along, actually let's back up slightly and look at the code. There's merge sort.

    好的,我想让你们看就是我运行过后,打印出来的结果,我们再回头看一下这段代码,这就是归并排序,输入一个列表

    麻省理工公开课 - 计算机科学及编程导论课程节选

  • Again. Basic premise of binary search, or at least we set it up was, imagine I have a sorted list of elements. We get, in a second, to how we're going to get them sorted, and I want to know, is a particular element in that list..

    好,二分查找的基本前提,或者是我们建立二分查找的基础,我们已经有了一个排好序的元素列表,我们就需要知道如何来快速的排序,如何从列表中找到特定的元素。

    麻省理工公开课 - 计算机科学及编程导论课程节选

  • Let's run merge sort on it, and then we'll look at the code.

    让我们在这个列表上运行归并排序,然后我们在看一下代码。

    麻省理工公开课 - 计算机科学及编程导论课程节选

  • Well let's see. My fall back is, I could just do linear search, walk down the list one at a time, just comparing those things. OK. So that's sort of my base. But what if I wanted, you know, how do I want to get to that sorted list? All right?

    我只能做线性搜索了,一次遍历一遍列表,一个一个比较,但如果我想要,那怎样得到有序的列表呢?,现在的一个问题是,我们排序之前?

    麻省理工公开课 - 计算机科学及编程导论课程节选

  • It could be two or three times.

    恩,等一等,如果我想要排序一个列表

    麻省理工公开课 - 计算机科学及编程导论课程节选

  • So to just preface what we're going to do next time, what would happen if I wanted to do sort, and rather than in sorting the entire list at once, I broke it into pieces, and sorted the pieces, and then just figured out a very efficient way to bring those two pieces and merge them back together again?

    所以为了引导下一次,我们要讲的内容,如果我想做排序,而且不是一次吧整个列表排完,会发生什么,我把它拆成小的列表,然后把各个小列表排序,接着用高效的方法再把小的列表

    麻省理工公开课 - 计算机科学及编程导论课程节选

  • That one's not so obvious. So let's think about this for a second. To sort a list in linear time, would say, I have to look at each element in the list at most a constant number of times.

    所以让我们来思考一会,要在线性时间能排序列表里每个元素最多被使用常数次,不一定是一次,对吧。

    麻省理工公开课 - 计算机科学及编程导论课程节选

  • I could still do the linear case, which is order n or I could say, look, take the list, let's sort it and then search it. But in that case we said well to sort it was going to take n log n time, assuming I can do that.

    我仍然可以做O的线性搜索,或者也可以以这个列表为例,我们先将其进行排序,然后再进行查找,但是在这种情况下,要花费n,log,n的时间去对其进行排序

    麻省理工公开课 - 计算机科学及编程导论课程节选

$firstVoiceSent
- 来自原声例句
小调查
请问您想要如何调整此模块?

感谢您的反馈,我们会尽快进行适当修改!
进来说说原因吧 确定
小调查
请问您想要如何调整此模块?

感谢您的反馈,我们会尽快进行适当修改!
进来说说原因吧 确定