OK. You can see that thing is cutting down the problem in half each time, which is good, but there's one more thing I need to deal with.
这很棒,但是我们还需要处理另外一件事情,让我们仔细来看看,我在开始做之前一直在说,应该先试验试验。
Because I'm cutting down the problem in half at each time. You're right, but there's something we have to do to add to that, and that's the last thing I want to pick up on.
但是我们还需要强调一点,这是我最后想讲的一点,让我们来看看代码-实际上,让我们先来测试测试吧。
And I keep cutting the problem down.
那么我应该选取数组中的哪个点呢?
Log n Log n, because at each stage I'm cutting the problem in half. So I start off with n then it's n n/2 n/4 n/8 over two n over four n over eight.
因为总共有多少层?,因为在每一层,我都是把问题分解成两半,因此以n开始,然后是。
With this, if I can assume that accessing the i'th element of a list is constant, then you can't see that the rest of that analysis looks just like the log analysis I did before, and each step, no matter which branch I'm taking, I'm cutting the problem down in half.
读取数组中的第i个元素,是个常量时间的操作的话,我也就能像以前那样得到,这个算法是对数级复杂度的分析,并且每一步不管我选择哪个区间,我都可以把问题的规模缩小一半。
应用推荐