And so the fact that in this whole slide here, this algorithm for sorting, I'm using the verb sort.
在这个排序算法中,我用到了一个动词排序。
The fact that the picture is a little prettier on the far right is testament to the fact that I'm sorting the left half, the left half, the left half, and that's why you get these little triangles, triangles, triangles, that then get merged together.
可以看到最右边的画面,变化很快,先对左半部分排序,然后再左半部分,这就是为什么会有这些小三角形,最后再将它们合并起来。
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.
他们是相当棒的排序算法,是有更好的算法,我们下一次,就会看一个更好的,但是开始想想,如何完成算法,或者说是如何排序,是一个好的学习方法,恩,再试试吧,如何来排序呢?
It's sorting things based on the light frequencies, but it doesn't have the experience of seeing red.
它只是根据光频来分辨颜色而已,并没有看见红色的体验
They started having mail cars on trains and they started having postal sorting on the train.
人们开始用铁路邮政车,并且在火车上分类整理。
So if you now reverse the story that we're telling here, what was the next line supposed to be after sorting left half?
回退到这个过程中来,在对左半部分排完序后,下一步该做什么呢?
And this is where it feels like we're not really doing anything except talking about sorting.
在这儿,似乎我们并没真正做什么而只是,在空谈排序。
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. What's this thing doing then, in terms of sorting?
这是在做什么呢?排序么?,在第一遍结束的时候?
I'm sorting the right half which means sort the left half first, alright?
我对整个右半部分排序,这意味着要先对其左半部分排序,对吗?
And the context of sorting, the worst case is your handed a problem that's in complete reverse order because that implies you have - to do as more work that could possibly-- that you could-- you have to do more work than you would of course if things were in perfect order.
在排序的环境中,最糟糕的情况是待排序的序列是,完全逆序的,在这种情况下,你不得不做更多的工作-,比起一个较理想顺序的序列,你必须花费更多的努力。
OK. Having said that, let's look at doing some sorts. And I'm going to start with a couple of dumb sorting mechanisms. Actually, that's the wrong way saying it, they're simply brain-damaged, they're not dumb, OK?
我们来做些排序吧,我要开始处理一些愚蠢的排序机制,事实上,我说的不正确,他们就是没脑子,不是笨,发明出来后,他们就在不停的被挑战?
OK. Could we do better in terms of sorting?
我们在排序上可能做的更好么?
So I've done sorting of the left half.
已对左边排序。
I'm done sorting a list of size 2.
现在我已将这2杯排好序了。
Well, you need an algorithm for sorting.
你需要一种排序算法。
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?
所以为了引导下一次,我们要讲的内容,如果我想做排序,而且不是一次吧整个列表排完,会发生什么,我把它拆成小的列表,然后把各个小列表排序,接着用高效的方法再把小的列表?
So supposed that I give you 16 elements to sort, well, following the logic before, the running time involved in sorting 16 elements is gonna be twice the running time 16 of sorting 8 elements, left half and right half plus 16 - and again, a little sanity check, 16 means-- just the merge steps, right?
现在要对16个元素进行排序,根据之前的逻辑,对16个元素排序,要花的时间是对8个元素排序所花时间的,2倍,分别用于左半部分和右半部分,再加上6,这里16是-,做合并的步数,对吗?
So I propose this as a new algorithm for sorting N elements and being 8 in this case or really a thousand in the case of the phonebook, or anything of larger size.
所以我提出一种新的算法,来解决N个元素的排序问题,在这个问题中N是8,在电话簿的问题中N是一千,或者是大规模的任何问题。
So if N is not less than 2, that is I have two elements or more in which case there's definitely some sorting to be done.
因此如果N不小于2,也就是有2个或更多的元素,那当然是需要做排序的。
If I'm using algorithm that I'm now calling merge sort, T the running time involved in sorting N elements, T of N, you know, is just the same as running the algorithm for the right half, plus what's this plus N come from?
如果我用归并排序算法,对N个元素其运行时间,就等于此算法一半元素的运行时间,另一半的运行时间,再加上N,这个N是什么呢?
And that's just a way of reminding you that we want to think carefully, but what are the things we're trying to measure when we talk about complexity here? It's both the size of the thing and how often are we going to use it? And there are some trade offs, but I still haven't said how I'm going to get an n log n sorting algorithm, and that's what I want to do today.
这只是在提醒你们我们要仔细的思考问题,但是当我们在讨论复杂性的时候,我们到底要衡量哪些东西?,是列表的大小和对其进行查找的频率吗?,这里面临一些取舍,但是我还没有说明,怎样得到一个n,log,n复杂度的排序算法,并且这是我今天想要讲的内容。
应用推荐