Given the code up there, if I want to move a tower of size n, what do I have to do?
鉴于这里的代码,如果我想移动N个圆盘,我该怎么做?
And this is now consistent with my claim that I have sorted a list of size N equals 1.
这与我之前所说的是一致的,我已经将N为1的一个序列排好了序。
Where you go from problem of size n to a problem of size n minus 1.
或者缩减了2,这都一样的,也就是把问题的规模从n变成了n-1。
So if we're keeping n the same, we look and what we saw was that size actually decreases as we increase the value of l.
如果我们保持n不变,我们看到随着l值的,增大尺寸变小。
So the running time of the problem where the input is T of size N as expressed here formulaically, T of N, the running time of an algorithm, given an input of size N. You know what?
因此一个输入为N的问题的运行时间,在这儿的公式表示为,如果输入为N,那么此算法的运行时间,是多少呢?
N Well, here is a list of size N. How many times can you divide a list of size N by 2, right?
这是一个大小为N的列表,将一个大小为,的列表除以2需要几次呢?
I've got to test to see if I'm in the base case, and if I'm not, then I need to move a tower of size n minus 1, I need to move a tower of size 1, and I need to move a second-sorry about that a second tower of size n minus 1.
首先我看看我是不是在最基本的情况,如果不是的话,我得先做一个N-1个,圆盘的移动,移动一个圆盘,然后再做一次N-1个圆盘的移动。
2 6 8 1 3 7 5 If I start off with fou, two, six, eight, one, three, seven, 8 five, so my list is of size N equals 8 at the moment.
顺序如下:,现在列表的大小N等于。
If I want to move this stack here, I'm going to take a stack of size n minus 1 move it to the spare spot, now I can move the base disk over, and then I'm going to move that stack of size n minus 1 to there. That's literally what I did, OK?
如果我想移动这些圆盘,我先把从n-1个圆盘1,移动到多余的柱子上去,这样我就能把最底下的圆盘放到这儿了,然后再把从n-1个圆盘放到这儿来,这就是确切的我怎么做的对不对?
And how about if the array is size N, and I say bracket N, where am I referring?
如果那个数组的大小为N,那会怎么样,我指明,涉及到了那个地方?
And now I have a problem of size N minus 1.
现在是一个N-1大小的问题。
And we said that was log rhythmic, took log n time where n is the size of the list.
当列表的长度为n的时候,整个算法耗时log,n的时间。
So we say if n increases, the orbital size is also going to increase.
轨道的尺寸,也增大了。
Down here, I've just got two things to merge, and then I've got things of size two to merge and then things of size four to merge. But notice a trade off. I have n operations if you like down there of size one.
但是n的大小是不同的,是吗?在这里我们只要合并两个元素,然后是合并长度为2的列表,接下来是合并长度为4的列表,但是观察一下之间的权衡关系。
Up here I have n over two operations of size two. Up here I've got n over four operations of size four.
最下面有n个规模为1的操作,接着上面有n/2个规模为2的操作,再上面有n/4个规模为4的操作。
If I'm running at nanosecond speed, 1000 n, the size of the problem, whatever it is, is 1000, and I've got a log algorithm, it takes 10 nanoseconds to complete.
如果这个问题的规模,也就是n,是,如果这个问题是对数级的,这将会占据10纳秒的时间,你一眨眼的时间。
So I propose this as a new algorithm for sorting N elements and being 8 in this case or really a thousand in the case of the phonebook, or anything of larger size.
所以我提出一种新的算法,来解决N个元素的排序问题,在这个问题中N是8,在电话簿的问题中N是一千,或者是大规模的任何问题。
I now have a list of size 1 so N is, in fact, less than 2.
现在序列的大小是1,可见N小于。
On the other hand, we've seen n that if the size of a is n, that's to say, we have n elements to choose from, then the number of possible subsets is 2 to the n.
另一方面,我们看到,如果a集合的大小是,也就是说我们有n个元素可供选择,而可能的子集的元素,个数就是2的n次方。
应用推荐