Whereas in the linear case, I make it ten times bigger, it takes ten times longer to run. OK.
它要占用原来十倍的时间去运行,我一直在说还有一件事情没有讲,这是我要强调的最后一件事。
So in fact if I run this, ah, and save it, and it prints out odd.
因此实际上如果我运行这个,啊,先保存它,然后它输出奇数。
GCC -o So, on the one hand, I've run this command here, GCC dash O and this projector I'm highlighting things all day long on the screen here and you're not seeing any of it unfortunately it seems on this projector.
我在这运行了一条命令,这台投影仪我一天到晚的开着,一再强调屏幕上的东西,不幸地,你们却,在投影仪上没有看到它。
I feel pretty good about this, and in fact I ran it a lot of times in my office.
我觉得这很好,实际上我在自己的办公室也运行了很多次。
And the obvious question I could start with is, and suppose I ask you, how long does the algorithm implemented by this program take to run?
我开始这个话题的第一个问题是,假设我问你,由这个算法实现的程序大概,要运行多久才能给出答案?
And in fact if I go off and run this, OK, what I was printing here was s 1 dot length, and that's -- What is it doing?
他们就是一些有结构的实例,实际上如果我去运行下这个,好,我这里输入的?
And I'm going to pause for a minute, before I run it, and ask each of you to compute in your head what you think the answer should be.
我将暂停一会儿,在我运行之前,我想问问你们你们,心算得出的答案应该是什么。
Let's assume, for sake of argument, the thing I'm looking for is bigger than this. In that case, I'm going to throw away all of this, I'm going to hit that bottom line of that code.
让我们假定不是,假定要找的元素,比这个大,在这样的情况下,这些都擦掉,我要运行到代码的最后一行。
OK. Having done this now, I can simply go ahead and run this, and in fact if I go up here to run, you'll see I've got both an option to check the module, though in this case I'm just going to run it.
好,讲完了这些,我可以去执行程序了,实际上如果我在这里运行,你们会看到我同样得到了,一个可以同时检查模块的选项,虽然在这个例子中我就是直接去运行程序了。
And so what I see is that as I run this, I'm doing a lot of redundant computation.
因此我在这里,看到的是随着我的运行,我将会进行很多冗余的计算。
But, just to be sure, not to be sure, but just to increase my confidence, I'm going to just run it again.
所以说它是对的是很有道理的,但是,确定一下,但是为了提高我们的自信,我要再运行一次。
So, let's see this eraser actually never works very well so I'm just going to draw below it.
这个清除器不能很好地运行,我将在下面画出它。
OK, what I would like you to see is I've been printing out, as I went along, actually let's back up slightly and look at the code. There's merge sort.
好的,我想让你们看就是我运行过后,打印出来的结果,我们再回头看一下这段代码,这就是归并排序,输入一个列表。
When the program is on your computer you say dot slash and this means on my computer.
当程序位于你的电脑上时,敲入,就意味着在我的电脑上运行。
Notice one last piece. If I'm going to do that, run through all possible answers, I still want to know, gee, what if there aren't any answers? How do I return that case?
注意最后一段,如果我要这样做,也就是运行所有可能的答案,我还是想知道要是没有结果呢?,在这个例子中应该返回什么呢?
Code is right here. And all it's doing is when I'm getting into the different places I'm simply printing out information about where I am. What I want you to see palindrome is notice what happened here.
代码就在这儿,它的作用是当我运行到不同地方时,就输出我所在方位的信息,我想让你们看的就是注意这儿发生了什么,好了我调用了一个。
And the problem is, that we want to build this abstract data type, but we'd like to basically know what kind of object is it, and what functions actually belong to it, how do we use them?
然后我对它们运行了这个方法,就是这一小段代码这个方法,这有意义么?,当然没有了,对不对?,因为你知道,当你把两个极坐标,表示的点进行相加运算的时候?
So how long it takes to run is related to how many items I end up being able to fit into the knapsack.
所以,运行的时间是和我能够,装进背包的物品数目有关的。
I'm going to go over here, and let me define a couple of these things.
仅仅是用来显示值的,好,让我们看看如果,我运行这个程序会有什么结果。
And I'm going to run it in a sec, but you can see, the same kind of idea.
我马上要去运行它,但是你们会明白,思想是一样的。
I should really just put it in a nice test harness, where I run 100, 200, 1,000 trials, but I didn't want to bore you with that here.
我应该把它放到一个测试组件中,我运行100次,200次,1000次,但是我现在不想用这个来烦你们。
So you can imagine that this is a very powerful mechanism. So let's look what happens when I run-- start to run this.
因此你可以想到这是一种很强大的机制,让我们看看让我开始运行,这个程序的时候会有什么结果。
So now when I compile this fourth version with make math4 1 31 and then run math4, I indeed get 1.31.
所以现在我键入“make,math4“来编译第四个版本4,然后运行math4,我得到了。
Nonetheless, having done that, let's look at what I'm going to do. I now want to run a loop where I need to collect things together.
尽管如此,讲完了这些,让我们去看看,我将要进行的操作,我想要运行一个,需要把东西收集起来的循环,我要命名它。
So before I try and run my program, I test each part of it independently.
因此在我尝试运行我的程序之前,我都会对它的每个部分进行独立的测试。
I can tell you the answer, but that's because I've cheated, run the program before.
我可以告诉你答案,但这是因为我作弊了,我之前运行过一次程序。
In fact, if I ran one of these things, it would just keep crunching away.
我们主要来谈谈时间问题,实际上,让我运行这些东西。
math2 But the point for now is just to run math2, which I just did.
但是现在的任务只是运行我刚写的。
And so when I run this program, nothing all that interesting happens.
所以当我运行这个程序,没有什么会发生。
Or, said a different way, what's going to happen when I run it?
或者,用不同说法来讲就是,当我运行它的时候会发生什么?
应用推荐