In week zero, when we tore the phonebook in half and half and half we were recursing through that problem.
当我们将电话簿划分为一半又一半的时候,其实就是利用递归在解决问题。
And there was an idea that we exercised with the phonebook which was this notion of dividing and conquering.
我们在进行电话簿实验时用到了一种思想,它就是划分和征服。
So binary search, the phonebook example, binary search on the pieces of paper on the white board, why is that?
是二分查找,例如电话簿的例子,对其中的某一页进行二分查找,为什么呢?
That the phonebook was sorted alphabetically and that the array of numbers on the board behind the second row of paper itself was sorted alphabetically.
电话簿是按照字母顺序排列的,而且黑板上第二排后面的一系列数字,也是按字母顺排列的。
In the phonebook, I just kept dividing and dividing Mike Smith and dividing into half and in the end I found Mike Smith 50 or I found the number 50.
在电话簿的例子中,我先将其划分为两部分,接着再划分,最后就可以找到,或者数字。
Taking the problem, recognizing that you know what, 8 even though this is a pretty big problem size 8 in this case and last time it was size 8 or in the case of the papers in size of a thousand roughly with the phonebook, I assume these are in a perfectly straight line they won't quite fit.
以这个问题为例,你们要认识到,在这种情况下,这是个比较大的问题,其大小是,上次它的大小也是8,但在纸片那个问题中,电话簿的规模大概是上千的,现在假设这些,杯子完全在同一条直线上,虽然并不十分符合这个条件。
Well recall from week zero when we took a very real world phonebook and then just last week we had our volunteer come up with the array of pieces of paper on the board and when I challenged myself and when I challenged our volunteer to find me the number 50 both he and I were able 50 to leverage one assumption.
大家回忆一下,当我们拿着一个现实世界的电话簿,就在上周我们的志愿者,在黑板上提出了纸片的阵列,我挑战自己,也挑战志愿者,要找出同一个,数字。
> So now that might not have felt like the fastest algorithm but think about what you could have done with that algorithm in each iteration, much like the phonebook up front here, you literally split that problem in two because on each iteration roughly half of you were sitting down and then another half and then another half.
虽然这并不是最快的算法,但如果把这种算法每次迭代,就像刚才查电话簿一样,你便将这个问题一分为二了,因为每一次迭代后只有一半坐下来,以此类推。
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是一千,或者是大规模的任何问题。
And you'll find in the end that recursion is a feature of a language, it allows you to map some very obvious concepts like the phonebook tearing in half and half and half and half to actual code without it using some arbitrary human contrived framework like a for loop or a while loop which are much more stilted mechanisms.
最后你会发现递归是某种语言的一种特征,你可以用它将一些非常明显的思想,比如将电话簿划分为一半又一半,映射为实际代码,而不必使用那些人为框架,像for循环,while循环之类的,那是很呆板的机制。
应用推荐