What's the complexity of this decision tree solution? Well, in the worst case, we're enumerating every possibility of in and out.
决策树解决方法的复杂度是多少?,在最糟的例子中得列举,所有可能的输入和输出。
Therefore, for simple branching programs, the length of time, the complexity the code, is what we would call constant.
因此,对于简单的分支程序,运行的时间长度,算法的复杂度,也就是我们说的常数。
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.
但这至少证实了归并排序,的时间复杂度为。
I mention this because such complications ? should alert the careful reader. Right?
我提到这个是因为这样的复杂度,是细心读者应要留神的地方,对吗?
Linear algorithms tend to be things where, at one pass-through, you reduce the problem by a constant amount by one. If you reduce it by two, 1 it's going to be the same thing.
有问题么?,线性复杂度的算法,当进行了一个,常量级步数的操作的时候,将问题的规模缩小了一个。
But that's also nice, it lets you see how the recursive thing is simply unwrapping but the complexity in terms of the amount of time it takes is going to be the same.
它让我们看到了,在复杂度依照时间总数来看,没有变化的情况下,递归是怎么一步步的展开的,我欠你一个糖,谢谢。
Now you might say, wait a minute. Thing's ordered, if I stop part way through and I throw away half the list, doesn't that help me? And the answer is yes, but it doesn't change the complexity.
如果我在半路上停下来,然后不去遍历剩下的数组了,这会有帮助么?答案是有帮助,但这没法改变算法的复杂度,因为我们之前怎么说来着?
So in fact, what does that suggest about the order of growth here? What is the complexity of this? Yeah. Logarithmic. Why?
复杂度是多少?,对的,对数级的么?,为什么呢?,学生:对数级的?
We said each of the merge operations O was of order n. But n is different. Right?
注意这里发生了什么,我们说过每一次合并操作的复杂度都是?
All right? It's now something that I can search in constant time. And that's what's going to allow me to keep this thing as being log.
在固定的时间内搜索,这样就可以让时间复杂度保持在对数级,好的,考虑过了这些。
The message I'm trying to get to here, because I'm running you right up against time, is I have to be careful about what's a primitive step.
我想说的事情是,因为我正在跟大家讲算法时间复杂度,我们需要注意一个基本步骤的定义,如果我可以假设。
What have we done over the last three or four lectures? We've started introducing you to classes of algorithms. Things that I'd like you to be able to see are how to do some simple complexity analysis.
我们在过去三节或四节课中讲了什么?,我开始向你们,介绍算法的类型,我想你们知道的是,如何做一些简单的复杂度分析。
I ask you for the running time of this algorithm and you give me the running time in terms of the running time, right.
我需要得到此算法的时间复杂度,那就明确地给出其,运行时间。
Ah, n times, because for each value of i, I'm going to do that m thing, n*m so that is, close to what you said, right?
因此这就和你说的差不多了对不对?,这个问题的复杂度为,让我写下来,是-对不对,是?
But I want you to take away from this how we reason about the complexity of these algorithms. And I'll remind you, we said we're going to mostly talk about time.
但是我想你们理解我们,是怎么推出这些问题的复杂度的,提醒大家,我说过了我们主要讨论时间问题。
This gentleman has helped me out. Somebody else help me out. What's the complexity here?
还有一个人帮我讲下么,这里的复杂度是多少?
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.
这里的复杂度不再是对数的了,因为每次在列表中,查找需要线性访问,可能还要糟糕,其实,有些编程语言,如。
I make the problem ten times bigger, it takes one more step to do it.
而在线性复杂度的算法里,我把规模扩大十倍。
And so, I get some power. I get the ability to store arbitrary things, but what just happened to my complexity?
但是复杂度变了,找到第k个元素,要花多少时间呢?
So you can see, even the quadratic ones can blow up in a hurry.
如你所见,甚至平方级复杂度的方法。
Right? You can see that this ought to be linear, because what am I doing?
这个算法应该是线性复杂度的,因为这个算法是怎么执行的呢?
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?
只需要遍历列表,每次找出最小的元素,然后重复上述步骤,但从数学角度看,选择排序的时间复杂度,又是多少呢?
This case, I reduced the size of the problem in half.
这很好的表明了这是,对数级复杂度的问题,我马上就要解释。
All right, having said that, what's the complexity here?
好了,说了这些了,这里的复杂度是多少?
Now. What's the order of growth here?
这里的增长率是多少,复杂度呢?
You can actually say big O of 1, big O of 1 being constant time, the same number of steps.
其复杂度为O,表示时间是一个常量,所用的步数是相同的。
What's the complexity of this algorithm?
这个算法的复杂度又是多少呢?
Yeah. Is the last one there?
对数级复杂度的算法的优势对不对?
What's the complexity of this?
它的复杂度是多少?
It has a constant.
它就是常数级复杂度。
应用推荐