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.
但是我们还需要强调一点,这是我最后想讲的一点,让我们来看看代码-实际上,让我们先来测试测试吧。
If everyone else is cutting down I don't have too, and if everyone else does cut down I don't have to, I end up using hot water and driving a big car and so on.
如果大家都想减排,我没必要跟风,如果别人真的减排了又与我何干,我照样用着热水,开着大排量汽车
And nobody knows, nobody believes that we can cut spending, right? -Somebody down the road has to pay the bills Somebody down the road has to pay the bills, either by cutting spending, cutting benefits or raising taxes.
而几乎没人相信,政府能够成功节流,不是吗?,-那总得,有人来埋单啊,迟早要有人来为此埋单的,要么精简政府开支,削减福利,要么增税。
At each stage, no matter which branch, here or here, I take, I'm cutting down the length of the list that I'm searching in half. All right?
选的是这里还是那里,我总是把列表分成两半,对吧?,所以如果我处理一个长度为n的列表?
In fact, it took the same number of steps as it did in the other case, because each time I'm cutting it down by a half.
因为每次我都把问题的规模,缩小一半,这很棒,好,接下来让我们这么做。
And you can see it wrapping its way down, cutting in half at each time until it gets there, but it takes a while to find. All right.
但是这也花了一点时间来搜索,好,让我们看看100万,或者1000万是不是在数组里。
And I keep cutting the problem down.
那么我应该选取数组中的哪个点呢?
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个元素,是个常量时间的操作的话,我也就能像以前那样得到,这个算法是对数级复杂度的分析,并且每一步不管我选择哪个区间,我都可以把问题的规模缩小一半。
应用推荐