We said each of the merge operations O was of order n. But n is different. Right?
注意这里发生了什么,我们说过每一次合并操作的复杂度都是?
In the linear case, meaning in the unsorted case what's the complexity of this? k times n, right? Order n to do the search, and I've got to do it k times, so this would be k times n.
复杂度是多少?k的n次方,对吧?,在序列n中做搜索,要做k次,所以是k的n次方次,如果先排序后搜索。
I know it's gonna take me a lot of work on the order of N squared steps to sort these things.
要对它们排序就要进行大量的工作,大概需要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的时间去对其进行排序。
O Right there, order n. So I have order n operations at each level in the tree. And then how many levels deep am I? Well, that's the divide, right? So how many levels do I have?
在这儿,所以我在树的每个层次都要做O的操作,那个这棵有多少层呢?,这是一个除法,不是吗?
The order complexity here, if I actually write it would be-- sorry, order n times m, and if m was equal to n, that would be order n squared, and this is quadratic.
如果m等于n的话,也就是n的平方,这是一个平方复杂度的问题,这是和前面不同类型的,好,我在做什么呢?
It's going to weigh too much, we don't need to look at it. But it'll still be order 2 to the n.
我们没必要去看它,但是它还是要遵循2到n的顺序。
If you substitute it all in, you get basically order 2 to the n.
得到的是2的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的时间内完成,虽然目前我们没做这件事,但是一旦开始做这件事,那么复杂性就是发生一些变化。
应用推荐