On May fifteenth, just seventeen days after leaving New York, Captain Creesy wrote this in the Flying Cloud's log: "We have passed the Equator in two days less time than ever before.
VOA: special.2009.12.23
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.
但这至少证实了归并排序,的时间复杂度为。
Right? If that was the case in that code, then my complexity is no longer log, because I need linear access for each time I've got to go to the list, and it's going to Lisp be much worse than that.
这里的复杂度不再是对数的了,因为每次在列表中,查找需要线性访问,可能还要糟糕,其实,有些编程语言,如。
N log N is not nearly as good as log N. As a sanity check, what algorithm have we seen that runs in log N time?
而N,log,N和log,N并不一样,我们之前探讨过的哪个算法其时间复杂度是log,N呢?
Yeah. Log. It's a good think, but why do you think it's log? Ah-ha. It's not a bad instinct, the length is getting shorter each time, but what's one of the characteristics of a log algorithm? It drops in half each time.
对了,对数,这是个好想法,但是你们为什么认为是对数呢?,啊哈,这样的本能不错,每次长度都会缩小些,但是对数算法的特性是什么。
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 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的时间内完成,虽然目前我们没做这件事,但是一旦开始做这件事,那么复杂性就是发生一些变化。
应用推荐