And that's the kind of instinct I'd like you to get into thinking about. So the answer here is no.
所以答案是否定的,好的,那我们能在线性时间内排序么?
What's shown in this diagram is the progress of the developing embryo as it travels in time, down the fallopian tube.
这张图上显示的,就是胚胎发育的过程,是按照它在输卵管中移动的时间排序的
It at least does corroborate the claim that merge sort N*log N as we argue intuitively is in fact, N log N in running time.
但这至少证实了归并排序,的时间复杂度为。
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.
所以让我们来思考一会,要在线性时间能排序,列表里每个元素最多被使用常数次,不一定是一次,对吧。
The Septuagint's rationale for ordering the books is temporal.
希腊译本是按时间顺序排序的。
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.
好,今天剩下的时间里,我们不再讲算法,计算和排序这些话题了,我们会做一些非常实用的事,我们主要的讲讲测试。
I just go down the list selecting the smallest person at a time and then I repeat, repeat, repeat but when we actually did out the math or kind of reason through it, the running time, the asymptotic running time of bub-- of Selection Sort was also what?
只需要遍历列表,每次找出最小的元素,然后重复上述步骤,但从数学角度看,选择排序的时间复杂度,又是多少呢?
Like what the heck have we been spending our time for-- our time on with Bubble Sort and with Selection Sort and in fact there's plenty of other N squared sorts that we're not even gonna bother looking at.
真见鬼,我们竟然在-,冒泡排序和选择排序上花时间,而事实上,还有很多我们根本都不想考虑的,复杂度为N平方的排序方法。
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的时间去对其进行排序。
On the other hand, if I want to sort it first, OK, if I want to do sort and search, I want to sort it, it's going to take n log n time to sort it, and having done that, then I can search it in log n time.
我先排序,好的,如果我想排序再搜索,我要排序,这需要花n,log,n时间排序,然后做完了,我们能花log,n时间搜索,啊,哪一种更好呢?恩,呵呵。
Once I have it sorted I can search it in log n time, but that's still isn't as good as just doing n. And this led to this idea of amortization, which is I need to not only factor in the cost, but how am I going to use it?
一旦对其完成排序,就可以在log,n的时间内对其完成搜索,但是这样做仍然不如n的复杂度,这样做引出了耗时分摊的想法,这时不仅需要考虑耗时的因素?
And this was just a formal way of describing the best case running time and in the case of Selection Sort, what was the best case running time?
这是描述最好情况下运行时间的,一种正式的方式,在选择排序中,最理想的运行时间是多少呢?
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是-,做合并的步数,对吗?
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 then one of the things that I suggested was that if we could figure out some way to order it, and in particular, if we could order it in n log n time, and we still haven't done that, but if we could do that, then we said the complexity changed a little bit.
这就涉及到了排序,如果可以想出一种来将其进行排序,甚至可以在n,log,n的时间内完成,虽然目前我们没做这件事,但是一旦开始做这件事,那么复杂性就是发生一些变化。
应用推荐